linux poison RSS
linux poison Email

Creating backup/restore images using dd

Create a hard disk image: dd if=/dev/hda1 of=/home/hda1.bin

Create a compressed disk image: dd if=/dev/hda1 | gzip > /home/hda1.bin.gz

Back up the MBR: dd if=/dev/hda of=/home/hda.boot.mbr bs=512 count=1

Restore MBR (from a Live CD): dd if=/mnt/hda1/home/hda.boot.mbr of=/dev/hda bs=512 count=1

Backup a drive to another drive: dd if=/dev/hda of=/dev/hdb conv=noerror,sync bs=4k

The command:

dd -if /dev/hda1 > partitionimage.dd

will backup "/dev/hda1" partition. A whole drive (including the MBR) could be backed up using just /dev/hda as the input "file". Restoring is done by: dd -if partitionimage.dd -of /dev/hda1

If you have a complete new harddrive and want to restore the backup (or copy your old system to the new drive). First, the new drive has to be bigger or exactly the same size as the old one. First go superuser and switch to runlevel 1 so that you can fumble around with the harddisk without other services interfering

restore either the whole disk to the new drive or one partition (depending on how you made the backup): dd -if partitionimage.dd -of /dev/hda1

If you restored the whole drive (/dev/hda), the system will not automatically create the devices (/dev/hda1, /dev/hda2) if you just restored the whole drive. If you know how to make the devices show up without reboot, write it here, otherwise this is a good moment to reboot.

If you restored the system to a new drive, and your device names changed (for example from /dev/hda to /dev/sda) then you must adapt the bootloader and the mount points. While still on runlevel 1, edit these files:

/boot/grub/menu.list
/etc/fstab

After your system is able to boot and runs again, you can resize your partitions to fill the rest of the new harddisk (if you want that) as described here


3 comments:

Unknown said...

Hi,
I am a newby to the dd command and I found this link of yours very useful. I am trying to make a backup of my disk (/dev/sda1) and I can see that there's only 5 Gigas of used space (using df command). The thing is that at the moment, my backup image is more than 20 gigas in size. How is this possible? Does this mean that the resulting backup will be of the same size of the whole disk (250Gb)?

Thanks

DevOps said...

dd command takes the backup of entire partition (in your case it's /dev/sda1) not of only data contains in this partition.

roughl said...

>If you restored the whole drive (/dev/hda), the system will not automatically create the devices
>(/dev/hda1, /dev/hda2) if you just restored the whole drive. If you know how to make the devices
>show up without reboot, write it here, otherwise this is a good moment to reboot.

One can use 'sudo partprobe' to inform the OS of partition table changes

Post a Comment

Related Posts with Thumbnails