Piero Blog

Wednesday, January 25, 2006

Backup Partition tables incl ext.

Making a backup of the partition entries

We will save all the partitions entries (both primary and logicial ones which appear in the extended partition). In this example, we'll be assuming that hda (the first IDE hard disk) is to be backed up.

First, we will save the MBR with DD (GNU convert and copy)

  • cd /root
  • mkdir partition-backup
  • cd partition-backup
  • dd if=/dev/hda of=backup-hda.mbr count=1 bs=512

It will produce a very small, but very important file: 512 bytes of data. Now, we will save entries of the extended partitions:

  • sfdisk -d /dev/hda > backup-hda.sf

sfdisk is a tool provided with the util-linux package.

IMPORTANT! You should now put these files somewhere safe - copy them to a floppy disk (and take a copy of it!), or burn them onto a CD. Keep these files safe. Do not leave them on your hard drive - if there is a problem with th drive, you may not be able to access these files, and while your partition images won't be wortheless, it will certainly be a lot harder to restore your data.

Restoring partition entries from the backup

Be careful, restoring is a dangerous action - it can destroy data! First, we will restore the Master Boot Record:

  • dd if=backup-hda.mbr of=/dev/hda

Then, here is how to restore extended partitions entries:

  • sfdisk /dev/hda <>

To finish, you will have to reboot your computer.