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.
sfdisk
doesn't work with large volumes or support GPT. – dhchdhd May 11 '11 at 09:11sfdisk -L /dev/sda < part_table
– Diego Jul 15 '14 at 10:17sudo sfdisk -L -d /dev/disk/bypid/$SOURCE | sudo sfdisk -L /dev/disk/by-id/$TARGET
Use disk-ids if you're a dizzy head.
– rzr Nov 19 '15 at 23:52-L
is deprecated, but still accepted (as a no-op?) for backward compatibility. But yes,sfdisk --dump | sfdisk
appears to be all you need. Also, nobody mentioned yet thatsfdisk
does support GPT partitions, since util-linux 2.26, where it was re-written from scratch on top of libfdisk. – Peter Cordes Feb 27 '16 at 02:53