Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I want to take a backup of the whole partition layout of a hard drive, including logical drives, so that I can restore that layout to another disk. I do not want to copy the contents of the partitions, only the layout. For the primary and extended partitions, it's easy:

dd if=/dev/sda of=partitiontable.bin bs=1 skip=446 count=64 # backup
dd if=partitiontable.bin of=/dev/sda bs=1 seek=446 count=64 # restore

But when it comes to the layout of the logical partitions, I wonder if there exists among the standard tools a similar way of saving the layout? I guess the main problem is finding the offsets to the locations of the EBRs, because with that, dd will do the rest. Keep in mind I need to be able to put everything back to a (possibly) blank disk and thereby restore the same layout. Using partitioning tools like fdisk or parted is fine, but I must be able to automate their use (scripting) and they should not depend on any X-related packages -- command line only.

My backup plan is doing it manually in a little python script using the struct module, but I rather hoped there was an easier way.

share|improve this question

3 Answers 3

up vote 37 down vote accepted

You can use sfdisk for this task.


sfdisk -d /dev/sda > part_table


sfdisk /dev/sda < part_table
share|improve this answer
Exactly what I was looking for, thank you! However, the man page says sfdisk is "not designed for large partitions", but does not specify any further what it means by "large". What specific limits does this impose? Will sfdisk tell me if it can't cope? – Lauritz V. Thaulow May 11 '11 at 8:48
sfdisk doesn't work with large volumes or support GPT. – Barry May 11 '11 at 9:11
@Barry and when you say "large", you're referring to the 2TB limit @Petr is talking about? – Lauritz V. Thaulow May 11 '11 at 9:18
The correct way is:sudo parted /dev/sda -lm > sda.parted – Barry Aug 12 '11 at 8:17
Sometimes it is useful, to ignore DOS only problems, to add the -L or --linux option: sfdisk -L /dev/sda < part_table – Diego Jul 15 '14 at 10:17

The correct answer, which will also work with GPT disks, was given here and here by Kris Harper.

You need GPT fdisk. Look at the download page or run sudo apt-get install gdisk.

Then use the sgdisk command like so

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

The first command copies the partition table of sda to sdb (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
I'm always scared I'll mix the two parameters, so a good trick is to use --backup=File to export a partition table from the source drive and --load-backup=File to restore in on the destination drive. – zidarsk8 Jul 24 '14 at 9:56

Older but still interesting pyparted and python-lvm bindings.


The previous was posted because the above does not work in many modern situations per the sfdisk man page.

sfdisk doesn't understand GUID Partition Table (GPT) and it is not designed for large partitions. In particular case use more advanced GNU parted(8).

This command however supports >2 TB partitions and LVM.

# parted -ms /dev/sda print > sda.parted

Sample output:

/dev/sda:12.9GB:scsi:512:512:msdos:VMware Virtual disk;
1:1049kB:12.9GB:12.9GB:::boot, lvm;
share|improve this answer
How do you restore from the saved sda.parted file to a new disk? – Avery Chan Jun 20 '12 at 1:46
This answer is useless because the question was about copying the partition layout to a new drive. The answer is just about dumping. How to import ? Please improve. – itsafire Oct 8 at 12:31

Your Answer


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.