How to backup DOS-type partition table/GPT and LVM metadata?

DOS partition table

We can use sfdisk to dump partition table in usable format and store it:

$ sudo sfdisk -d /dev/sda > sda_partitions

Partition table can be restored using stored backup:

$ sudo sfdisk /dev/sda < sda_partitions

Partition table can be easily cloned (from sda to sdz in this example):

$ sudo sfdisk -d /dev/sda | sfdisk /dev/sdz

GPT

To backup GUID partition table use sgdisk command (from gdisk package):

$ sudo sgdisk -b sda_gpt_backup /dev/sda

Restore it in similar way:

$ sudo sgdisk -l sda_gpt_backup /dev/sda

LVM

To backup LVM metadata for volume group vol_test to vol_test_backup file use command:

$ sudo lvm vgcfgbackup -f vol_test_backup vol_test

To restore volume group metadata use similar command:

$ sudo lvm vgcfgbackup -f vol_test_backup vol_test

To restore physical volume metadata (with specified UUID to /dev/sda1 device):

$ sudo pvcreate --restorefile vol_test_backup --uuid rRD... /dev/sda1

There is a little more work to be done in this case (beyond this short post) so jump directly to Red Hat - Logical Volume Manager Administration.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu