Duplicate partition table for RAID 1

Almost all HOWTOs for re-adding a drive to a RAID 1 I found on the internet told me to manually recreate the partition table on the new drive. But having 8 partitions, that’s no fun:-(

Here’s how I did it.

/dev/sda is the working drive, /dev/sdb the new one

sudo dd if=/dev/sda of=/dev/sdb count=1

You now have copied the main partition table. But as I’m using logical/extended partitions, I needed to copy those partition tables, too. I used fdisk to get at the sector:

sudo fdisk -ul /dev/sda

Disk /dev/sda: 251.0 GB, 251000193024 bytes
255 heads, 63 sectors/track, 30515 cylinders, total 490234752 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 63 996029 497983+ fd Linux raid autodetect
/dev/sda2 996030 6859754 2931862+ 82 Linux swap / Solaris
/dev/sda3 6859755 490223474 241681860 5 Extended
/dev/sda5 6859818 22490999 7815591 fd Linux raid autodetect
/dev/sda6 22491063 61561079 19535008+ fd Linux raid autodetect
/dev/sda7 61561143 81096119 9767488+ fd Linux raid autodetect
/dev/sda8 81096183 490223474 204563646 fd Linux raid autodetect

Look for the ‘Start’ of the ‘Extended’ partition and use it for ‘seek’ and ‘skip’:

sudo dd if=/dev/sda of=/dev/sdb count=1 skip=6859755 seek=6859755

That worked like a charm. I had to reboot to have the partition devices in /dev created, but that’s it:-)

Disclaimer: Double check source and target when doing such stuff. I didn’t check on more than 8 partitions…


3 thoughts on “Duplicate partition table for RAID 1

  1. In case the disks are not identical in size, here’s an alternative (and more flexible way):

    sfdisk -d /dev/orig-disk > parts.txt
    sfdisk /dev/newdisk < parts.txt

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s