Clone a disk using dd
This is a practical example of what I did to clone my disk to be up and running as soon as I get the new laptop. This could also be used to wipe a disk clean (if you sell a computer for example)
Clone the disk
First of all I booted from the laptop on a live CD (Gentoo live cd for example), started ssh and gave root a password.
Then from the laptop, I ran the following command
# dd if=/dev/sda | ssh email@example.com "dd of=/mnt/data/laptop_sda.img"
This typically takes several hours to complete so before you run the command use the screen command in case you need to close the terminal.
Check the image
There are many ways to check the state of the image. The following is how I chose to do it.
- Install a kubuntu vm in VirtualBox.
- Add an extra 'vm disk' (sdb) of 110G to contain the image.
- Make the CDRom point to our image.
- Boot into the vm
Now I can copy my image back to the secondary device like this:
# dd if=/dev/cdrom of=/dev/sdb bs=512
The i/o might be high so it could take a while. Took me ~17 hours.
- Shutdown the vm
- swap the boot disk order and make sdb primary master.
- Boot the system and see if it works.
The system booted and asked for the password to my encrypted filesystems. It then fully booted regardless of hardware change, etc. I checked the files and found no corruption.
This proves that my image is good and that linux rulz!
Wipe a disk clean
By selecting /dev/zero as the source you can write a bunch of zeros to the disk, essentially wiping it clean.
# dd if=/dev/zero of=/dev/sdb bs=512