用DD命令制作硬盘镜像
2012-09-28 17:50
330 查看
用DD命令制作硬盘镜像
本文参考http://serverfault.com/questions/4906/using-dd-for-disk-cloning写出,转载时请说明出处。
以下的说明都是针对备份整个硬盘,而不是备份某一个分区。
一、用DD命令制作硬盘镜像的特点
(1)在制作镜像时,不能对需要进行备份的硬盘经常写操作,可以只读挂载或者不挂载。
(2)在制作镜像时,MBR、硬盘的分区表、bootloader也会被备份。
(3)生成的镜像文件用于恢复时,目标硬盘的容量必须等于或大于源硬盘的容量。
(4)使用硬盘镜像完成恢复后,由于目标硬盘的分区表跟源硬盘的分区表是一样的,所以会造成目标硬盘的空间浪费。这个问题可以通过使用硬盘分区大小调整工具解决。
(5)在dd生成或恢复镜像时,默认没有显示进度,但这个问题可以解决。解决方法请看下文。
二、备份和还原操作
(1)制作硬盘sdb的镜像文件sdb_backup.img:
$dd if=/dev/sdb of=~/sdb_backup.imgbs=32M
注:bs即blocksize,bs根根系统的内存大小和硬盘读写速度而设定
(2)将硬盘sdb的内容直接克隆到硬盘sdc中(要保证sdc的容量等于或大于sdb的容量):
$dd if=/dev/sda of=/dev/sdbbs=32M
(3)需要备份的硬盘可能存在大量的空白区域(未用于存储数据的区域),如果用压缩工具压缩生成的镜像,可大大减小镜像的大小。
在制作硬盘sdb的镜像文件时就进行压缩:
$dd if=/dev/sdb| gzip -c > ~/sdb_backup.img.gz
将备份的镜像恢复到硬盘sdc中
$gunzip -c ~/sdb_backup.img.gz| dd of=/dev/sdc
(5)只备份硬盘的MBR
(6)当使用dd进行镜像备份时,如dd发现某个sector(扇区)错误,默认会停止备份操作。这时可以 "conv=noerror,sync" to ensure that it doesn't stop whenit encounters an error, and fills in the missing sector(s) with null bytes.This is usually the first step I take if trying
to recover from a failed orfailing disk -- get a copy before doing any recovery attempts, and then dorecovery on the good (cloned) disk. I leave it to the recovery tool to copewith any blank sectors that couldn't be copied.
gunzip -c ~/sdb_backup.img.gz| dd of=/dev/sdc conv=noerror,sync
注意:
If you have a disk with bad sectors,you really should be using 'ddrescue' instead of dd. It's much more efficient,and has a much better chance of recovering more data. (Don't get it confusedwith dd_rescue, which is not as good)
If the source drive is damaged at all,you'll have more luck using
The reason behind this is that, on readerrors,
isbasically a
The end result of
read errors at byte 100 of your 100Gb disk, you'd haveto wait a long time to recover the other 9,999,900 bytes*, whereas
(5)显示制作操作或恢复操作的进度
参考A
Youcan follow the progression of the operation with :
$ddif=/dev/sda of=/dev/sdb & pid=$!
$kill-USR1 $pid; sleep 1; kill $pid
参考B
Youcan get a dd process running in the background to report status by sending it asignal with the kill command, e.g.:
$ddif=/dev/hdb of=/image.img &
$kill -SIGUSR11234
#这里假设1234为备份进程号
参考C
The man page says: Sending a USR1 signal to a running ‘dd’process makes it print I/O statistics to standard error and then resumecopying.
I use this feature regularly.
Thisis kind of a cheap hack, but it's a quick and dirty way to monitor your DDprocess.
Runyour dd command. Open a new shell and do a ps awx to find your dd process' PID.Now in the new shell type watch -n 10 kill -USR1 {pid of your DD process}
Thiswill do nothing in the watch output window, but back in the original DD shell,DD will start outputting status reports every 10 seconds. You can change the -n10 in the watch command to any other time frame of
course.
本文参考http://serverfault.com/questions/4906/using-dd-for-disk-cloning写出,转载时请说明出处。
以下的说明都是针对备份整个硬盘,而不是备份某一个分区。
一、用DD命令制作硬盘镜像的特点
(1)在制作镜像时,不能对需要进行备份的硬盘经常写操作,可以只读挂载或者不挂载。
(2)在制作镜像时,MBR、硬盘的分区表、bootloader也会被备份。
(3)生成的镜像文件用于恢复时,目标硬盘的容量必须等于或大于源硬盘的容量。
(4)使用硬盘镜像完成恢复后,由于目标硬盘的分区表跟源硬盘的分区表是一样的,所以会造成目标硬盘的空间浪费。这个问题可以通过使用硬盘分区大小调整工具解决。
(5)在dd生成或恢复镜像时,默认没有显示进度,但这个问题可以解决。解决方法请看下文。
二、备份和还原操作
(1)制作硬盘sdb的镜像文件sdb_backup.img:
$dd if=/dev/sdb of=~/sdb_backup.imgbs=32M
注:bs即blocksize,bs根根系统的内存大小和硬盘读写速度而设定
(2)将硬盘sdb的内容直接克隆到硬盘sdc中(要保证sdc的容量等于或大于sdb的容量):
$dd if=/dev/sda of=/dev/sdbbs=32M
(3)需要备份的硬盘可能存在大量的空白区域(未用于存储数据的区域),如果用压缩工具压缩生成的镜像,可大大减小镜像的大小。
在制作硬盘sdb的镜像文件时就进行压缩:
$dd if=/dev/sdb| gzip -c > ~/sdb_backup.img.gz
将备份的镜像恢复到硬盘sdc中
$gunzip -c ~/sdb_backup.img.gz| dd of=/dev/sdc
(5)只备份硬盘的MBR
$dd if=/dev/sdb of=~/MBR_backup bs=512 count=1
(6)当使用dd进行镜像备份时,如dd发现某个sector(扇区)错误,默认会停止备份操作。这时可以 "conv=noerror,sync" to ensure that it doesn't stop whenit encounters an error, and fills in the missing sector(s) with null bytes.This is usually the first step I take if trying
to recover from a failed orfailing disk -- get a copy before doing any recovery attempts, and then dorecovery on the good (cloned) disk. I leave it to the recovery tool to copewith any blank sectors that couldn't be copied.
gunzip -c ~/sdb_backup.img.gz| dd of=/dev/sdc conv=noerror,sync
注意:
If you have a disk with bad sectors,you really should be using 'ddrescue' instead of dd. It's much more efficient,and has a much better chance of recovering more data. (Don't get it confusedwith dd_rescue, which is not as good)
If the source drive is damaged at all,you'll have more luck using
dd_rhelpwith
dd_rescue(my personal preference) or GNU
ddrescue.
The reason behind this is that, on readerrors,
ddkeeps trying and trying and trying - potentially waiting for along time for timeouts to occur.
dd_rescuedoessmart things like reading up to an error, then picking a spot further on on thedisk and reading backwards to the last error, and
dd_rhelp
isbasically a
dd_rescuesession manager - cleverly starting and resuming
dd_rescuerunsto make it quicker again.
The end result of
dd_rhelpismaximum data recovered in minimum time. If you leave
dd_rhelprunning, in the end it does the exact same job as
ddinthe same time. However, if
ddencountered
read errors at byte 100 of your 100Gb disk, you'd haveto wait a long time to recover the other 9,999,900 bytes*, whereas
dd_rhelp+
dd_rescuewouldrecover the bulk of the data much faster.
(5)显示制作操作或恢复操作的进度
参考A
Youcan follow the progression of the operation with :
$ddif=/dev/sda of=/dev/sdb & pid=$!
$kill-USR1 $pid; sleep 1; kill $pid
参考B
Youcan get a dd process running in the background to report status by sending it asignal with the kill command, e.g.:
$ddif=/dev/hdb of=/image.img &
$kill -SIGUSR11234
#这里假设1234为备份进程号
参考C
The man page says: Sending a USR1 signal to a running ‘dd’process makes it print I/O statistics to standard error and then resumecopying.
I use this feature regularly.
Thisis kind of a cheap hack, but it's a quick and dirty way to monitor your DDprocess.
Runyour dd command. Open a new shell and do a ps awx to find your dd process' PID.Now in the new shell type watch -n 10 kill -USR1 {pid of your DD process}
Thiswill do nothing in the watch output window, but back in the original DD shell,DD will start outputting status reports every 10 seconds. You can change the -n10 in the watch command to any other time frame of
course.
OS X doesn't have watch available and -USR1 kills dd. The following command works though: while [ true ]; do killall -INFO dd; sleep 30; done |
相关文章推荐
- 在Linux系统下用dd命令制作ISO镜像U盘启动盘
- 利用dd命令制作u盘iso镜像
- AIX下rootvg镜像制作与取消,更换硬盘问题
- 再生龙制作的镜像 复制到 大硬盘后 扩容目标盘
- 在Linux系统下用dd命令制作ISO镜像U盘启动盘
- AIX下rootvg镜像制作与取消,更换硬盘问题
- AIX下镜像制作与取消,更换硬盘
- linux从硬盘制作ISO镜像
- 借助loop device与losetup命令制作硬盘镜像
- 借助loop device与losetup命令制作硬盘镜像
- 在Linux系统下用dd命令制作ISO镜像U盘启动盘
- Linux系统下使用DD命令克隆磁盘或者镜像
- 制作centos6.5 镜像,安装cloud-init 支持openstack 密码注入
- 03-镜像文件的制作
- ubifs文件系统的制作过程&&遇到的问题及解决方案总结---之三“UBIFS镜像的制作&&烧写”
- 【嵌入式学习笔记二】烧录制作好的镜像到4412开发板中
- kvm-4:镜像制作
- linux下如何挂接(mount)光盘镜像文件、移动硬盘、U盘、Windows网络共享
- 利用mkfs.ubifs和ubinize两个工具制作UBI镜像
- 使用dd命令制作U盘启动盘wodim刻录光盘cd dvd