Backup, Restore and Clone Partition table

Backup, Restore and Clone Partition table

The Problem

Experiment completed, I redefined the partitions using fdisk by entering the values shown in the original fdisk output. I used ntfsclone to restore the Windows Server 2008 partition. No problem with sda1 but linux couldn’t mount the NTFS filesystem in sda2. I tried the same thing a second time – still couldn’t mount the partition. Tried a third time – still couldn’t mount sda2. This doesn’t make sense – I know all the data is still there, all I need to do is redefine the partition and the filesystem should be there. But I remembered someone telling me that the definition of Insanity is doing the same thing over and over again and expecting a different outcome. So maybe it is time to stop and think.

A few minutes of sober second thought revealed the problem: fdisk shows the start and end cylinder numbers, but each cylinder contains 16065 blocks. Did you notice that sda1 ends in the same cylinder that sda2 starts? That means that within cylinder 25497 there is a block, call it LAST_BLOCK_IN_SDA1 which is the last block in sda1. And later in the same cylinder there is another block which is FIRST_BLOCK_IN_SDA2. I don’t know exactly where either of these blocks is located – could be any two of the more than sixteen thousand blocks. And the two blocks might not be right next to each other, there could be unused blocks between them. In fact, the original sda1 might not have started at the first block in cyclinder 1. In hindsight, fdisk might be a decent tool for quickly partitioning a disk, but it is a poor tool for partition backup and recovery. I need to find something better than fdisk …

Useful with software raid to quickly create the same scheme on new disks after failure.

To backup partition table:

sfdisk -d /dev/sda > sda.table


To restore the partition table:

sfdisk /dev/sda > sda.table


To clone partition table:

sfdisk -d /dev/sda | sfdisk /dev/sdb

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.