![Recover LVM Partitions In Linux](https://blog.assistanz.com/wp-content/uploads/2023/09/image-364.png)
Have you ever undergone a situation in which you have extended or created an LVM partition but your disk got corrupted and the disks will not be shown while executing the PV(physical volume) display, LV(logical volume) display, and VG(volume group) display. Feel free as this blog aims to reveal the steps to recover the missing LVM partition data in Linux.
Steps to recover the partition
Step 1 :
As we already know LVM has the feature of taking backups of the details of metadata regularly in /etc/lvm/backup/<vg_name> whenever we do any modifications. Now, please verify the file which have all the partitions and size.
“logical_volumes {
root {
id = “j2rlvk-cGYE-fxbN-F8bO-p90r-x0FL-suSNUA”
status = [“READ”, “WRITE”, “VISIBLE”]
flags = []
creation_host = “unassigned-hostname”
creation_time = 1475126039 # 2016-09-29 10:43:59 +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
]
}
}
Step 2 :
Once we have verified all the settings, we need to take the backup of the file and reboot the server into rescue mode.
Step 3:
Once the server got booted to the rescue mode, unmount the root partition disk as like the below command.
#umount /dev/sda1
Step 4 :
After unmounting the root partition disks we need to verify whether all the partitions are unmounted and no mounted on the server. To check whether it is mounted or not use the below command.
#lsblk
Step 5 :
After finishing the checking, upload the backup file of the local volume management’s (LVM) meta data in the rescue server and get the uuid of /dev/sda1 as like below,
physical_volumes {
pv0 {
id = “ck9MZu-UeBT-4boe-IkJU-Q8n7-yfpX-yLK3WY” –> copy this uuid from LVM backup file.
device = “/dev/sda1” # Hint only
Step 6:
Once you have done with the above steps now execute below command in order to create the physical volumes(PV),
#pvcreate –restorefile <lvm-backup-file> –uuid <uuid> <disk>
#Ex: pvcreate –restorefile <lvm-backup-file> –uuid ck9MZu-UeBT-4boe-IkJU-Q8n7-yfpX-yLK3WY /dev/sda1
Step 7:
Now, check whether the physical volume(PV) is created or not,
#pvs
Step 8:
Next, we need to restore and sync the volume group(VG) by executing below command, and additionally in order to check whether the volume group is restored properly check by using the below command,
#vgcfgrestore –force <vg-name>
#vgscan
#vgs
Step 9:
After creating and restoring the physical volume and volume group now we are heading towards the final part of the process (ie) restoring the LVM by using the below command,
#vgchange -ay <vg-name>
If you get any error which is related to the lvm-thin, then you need the package “thin-provisioning-tools”. Install it by using the following command.
#apt install thin-provisioning-tools
Bingo! we had successfully recovered the LVM partition. Now boot up your server into the normal mode and proceed with your operations.
Thank you for taking the time to read our blog on “Learn how to recover the LVM partitions in Linux?.” We hope you found the information valuable and insightful. If you find any issues with the information provided in this blog don’t hesitate to contact us (info@assistanz.com).
Optimize server speed and never lose a valuable customer again!
Our mission is to ensure that your server remains lightning-fast and protected by monitoring and maintaining it 24×7 with our experts.