Page 1 of 1

Use sfdisk to clone partition table

Posted: Thu Apr 03, 2014 6:48 pm
by gilthanaz
[Problem]
I had a softraid mirroring sda1/sdb1 and sda5/sdb5. A disk failed, so i replaced it but could not remember the exact values i had used for the partition size when setting up the disks back then.

[Solution]
You can clone the partition table using 'sfdisk' if you have an harddisk of the exact same size as the one you want to clone (which will most likely be the case for a softraid).

The following line dumps the partition table of sda into a file:

Code: Select all

sfdisk -d /dev/sda > partitiontable_sda
You can then apply the stored partition table to the other disk by using:

Code: Select all

sfdisk /dev/sdb < partitiontable_sda
For some reason this did not work on a completely virgin disk (with no partition table existing yet) so i had to create a dummy partition with fdisk and then do the above.

The following will show you if you were successfull:

Code: Select all

fdisk -l