How to restore LVM Volume Group metadata from a previous configuration
This article explains how to recover LVM Volume Group metadata to the physical volume using the vgcfgrestore command. Due to several reason a volume group may become corrupted after unintended user intervention.
This article explains how to recover LVM Volume Group metadata to the physical volume using the vgcfgrestore command. Due to several reason a volume group may become corrupted after unintended user intervention. A very common situation is to incorrectly use the pvcreate to an alternate path of a physical volume already in use by a volume group. LVM will not be aware of this situation unless the alternate is already on the volume group, and may allow to add the alternate path to a different volume group.
The vgdisplay command will show no problem until the system is rebooted or the original volume group is reactivated.
Let's assume that accidentally the pvcreate -f command was run on the c20t0d0 physical volume, that is an alternate path of c19t0d0.
The vgdisplay command shows two disks, both are available, the current and active PV shows the same number (2).
Up to this point everything looks fine, but actually behind the scene when the pvcreate -f command was run on c20t0d0 it overwrote the header configuration on the physical volume. That is why LVM report two different disks, when actually both are the same.
When the server was rebooted, LVM was not able to understand the configuration and the problem reveals itself.
The following procedure will require a valid prior LVM volume group configuration file and also a map file.
1. Make sure the volume group is deactivated.
# vgchange -a n /dev/<vgname> Volume group "<vgname>" has been successfully changed.
2. Verify the PV list in the configuration file shows the previous configuration. In this case we are assumming that the user added a second disk to the VG, old configuration file will show only one:
# vgcfgrestore -f /dev/lvmconf/<vgname>.conf.old Volume Group Configuration information in "<vgname>.conf.old" VG Name /dev/<vgname> ---- Physical volumes : 1 ---- /dev/rdsk/c#t#d0 (Non-bootable)
3. Restore the VG header information from previous configuration file. It should be restore to the old physical volume.
# vgcfgrestore -f /etc/lvmconf/<vgname>.conf.old /dev/rdsk/c#t#d# Volume Group configuration has been restored to /dev/rdsk/c3t15d0
4. Remove VG configuration out of the lvmtab.
# vgexport /dev/<vgname>
5. Recreate VG directory:
# mkdir /dev/<vgname>
6. Recreate the volume group "group" node file. Remember that the minor number must be unique.
# mknod /dev/<vgname>/group c 64 0x0#0000
7. Reimport the volume group. LV structures will be recover from map file.
# vgimport -m /tmp/<vgname>.map /dev/<vgname> /dev/dsk/c#t#d# Warning: A backup of this volume group may not exist on this machine. Please remember to take a backup using the vgcfgbackup command after activating the volume group.
8. Reactivate volume group. Some warning messages may be received.
# vgchange -a y /dev/<vgname> Volume group "<vgname>" has been successfully changed.
9. Verify the current LVM configuration. Some parameters to check are current and active PV number (both should be the same), the Used PVs parameter for each logical volume and the status of the PV (Should be available):
# vgdisplay -v /dev/<vgname> --- Volume groups --- VG Name /dev/<vgname> VG Write Access read/write VG Status available Max LV 255 Cur LV 1 Open LV 1 Max PV 16 Cur PV 1 Act PV 1 Max PE per PV 1000 VGDA 2 PE Size (Mbytes) 4 Total PE 1000 Alloc PE 100 Free PE 900 Total PVG 0 Total Spare PVs 0 Total Spare PVs in use 0 --- Logical volumes --- LV Name /dev/<vgname>/test LV Status available/syncd LV Size (Mbytes) 400 Current LE 100 Allocated PE 100 Used PV 1 --- Physical volumes --- PV Name /dev/dsk/c#t#d# PV Status available Total PE 1000 Free PE 900 Autoswitch On Proactive Polling On
How to use vgcfgrestore on every physical volume of a volume group?
This script allows to use the vgcfgrestore command on every physical volume of a particular volume group. Because vgcfgrestore will pass through all primary and alternate path, the volume group needs to be deactivated.
for pv in $(strings /etc/lvmconf/<vgname> | grep /dev/r | sed 's/\/r/\//') do echo vgcfgrestore -n <vgname> $pv done
for pv in $(strings /etc/lvmconf/vgdata | grep /dev/r | sed 's/\/r/\//') do echo vgcfgrestore -n vgdata $pv done > /tmp/vgdata.vgcfgrestore sh /tmp/vgdata.vgcfgrestore
- HP-UX System Administration Tasks: HP 9000 - Chapter 3 Managing Disks Using the Logical Volume Manager (LVM) - An Introduction to the Logical Volume Manager