AKA: clone partition tables

When to use:

Sometimes a drive might lose its partition tables for unknown reasons. Sometimes you need to setup a partition table to be identical to a drive in the same system, so that you can use them together with RAID(mdadm) or LVM or btrfs or whathave you.




MBR – sfdisk

To backup an MBR partition table using ‘sfdisk’: # sfdisk -d /dev/sda > sda.table

​To restore an MBR partition table from backup using ‘sfdisk’: # sfdisk /dev/sda < sda.table

Clone with the backup file: # sfdisk /dev/sdb < sda.table

Clone partition from SDA to SDB (copy from sda to sdb): # sfdisk -d /dev/sda | sfdisk /dev/sdb

Confirm by listing(printing) partition table of source: # sfdisk -l /dev/sda

Confirm by listing(printing) partition table of destination: # sfdisk -l /dev/sda

NOTE: source and destination partition tables should match after clone (obviously)

NOTE: sfdisk -d is for dump, -l is for list


GPT – sgdisk

To backup a GPT partition table using ‘sgdisk’: # sgdisk -b sdX.gpt /dev/sdX

​To restore a GPT partition table from a backup file using ‘sfdisk’: # sgdisk -l sdX.gpt /dev/sdX

To clone a partition table from one drive to another using ‘sgdisk’:# sgdisk -R=Destination Source

NOTE: note the syntax is destination is first (not source) unlike the common other way where source is first. So keep that in mind and dont mess up the commnd

NOTE: sometimes that command doesnt go through so try with and without =, and consider the space (sometimes its best not to include it)

Other likeable forms (copy table from sda to sdb):

# sgdisk -R=/dev/sdb /dev/sda

# sgdisk -R/dev/sdb /dev/sda

​After cloning GPT tables you will need to randomize the GUID of the destination:​

# sgdisk -G /dev/sdb

Confirm by listing(printing) partition table of source: # sgdisk -p /dev/sda

Confirm by listing(printing) partition table of destination: # sgdisk -p /dev/sdb

NOTE: -R is for replicate (also known as copy or clone), -G is for GUID or randomizing GUID, -p is for print


Protective MBR?

NOTE: some GPT partitioned disks have a Protective MBR which is important if its a bootable drive, BIOS looks thru MBR only, this tells it that there is a GPT volume.

Leave a Reply

Your email address will not be published. Required fields are marked *