Copy a disk image with progress indicator —30 September 2015
Assuming you want to save the image of a 4GB disk at
sudo dd if=/dev/disk2 bs=4000 | pv -s 4G | dd of=disk.image bs=4000
bs=4000means buffer size 4000 bytes. On GNU versions of
ddyou can use the shorter
4mnotation for the same effect.
- It’s important to specify a buffer size, otherwise the default might be too small, and then the transfer will be very slow.
- The upper limit for the buffer size is practically the bandwidth of the I/O channel (speed of the disk). Specifying a higher value will make no difference.
pvis a tool to monitor the progress of data through a pipe. The
-s 4Gflag is the estimated size of the data to transfer. This value should match the size of the disk, and it’s used by the progress indicator calculation and display.
- The first
ddreading the disk typically needs to run as root, the second
ddwriting to a file doesn’t
When doing the reverse, before writing an image file back to disk, double-check the destination disk first. The specified disk will be overwritten, its previous data will not be recoverable.
dd if=disk.image bs=4000 | pv -s 4G | sudo dd of=/dev/disk2 bs=4000
- The file and the image device parameters are in inverse order
sudois now at the disk writing side