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

This actually copies the layout to a file. If I want to restore the layout, what command should I give?

Anthon
  • 79,293

1 Answers1

1

I think that it's not so straightforward to clone GPT table with parted otherwise you would write some simple wrapper which would parse the ouptut of the parted -ms /dev/sda print command and prepare related parted sub-commands to do it.

But there is available a GPT-aware fdisk tool called sgdisk which is part of the gdisk package on RHEL/CentOS/Ubuntu distros. With this one, it's easily doable:

# clone GPT table from /dev/sda to /dev/sdb
sgdisk -R=/dev/sdb /dev/sda

# make unique its GUID as it was cloned and is identical with /dev/sda
sgdisk -G /dev/sdb
dsmsk80
  • 3,068
  • 1
    This seems to assume that the two disks are connected and working simultaneously. I get the feeling from the OP's question that the question is about copying the partitioning scheme from one disk to another, by way of a file and possibly separated by time. Could you expand your answer to perhaps indicate how one would do that using sgdisk? – user Oct 03 '13 at 07:43
  • 1
    sudo sgdisk --backup=sda.sgdisk /dev/sda – Hardbyte Aug 28 '15 at 08:48
  • Going off the comment added by @hardbyte, this is how you'd restore: sudo sgdisk --load-backup=sda.sgdisk /dev/sda – harperville Dec 07 '21 at 19:08