• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

RHEL / CentOS : How to rebuild LVM from Archive (metadata backups)

by admin

Problem : The filesystem was corrupted and the LVM volumes could not be mounted, with the lvm partitions are lost.

Solution :
Metadata backups and archives are automatically created on every volume group and logical volume configuration change unless disabled in the lvm.conf file. By default, the metadata backup is stored in the /etc/lvm/backup file and the metadata archives are stored in the /etc/lvm/archive file. If the physical volume meta data has become corrupted, missing, or severely damaged, then LVM will consider that disk as an “unknown device” and ignore it. The below procedure can be used to rebuild lvm from the archive. Before proceeding with the action plan, please take a backup of directory /etc/lvm.

# cp -pr /etc/lvm /etc/lvm_bkp

1. First find the backed up configurations of Volume Group (vg1 in this case)

# vgcfgrestore --list vg1

File: /etc/lvm/archive/vg1_00000-1238318622.vg
VG name: vg1
Description: Created *before* executing 'vgcreate vg1 /dev/sda6'
Backup Time: Mon Feb 29 10:58:51 2016

File: /etc/lvm/archive/vg1_00001-285796155.vg
VG name: vg1
Description: Created *before* executing 'lvcreate -L 1G -n lv2 vg1'
Backup Time: Mon Feb 29 10:59:23 2016

File: /etc/lvm/archive/vg1_00002-1661997476.vg     ---> just before removal of volume (this is the archive we need)
VG name: vg1
Description: Created *before* executing 'lvremove /dev/vg1/lv2'
Backup Time: Mon Feb 29 13:55:08 2016

File: /etc/lvm/backup/vg1
VG name: vg1
Description: Created *after* executing 'lvremove /dev/vg1/lv2' 
Backup Time: Mon Feb 29 13:55:08 2016

2. Create partition (Ex: /dev/sdb1 ). Recovering Physical Volume Metadata, Use the –uuid and –restorefile arguments of the pvcreate command to restore the physical volume.

# pvcreate --uuid "6OZVZF-2CPS-Fo0r-hHsy-EFwN-LFMm-7LwJjK" --restorefile /etc/lvm/archive/vg1_00002-1661997476.vg /dev/sdb1
Warning : You should not attempt this procedure with a working LVM logical volume. You will lose your data if you specify the incorrect UUID.

3. Recover the LVM partition using vgcfgrestore and archive file and verify.

# vgcfgrestore -f /etc/lvm/archive/vg1_00002-1661997476.vg vg1
Restored volume group vg1
# vgdisplay VG1

4. Activate the Volume Group.

# vgchange -ay VG1

5. Display the logical volumes

# lvs -a -o +devices

6. The following commands activate the volumes and display the active volumes.

# lvscan
inactive '/dev/vg1/lv2' [1.00 GiB] inherit      ### its in inactive state and make it active to use.
ACTIVE '/dev/vg0/lv1' [1.00 GiB] inherit
# lvchange -a y /dev/vg1/lv2

7. Verify the lvm status

# lvs -a -o +devices
# lvscan
ACTIVE '/dev/vg1/lv2' [1.00 GiB] inherit
ACTIVE '/dev/vg0/lv1' [1.00 GiB] inherit

8. Mount LVM and verify the mount access and data available.

# mount /dev/vg1/lv2 /lv2
# df -h /lv2
Filesystem                Size    Used   Avail   Use%     Mounted on
/dev/mapper/vg1-lv2       976M    1.3M   924M    1%       /lv2

Filed Under: Linux

Some more articles you might also be interested in …

  1. module Command Examples in Linux
  2. iptables Command Examples in Linux
  3. ledctl: command not found
  4. How to Run DNS and FTP services in a chroot Jail
  5. ar – Create, modify, and extract from archives (.a, .so, .o)
  6. gnome-screenshot: command not found
  7. taskset Command Examples in Linux
  8. datamash Command Examples in Linux
  9. git annotate: Show commit hash and last author on each line of a file
  10. gbp Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • “glab pipeline” Command Examples
  • “glab mr” Command Examples
  • “glab mr merge” Command Examples
  • “glab mr” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright