Use sfdisk to clone partition table

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
gilthanaz
Site Admin
Posts: 444
Joined: Fri Aug 29, 2003 9:29 pm
Contact:

Use sfdisk to clone partition table

Post 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
Post Reply