Fixing LVM metadata corruption on Linux servers
LVM volume group metadata gets corrupted after a crash or bad disk. Here's how to recover your data without losing everything.
When this error hits
You reboot a Linux server after a power loss or kernel panic. And then you see it: Volume group "vg_data" not found or Can't open /dev/vg_data/lv_home. Maybe pvscan shows your physical disk but the volume group is missing. I had a client last month whose file server died during a UPS failure. The RAID was fine, the disks were fine, but LVM just couldn't see the volume group. That's metadata corruption.
Root cause – what went wrong
LVM stores metadata in two places: on the disk itself (usually at the start of each physical volume) and in a backup file at /etc/lvm/backup/. When something crashes mid-write – like a resize, a snapshot merge, or a failed pvcreate – the on-disk metadata gets scrambled. The kernel can't read it, so the volume group vanishes. The backup file is often still good, but only if you didn't overwrite it after the corruption.
Step-by-step fix
Do not reboot again. Do not run pvcreate or vgcreate. You'll wipe the metadata for good. Work from single-user mode or a live CD. I prefer SystemRescue, but any Linux live USB works.
- Boot into single-user mode or a live environment. If you're on a remote server, you might need IPMI or a console. No network? Use a live USB physically.
- Find your physical volumes. Run
lvm pvsorpvscan. If you see a device listed but withunknown deviceor missing metadata, you're in the right place. - Check the backup files. Look in
/etc/lvm/backup/. You'll see a file named after the volume group, likevg_data. Open it withcat /etc/lvm/backup/vg_data. If it has ametadatasection with acreation_timeand a list of physical volumes, you're in luck. If the file is empty or missing, skip to the alternative fix below. - Try a manual restore from backup. Use
vgcfgrestore -f /etc/lvm/backup/vg_data vg_data. This writes the backup metadata back to the physical disks. Be sure you're restoring the right volume group name. - Activate the volume group. Run
vgchange -ay vg_data. Check withlvsandmountto see if your logical volumes are back. If they mount, you're done. - If vgcfgrestore fails – it might say
Can't open vg_dataorVolume group not found. That means the backup has a different UUID or timestamp than the disks. In that case, you need to scan for old metadata on the disk itself.
Alternative fix – manual metadata recovery with pvck
If the backup is no good, you need to dig metadata straight off the disk. pvck is your tool. But it's dangerous and you must know exactly what you're doing.
- Run pvck on each physical volume. Example:
pvck /dev/sda1. It will show you metadata areas and labels. Look for lines likeFound label at sector 1andFound metadata at sector X. - Dump the metadata to a file. Use
pvck --dump metadata /dev/sda1 > /tmp/metadata.txt. This gives you the raw metadata. - Read the metadata file. It's a text file with sections like
physical_volumes,logical_volumes, andmetadata_hash. Check if the UUIDs match what you expect. If you see entries forlv_root,lv_swap, etc., you're on the right path. - Restore the metadata manually. Use
vgcfgrestore -f /tmp/metadata.txt vg_data. This is risky because the file's format must be exact. If it works, great. If not, you might need to reconstruct the metadata by hand – that's beyond this guide. - If pvck finds nothing – the metadata is completely gone. You can try
pvcreate --uuid "original-uuid" --restorefile /dev/null /dev/sda1to mark the disk as a PV without wiping data, but only if you have a backup of the UUID from/etc/lvm/archive/. Otherwise, you're looking at a full restore from backup.
What to check if it still fails
If the steps above don't work, here's what to look at next:
- Check the backup archive. Go to
/etc/lvm/archive/. There are multiple backup files with timestamps. Try an older one. Sometimes the most recent backup is also corrupt. - Check for duplicate UUIDs. Run
blkidon all your disks. If two devices have the same UUID, LVM gets confused. Usepvchange -u /dev/sdb1to assign a new UUID to one of them. - Check the disk health. Run
smartctl -a /dev/sda(or your device). If the disk has bad sectors, the metadata might be in a bad block. In that case, you need to replace the disk and restore from backup. - Check if the volume group is exported. Run
vgexport -athenvgimport -ato re-import all volume groups. Sometimes the metadata just needs a refresh. - If nothing works, do a file-level recovery. Use
fsckon the raw partition (without LVM) if you can. Or usetestdiskto scan for lost partitions. It's ugly but it can save your data.
One last thing – always keep a current backup of your LVM metadata. Put vgcfgbackup -f /backup/lvm-%m-%d-%Y in your cron. It takes seconds and saves you hours of headache. Learned that one the hard way.
Was this solution helpful?