RHEL / CentOS : How to rebuild LVM from Archive (metadata backups)

Problem : The filesystem was corrupted and the LVM volumes could not be mounted, with the lvm partitions are lost.

Solution :
Metadata backups and archives are automatically created on every volume group and logical volume configuration change unless disabled in the lvm.conf file. By default, the metadata backup is stored in the /etc/lvm/backup file and the metadata archives are stored in the /etc/lvm/archive file. If the physical volume meta data has become corrupted, missing, or severely damaged, then LVM will consider that disk as an “unknown device” and ignore it. The below procedure can be used to rebuild lvm from the archive. Before proceeding with the action plan, please take a backup of directory /etc/lvm.

# cp -pr /etc/lvm /etc/lvm_bkp

1. First find the backed up configurations of Volume Group (vg1 in this case)

# vgcfgrestore --list vg1

File: /etc/lvm/archive/vg1_00000-1238318622.vg
VG name: vg1
Description: Created *before* executing 'vgcreate vg1 /dev/sda6'
Backup Time: Mon Feb 29 10:58:51 2016

File: /etc/lvm/archive/vg1_00001-285796155.vg
VG name: vg1
Description: Created *before* executing 'lvcreate -L 1G -n lv2 vg1'
Backup Time: Mon Feb 29 10:59:23 2016

File: /etc/lvm/archive/vg1_00002-1661997476.vg     ---> just before removal of volume (this is the archive we need)
VG name: vg1
Description: Created *before* executing 'lvremove /dev/vg1/lv2'
Backup Time: Mon Feb 29 13:55:08 2016

File: /etc/lvm/backup/vg1
VG name: vg1
Description: Created *after* executing 'lvremove /dev/vg1/lv2' 
Backup Time: Mon Feb 29 13:55:08 2016

2. Create partition (Ex: /dev/sdb1 ). Recovering Physical Volume Metadata, Use the –uuid and –restorefile arguments of the pvcreate command to restore the physical volume.

# pvcreate --uuid "6OZVZF-2CPS-Fo0r-hHsy-EFwN-LFMm-7LwJjK" --restorefile /etc/lvm/archive/vg1_00002-1661997476.vg /dev/sdb1
Warning : You should not attempt this procedure with a working LVM logical volume. You will lose your data if you specify the incorrect UUID.

3. Recover the LVM partition using vgcfgrestore and archive file and verify.

# vgcfgrestore -f /etc/lvm/archive/vg1_00002-1661997476.vg vg1
Restored volume group vg1
# vgdisplay VG1

4. Activate the Volume Group.

# vgchange -ay VG1

5. Display the logical volumes

# lvs -a -o +devices

6. The following commands activate the volumes and display the active volumes.

# lvscan
inactive '/dev/vg1/lv2' [1.00 GiB] inherit      ### its in inactive state and make it active to use.
ACTIVE '/dev/vg0/lv1' [1.00 GiB] inherit
# lvchange -a y /dev/vg1/lv2

7. Verify the lvm status

# lvs -a -o +devices
# lvscan
ACTIVE '/dev/vg1/lv2' [1.00 GiB] inherit
ACTIVE '/dev/vg0/lv1' [1.00 GiB] inherit

8. Mount LVM and verify the mount access and data available.

# mount /dev/vg1/lv2 /lv2
# df -h /lv2
Filesystem                Size    Used   Avail   Use%     Mounted on
/dev/mapper/vg1-lv2       976M    1.3M   924M    1%       /lv2
Related Post