Thursday, June 25, 2009

Backing up your boot drive on Fedora with dd

This is especially useful for people whose installation have a boot partition and software raid partition on the same drive.
Example Installation:
/dev/sda1 /boot
/dev/sda2 swap
/dev/sda3 raid member

/dev/sdb1 raid member

/dev/md0 / devices=/dev/sda3,/dev/sdb1

If your boot drive fails, your computer will be unable to boot. Here, I will explain
how to backup the boot drive so you can get it up and running very quickly again.

--------------------------
BACKUP PROCEDURE
--------------------------
1] Use dd to save the first 512 bytes of data which contain the drive's MBR (master boot record) and partition info.
# dd if=/dev/sda of=/backup/dd/sda-mbr.img bs=512 count=1

2] Use dd to image the partition containing the boot files(#fdisk says /dev/sda1 contains /boot in my case) as well.
# dd if=/dev/sda1 of=/backup/dd/sda1.img bs=64K

--------------------------
RESTORE PROCEDURE
--------------------------
1] Boot with fedora rescue CD

2] First we have to restore our RAID device.
#echo DEVICE partitions > /etc/mdadm.conf
#mdadm --examine --scan >> /etc/mdadm.conf
#mdadm --assemble --scan /dev/md0

3] Now we have to mount it somewhere
#mkdir /mnt/sysimage
#mount /dev/md0 /mnt/sysimage

4] Restore the MBR and partition info to /dev/sda first.
# dd if=/mnt/sysimage/backup/dd/sda-mbr.img of=/dev/sda
Confirm partitions were restored
# fdisk -l

5] Restore the partition containing the boot files.
# dd if=/mnt/sysimage/backup/dd/sda1.img of=/dev/sda1
Confirm boot files were restored
#mkdir /boot
#mount /dev/sda1 /boot
#ls /boot

6] The boot drive should be good now, it's time to see if it works.
#reboot

7] If your OS boots, it's time to re-add the raid member to the array.
#mdadm --manage /dev/md0 --add /dev/sda3