LVM: Recovering Physical Volume Metadata

LVM: Recovering Physical Volume Metadata

# Tested on RHEL 5, 6 & 7

# If the volume group metadata area of a physical volume is accidentally overwritten or
# otherwise destroyed, you will get an error message indicating that the metadata area is
# incorrect, or that the system was unable to find a physical volume with a particular UUID.

   Couldn't find device with uuid 7GCY3s-1LYB-fhAF-kvu0-cCDm-9Q6m-s6xAQd.
   Couldn't find device with uuid 48rLN6-ztLy-nzqS-GM2a-9yvB-Cua5-wU826d.


# You may be able to recover the data the physical volume by writing a new metadata area
# on the physical volume specifying the same UUID as the lost metadata.

# UUID for the physical volume that was overwritten can be found in the /etc/lvm/archive
# directory. Look in the file
testvg_<00044-439430220>.vg for the last known valid
# archived LVM metadata for that volume group.


# If possible, before beginning, take a backup of F.S. existing on the Volume Group

VG=testvg

# umount F.S.

FS=""

for LV in `lvs --noheadings /dev/$VG | awk '{print$1}'`; do FS="$FS `mount | grep "$VG-$LV" | awk '{print$3}'`"; done

for FS in $FS; do umount $FS; done


# Deactivate the Volume Group

vgchange -an --partial $VG
  Partial mode. Incomplete volume groups will be activated read-only.
  0 logical volume(s) in volume group "testvg" now active



# Restore the right UUID (the lost ones) on the adequate Physical Volumes (match between disk
# and UUID can be found in valid /etc/lvm/archive/
testvg_<00044-439430220>.vg file)

pvcreate -ff --uuid "7GCY3s-1LYB-fhAF-kvu0-cCDm-9Q6m-s6xAQd" --restorefile /etc/lvm/archive/testvg_00044-439430220.vg /dev/mpath/mpath9p1
   Really INITIALIZE physical volume "/dev/mpath/mpath9p1" of volume group "testvg" [y/n]? y
      WARNING: Forcing physical volume creation on /dev/mpath/mpath9p1 of volume group "testvg"
      Physical volume "/dev/mpath/mpath9p1" successfully created


pvcreate -ff --uuid "48rLN6-ztLy-nzqS-GM2a-9yvB-Cua5-wU826d" --restorefile /etc/lvm/archive/testvg_00044-439430220.vg /dev/mpath/mpath12p1
   Really INITIALIZE physical volume "/dev/mpath/mpath12p1" of volume group "testvg" [y/n]? y
     WARNING: Forcing physical volume creation on /dev/mpath/mpath12p1 of volume group "testvg"
     Physical volume "/dev/mpath/mpath12p1" successfully created



# Restore Volume Group's metadata

vgcfgrestore $VG
   Restored volume group testvg


# Activate Logical Volumes

for LV in `l
vs --noheadings /dev/$VG | awk '{print$1}'`
do
   lvchange -ay /dev/$VG/$LV
done



# Verify that Logical Volumes are available

vgdisplay -v $VG | egrep "LV Name|LV Status"

# Check that you don't have the errors regarding the devices not found

   Couldn't find device with uuid 7GCY3s-1LYB-fhAF-kvu0-cCDm-9Q6m-s6xAQd.
   Couldn't find device with uuid 48rLN6-ztLy-nzqS-GM2a-9yvB-Cua5-wU826d.



# Mount F.S.

# If declared in /etc/fstab:
for FS in $FS; do mount $FS; done
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
LVM: Create a new Logical Volume / Filesystem
Viewed 2153 times since Sat, Jun 2, 2018
LVM: Create a new Volume Group
Viewed 2156 times since Sat, Jun 2, 2018
linux ssh Remotely Initiated Reverse SSH Tunnel
Viewed 3253 times since Wed, Apr 22, 2020
RHEL: Displaying/setting kernel parameters - ’sysctl’
Viewed 3102 times since Sat, Jun 2, 2018
Tunnel SSH Connections Over SSL Using ‘Stunnel’ On Debian 7 / Ubuntu 13.10
Viewed 3381 times since Fri, Sep 28, 2018
Migrate a Linux System from Red Hat Enterprise to CentOS
Viewed 10412 times since Fri, May 15, 2020
7 Tips – Tuning Command Line History in Bash
Viewed 5515 times since Fri, Jul 5, 2019
Linux Cluster Tutorial
Viewed 2210 times since Sat, Sep 29, 2018
Linux Screen
Viewed 2110 times since Sat, Jun 2, 2018
RHEL: Extending a vmdk (Virtual Machine disk)
Viewed 4249 times since Sun, May 27, 2018
Recently Viewed
Linux Customizing Bash