Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

On a non GPT partition table I can do

sfdisk -d /dev/sda | sfdisk /dev/sdb.

But sfdisk doesn't support GPT partition tables. What can I use instead?

I'm looking for a one or two command solution, not just using GNU parted to output the partition sizes and then manually making them again.

share|improve this question
add comment

4 Answers

dd if=/dev/sda of=GPT_TABLE bs=1 count=A
dd if=GPT_TABLE of=/dev/sdb bs=1 count=A
partprobe /dev/sdb

where A is:

A=(128*B)+1024
B=parted -ms /dev/sda print |tail -1|cut -b1
share|improve this answer
add comment
up vote 38 down vote accepted

Install gdisk which is available in the Ubuntu Universe repositories.

Then use the sgdisk command (man page here) like so

sgdisk -R=/dev/sdY /dev/sdX
sgdisk -G /dev/sdY

The first command copies the partition table of sdX to sdY (be careful not to mix these up). The second command randomizes the GUID on the disk and all the partitions. This is only necessary if the disks are to be used in the same machine, otherwise it's unnecessary.

share|improve this answer
2  
This information is golden for anyone who wants to replace a failed RAID-1 disk. Thanks! –  Christian Oct 22 '12 at 14:30
    
@Christian Yep, that's what I used it for. –  Kris Harper Oct 22 '12 at 14:42
    
According to the manual this also supports MBR-only disks (sgdisk auto-converts on load), which is pretty great. –  Tobu Mar 9 '13 at 23:11
add comment

I just tried replication with sgdisk and it works just fine - you just have to follow readline syntax rules:

   sgdisk --replicate=/dev/target /dev/source

or

   sgdisk -R/dev/target /dev/source

and everything works.

share|improve this answer
    
This is exactly what my answer says. –  Kris Harper Nov 5 '13 at 21:20
add comment

I tried and it didn't work for me. The solution that I found is:

sgdisk --backup=table /dev/sda
sgdisk --load-backup=table /dev/sdb
sgdisk -G /dev/sdb
share|improve this answer
    
I found this solution is better, because it can work with non-GPT. I also change the last command to: sgdisk -g /dev/sdb –  Locke Dec 7 '13 at 9:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.