Copying GPT partition tables from disk to disk
There's a number of situations where you want to replicate partition
tables from one disk to another disk; for example, if you are setting
up mirroring or (more likely) replacing a dead disk in a mirrored
setup with a new one. If you're using old fashioned MBR partitioning,
the best tool for this is
sfdisk and it's done as follows:
sfdisk -d /dev/OLD | sfdisk /dev/NEW
Under some situations you may need '
If you're using new, modern GPT partitioning,
the equivalent of
sgdisk. However it gets used somewhat
differently and you need two operations:
sgdisk -R=/dev/NEW /dev/OLD sgdisk -G /dev/NEW
For obvious reasons you really, really don't want to accidentally flip
the arguments. You need
sgdisk -G to update the new disk's partitions
to have different GUIDs from the original disk, because GUIDs should be
globally unique even if the partitioning is the same.
The easiest way to see if your disks are using GPT or MBR partitioning
is probably to run '
fdisk -l /dev/DISK' and look at what the
Disklabel type' says. If it claims GPT partitioning, you can
then run '
sgdisk -p /dev/DISK' to see if
sgdisk likes the full
GPT setup or if it reports problems. Alternately you can use '
-l /dev/DISK' and pay careful attention to the '
scan' results, but this option is actually kind of dangerous; under
gdisk will stop to prompt you about what to do
about 'corrupted' GPTs.
sgdisk lacks any fully supported way of dumping and
saving a relatively generic dump of partition information; '
-b' explicitly creates something which the documentation says
should not be restored on anything except the original disk. This
is a hassle if you want to create a generic GPT based partitioning
setup which you will exactly replicate on a whole fleet of disks (not that we use GPT partitioning
on our new iSCSI backends, partly for this reason).
(I suspect that in practice you can use '
sgdisk -b' dumps for
this even if it's not officially supported, but enhh. Don't forget
to run '
sgdisk -G' on everything afterwards.)
(This is the kind of entry that I write so I have this information in a place where I can easily find it again.)