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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to recover deleted Logical volume (LV) in LVM using vgcfgrestore

by admin

You have accidentally removed a logical volume lv01 from the Volume group vg01. Now you want to recover the LV without losing the data. Follow the steps given below to recover LV (lv01) under VG (vg01).

# lvremove vg01/lv01
Do you really want to remove active logical volume vg01/lv01? [y/n]: y
  Logical volume "lv01" successfully removed

Recovering remove LV

1. Verify the archive file under the directory /etc/lvm/archive when the logical volume was removed. In my case the file with latest timestamp under the /etc/lvm/archive directory will have the required information on the deleted volme lv01.

# cd /etc/lvm/archive/
# ls -lrt
total 16
-rw-------. 1 root root 1752 Oct 11 22:20 cl_00000-2084244320.vg
-rw-------. 1 root root 1111 Oct 13 20:05 vg01_00000-1050327195.vg
-rw-------. 1 root root 1112 Oct 13 20:06 vg01_00001-86976415.vg
-rw-------. 1 root root 1515 Oct 13 20:09 vg01_00002-1315455408.vg

2. Before running the actual restore you can do a dry run using the –test switch as shown below.

# vgcfgrestore vg01 --test -f /etc/lvm/archive/vg01_00002-1315455408.vg 
  TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
  Restored volume group vg01

3. If the above dry run is successful, do the actual restore.

# vgcfgrestore vg01  -f /etc/lvm/archive/vg01_00002-1315455408.vg 
  Restored volume group vg01

4. Verify if the deleted volume has been successfully restored or not using ‘lvscan’.

# lvscan
  inactive          '/dev/vg01/lv01' [10.00 GiB] inherit
  ACTIVE            '/dev/cl/swap' [2.00 GiB] inherit
  ACTIVE            '/dev/cl/root' [17.00 GiB] inherit

5. As shown in the output the Logical volume lv01 is successfully restored from the metadata backup of VG. Activate the LV to access the data onto it.

# lvchange -a y /dev/vg01/lv01

6. Mount the logical volume and verify if the data is intact.

# mount /dev/mapper/vg01-lv01 /data
# ls /data
file1  file2  file3  lost+found
# df -hP /data
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/vg01-lv01  9.8G   37M  9.2G   1% /data

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to view file size/details from ls command in Unix
  2. 10 Sed (Stream Editor) Command Examples
  3. CentOS / RHEL : How to exclude kernel or other packages from getting updated using YUM Versionlock Plugin
  4. How to Set External Network For Containers in Linux Containers (LXC)
  5. What is the purpose of “mysql.sys@localhost” user
  6. How to Display Routing Table in Linux
  7. How to disable IPv6 on CentOS / RHEL 7
  8. Shell Script to Find Network Interface Link Status and Speed (CentOS/RHEL)
  9. CentOS / RHEL : How to Disable / Enable direct root and non-root user ssh login
  10. How to copy directories recursively using rsync while excluding specific files

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright