I want to take a backup of the whole partition layout of a hard drive, including logical drives, so that I can restore that layout to another disk. I do not want to copy the contents of the partitions, only the layout. For the primary and extended partitions, it's easy:
dd if=/dev/sda of=partitiontable.bin bs=1 skip=446 count=64 # backup
dd if=partitiontable.bin of=/dev/sda bs=1 seek=446 count=64 # restore
But when it comes to the layout of the logical partitions, I wonder if there exists among the standard tools a similar way of saving the layout? I guess the main problem is finding the offsets to the locations of the EBRs, because with that, dd
will do the rest. Keep in mind I need to be able to put everything back to a (possibly) blank disk and thereby restore the same layout. Using partitioning tools like fdisk
or parted
is fine, but I must be able to automate their use (scripting) and they should not depend on any X-related packages -- command line only.
My backup plan is doing it manually in a little python script using the struct module, but I rather hoped there was an easier way.