Monday, June 8, 2009

dd: Like Fire for a Caveman

Before I could install Ubuntu on my harddisk, I needed to make a backup in case stuff went completely wrong. It's not easy finding a good way to do that. Most googling turns up recommendation for expensive packages that I don't want to pay for. I eventually went for the free Macrium Reflect.

Part of the installation process was using the 'dd' command to get an image of the boot sector. It was something like this:
dd if=/dev/hda3 of=/mnt/backup/bootimage.bin bs=512 count=1
That means that the input file is simply the partition /dev/hda3, the output file is the Windows backup sector that I mounted into the /mnt directory, the number of bytes per sector is 512 and the number of sectors is 1.

Why not use 'dd' to do a backup. With the Ubuntu live CD, all you would need to do is:
  1. create a directory where you want to mount the drive to store the backup
  2. mount that drive
  3. dd the whole partition to save into the backup drive
To restore:
  1. create a directory where you want to mount the drive where you stored the backup
  2. mount that drive
  3. dd the image back from the backup drive onto the partition to restore
Also, you can apparently treat the entire disk as a file and back the whole thing up--not just the partitions. This is good if you want to make an exact copy of the same disk. But it won't necessarily work if the disk is replaced by some other disk off the shelf at the local computer store and has different geometry.

The dd command is very useful and very powerful. It is also very dangerous. One best type very carefully and double-check everything before pressing 'enter'.

No comments:

Post a Comment