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
-
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 ] } } }
-
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
-
Now reboot the server into the Rescue System.
-
Once you're logged into the Rescue System, please
mount
the partition that contains thelvm_backup_file
, copy it to the Rescue System's filesystem, and thenumount
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
-
Verify and that none of the partitions is mounted anymore:
lsblk
-
Output the content of the
lvm_backup_file
usingcat
, 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 [...]
-
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
-
Check if the Physical Volume has been created:
pvs
-
Next, restore the Volume Group (VG) by using the command below:
vgcfgrestore –force <vg_name>
Example:
vgcfgrestore –force vg0
-
Sync the Volume Group data:
vgscan
-
Now, check if the Volume Group has been restored properly:
vgs
-
Next, restore the LVM:
vgchange -ay <vg_name>
Example:
vgchange -ay vg0
-
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.