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
stunnel basics and pki standards
Viewed 9315 times since Fri, Sep 28, 2018
How To: Create Self-Signed Certificate – OpenSSL
Viewed 2805 times since Mon, Feb 18, 2019
Linux How to reset a root password on Fedora
Viewed 2344 times since Sun, Dec 6, 2020
Method 2 – Use shell scripts How to install yum cron on a CentOS/RHEL 6.x/7.x
Viewed 3979 times since Tue, Dec 4, 2018
RHEL: Remove existing SAN LUNs
Viewed 13905 times since Sat, Jun 2, 2018
systemctl Use systemd to Start a Linux Service at Boot
Viewed 5556 times since Mon, Dec 7, 2020
tcpdump usage examples
Viewed 2160 times since Fri, Jul 27, 2018
RHEL: Building a custom kernel on RHEL 6
Viewed 3914 times since Sat, Jun 2, 2018
RHEL: Handling SCSI disks
Viewed 12188 times since Sun, May 27, 2018
How to disable SSH cipher/ MAC algorithms for Linux and Unix
Viewed 45205 times since Fri, Aug 21, 2020