Recovery of LVM Volumes

Last change on 2021-05-12 • Created on 2020-06-04 • ID: RO-84880

This article provides a guide for restoring a missing volume and the data on it when using LVM (Logical Volume Manager).

The problem/issue

The LVM meta data of a Linux system is corrupted and the drives or partitions are not displayed when executing, PVdisplay, LVdisplay or VGdisplay.

Restoring the missing volume

  1. LVM will always make the backup of its meta data in /etc/lvm/backup/<vg_name> (VG ~ Volume Group) after a modification. Please verify this file is present and that it has all volumes and their sizes listed inside:

    logical_volumes {
    	root {
    		id = "j5rlvk-cGYE-fxbN-F8bO-p90r-x0FL-suSAUN"
    		status = ["READ", "WRITE", "VISIBLE"]
    		flags = []
    		creation_host = "unassigned-hostname"
    		creation_time = 1475126039 # 2020-05-03 10:42:51 +0530
    		segment_count = 2
    		segment1 {
    			start_extent = 0
    			extent_count = 6425 # 25.0977 Gigabytes
    			type = "striped"
    			stripe_count = 1 # linear
    			stripes = [
    				"pv0", 0
    			]
    		}
    		segment2 {
    			start_extent = 6425
    			extent_count = 15360 # 60 Gigabytes
    			type = "striped"
    			stripe_count = 1 # linear
    			stripes = [
    				"pv1", 0
    			]
    		}
    	}
    }
  2. Once you have quickly verified all the settings, save a backup of this file:

    cat /etc/lvm/backup/<vg_name> > /path/to/lvm_backup_file

    Example:

    cat /etc/lvm/backup/vg0 > /media/storage/lvm_backup_file
  3. Now reboot the server into the Rescue System.

  4. Once you're logged into the Rescue System, please mount the partition that contains the lvm_backup_file, copy it to the Rescue System's filesystem, and then umount the partition:

    mount /dev/<partition> /mnt
    cp /mnt/path/to/lvm_backup_file lvm_backup_file
    umount /mnt

    Example:

    mount /dev/sdb1 /mnt
    cp /media/storage/lvm_backup_file lvm_backup_file
    umount /mnt
  5. Verify and that none of the partitions is mounted anymore:

    lsblk
  6. Output the content of the lvm_backup_file using cat, and copy the UUID (Universally Unique Identifier) of the corresponding <partition>:

    cat lvm_backup_file
    physical_volumes {
    	pv0 {
    		id = "ek9MZu-UeBK-4boe-IkJU-Q4n7-yfpX-yLK1WY" –> copy this UUID
    [...]
  7. Once you're done, use the command below to create the Physical Volume (PV):

    pvcreate –restorefile lvm_backup_file –uuid <uuid> <partition>

    Example:

    pvcreate –restorefile lvm_backup_file –uuid ek9MZu-UeBK-4boe-IkJU-Q4n7-yfpX-yLK1WY /dev/sda1
  8. Check if the Physical Volume has been created:

    pvs
  9. Next, restore the Volume Group (VG) by using the command below:

    vgcfgrestore –force <vg_name>

    Example:

    vgcfgrestore –force vg0
  10. Sync the Volume Group data:

    vgscan
  11. Now, check if the Volume Group has been restored properly:

    vgs
  12. Next, restore the LVM:

    vgchange -ay <vg_name>

    Example:

    vgchange -ay vg0
  13. Finally, please restart the server and let it boot into the installed system. Please verify that the data is intact there. If you still face issues, please consider performing a filesystem check.

Table of Contents