As Mark Williams says, the dd
commands you've specified will replicate the old partition table, which you can then modify if necessary.
One caveat, though: If the disk uses the GUID Partition Table (GPT), as most disks do on modern computers, the partition table is replicated at both the start and end of the disk. If the target disk is not exactly the same size as the original, the resulting restored disk may need minor repairs. IIRC, parted
, GParted, and similar tools will notice if the new disk is bigger than the original and offer to make repairs. If you use my own GPT fdisk (gdisk
, sgdisk
, or cgdisk
), you can manually repair the problem by typing x
to go to the experts' menu, typing e
to relocate the backup data structures to the end of the disk, and then typing w
to save the changes.
If the new disk is smaller than the original, then the backup partition table on a GPT disk will be lost, necessitating a similar recovery procedure. Worse, on either a GPT disk or an MBR disk, the final partition (or even multiple partitions) might be damaged or lost entirely. There's nothing that can be done about this, really; at best, you'll be able to resize the final partition to fit and then do a filesystem repair (with fsck
) to try to recover as much data as possible.
Note that these size issues can crop up even if the disks differ in size by even just a single sector. Disks marketed as being the same size (say, 2TB) may differ from each other in size by significantly more than that. If you plan to buy a replacement disk of the "same" size as the original, check the first original's size accurate to the sector and look up the technical specs on any potential replacement to be sure it's as large as or bigger than the original.