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
How to deal with dmesg timestamps
Viewed 2756 times since Wed, Oct 3, 2018
Enabling or disabling a repository using Red Hat Subscription Management
Viewed 7891 times since Mon, Oct 29, 2018
SSH ProxyCommand example: Going through one host to reach another server
Viewed 12990 times since Tue, Aug 6, 2019
SSL HowTo: Decode CSR
Viewed 4456 times since Mon, Feb 18, 2019
Method 2 – Use shell scripts How to install yum cron on a CentOS/RHEL 6.x/7.x
Viewed 3844 times since Tue, Dec 4, 2018
HowTo: Find Out Hard Disk Specs / Details on Linux
Viewed 2965 times since Mon, Jan 28, 2019
Tcpdump Examples Linux
Viewed 5577 times since Fri, Nov 16, 2018
Linux 20 Netstat Commands for Linux Network Management
Viewed 9180 times since Mon, Sep 21, 2020
debian Debian/Ubuntu Linux: Find If Installed APT Package Includes a Fix/Patch Via CVE Number
Viewed 9163 times since Sun, Sep 23, 2018
Linux - How to get IP and MAC address of ethernet adapter in Linux
Viewed 2376 times since Fri, Jun 8, 2018