Cloning disk

This instructions about how you can clone full your physical disk to another physical disk.

https://wiki.archlinux.org/index.php/disk_cloning

dd (clonning)

This will clone the entire drive, including the MBR (and therefore bootloader), all partitions, UUIDs, and data:

dd if=/dev/sdX of=/dev/sdX bs=32M conv=sync,noerror
  • noerror instructs dd to continue operation, ignoring all read errors. Default behavior for dd is to halt at any error.
  • sync fills input blocks with zeroes if there were any read errors, so data offsets stay in sync.
  • bs= sets the block size. Defaults to 512 bytes, which is the “classic” block size for hard drives since the early 1980s, but is not the most convenient. Use a bigger value, 64K or 128K.

Note

If you are positive that your disk does not contain any errors, you could proceed using a larger block size, which will increase the speed of your copying several fold. For example, changing bs from 512 to 64K changed copying speed from 35 MB/s to 120 MB/s on a simple Celeron 2.7 GHz system. But keep in mind that read errors on the source disk will end up as block errors on the destination disk, i.e. a single 512-byte read error will mess up the whole 64 KiB output block.

Note

If you would like to view dd progressing, use the status=progress option.

Maybe faster (not tested):

dd if=/dev/sda | dd of=/dev/sdb

Tested

Clone all disk:

sudo dd if=/dev/sda of=/dev/sdb bs=32M conv=sync,noerror status=progress

120057757696 bytes (120 GB, 112 GiB) copied, 2919.16 s, 41.1 MB/s
3577+1 records in
3578+0 records out
120057757696 bytes (120 GB, 112 GiB) copied, 2951.48 s, 40.7 MB/s

Clone just one partition (Windows 7 system disk):

# check end of partition size
sudo fdisk -l /dev/sda  # source disk
# /dev/sda1   End: 41945714
# (41945652 + 1) / 8 = 5243215  # use this count in the next step
sudo dd if=/dev/sda of=/dev/sdb bs=4096 count=5243215 conv=sync,noerror status=progress

cat (clonning)

Clonning with cat:

cat /dev/sda > /dev/sdb

If you want to run this command in sudo, you need to make the redirection happen as root:

sudo sh -c 'cat /dev/sdb >/dev/sdc'

pv (clonning)

If you want a progress report and your unix variant doesn’t provide an easy way to get at a file descriptor positions, you can install and use pv instead of cat:

pv /dev/sda > /dev/sdb

Backuping in file

To save space, you can compress data produced by dd with gzip, e.g.:

dd if=/dev/hdb | gzip -c  > /image.img

You can restore your disk with:

gunzip -c /image.img.gz | dd of=/dev/hdb