Using sfdisk with the -d option we can get a dump of the current partition table in a regular file, and if needed we can restore it from that file:
sfdisk -d /dev/sda > sda_table
and to restore the partition table to the same drive (or change device name for another destination drive):
sfdisk /dev/sda < sda_table
Regardless on the method used, having a backup of the partition table might be handy.
One more tip: another usage of sfdisk with -d is to create an identical partition table from another hard disk. In this example we are partitioning sdb with the exact same partitions as sda (ie. copying partition table from SDA to SDB):
sfdisk -d /dev/sda | sfdisk /dev/sdb
of course this can be handy when the hard drives are identical, in raid1 setups, etc. (actually, they don't even have to be identical, but the destination drive needs to be the same size or larger (exactly the same size, not "sales pitch gigabytes size")).
So there you have it (and I have it for my permanent memory now!).
Sidenote: copying the first 512bytes of your drive may copy many partition tables, but only if they do not include extended partitions, since the main/base partition table actually uses a reference that links to another part of the drive where it stores the rest of the extended partition table data. Don't ask how I know this, other then it was a late night, and interesting things were learned using hexedit! :) ask Jaymes if one must know! :P
No comments:
Post a Comment