• 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

How to Create An LVM Snapshot Of The Root Filesystem And Restore To An Earlier State

by admin

The Task

Create an LVM snapshot of the root filesystem. Revert Snapshot Changes To An Earlier State.

The Solution

1. Before proceeding make sure LVM Volume Group (VG) has enough space for the snapshot.

# vgs
VG  #PV  #LV  #SN   Attr    VSize   VFree
ol   2    2    0    wz--n-  12.00g  1.01g

2. In this example we are creating a root snapshot of 512M. Here “snap” is the snapshot name of a root volume.

# lvcreate -L 512M -s -n snap /dev/ol/root
Logical volume "snap" created.

3. Verify the snapshot created.

# lvs
LV    VG   Attr       LSize Pool   Origin  Data% Meta% Move Log Cpy%Sync Convert
root  ol   owi-aos--- 9.79g
snap  ol   swi-a-s--- 512.00m       root   0.01 
swap  ol   -wi-ao---- <1.20g

4. Verify the snapshot functioning.

# fallocate -l 100m test.img
# lvs
LV    VG  Attr       LSize Pool  Origin  Data% Meta% Move Log Cpy%Sync Convert
root  ol  owi-aos--- 9.79g
snap  ol  swi-a-s--- 512.00m      root   0.03 
swap  ol  -wi-ao---- <1.20g
# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test.img tmp usr var 

Note that the snapshot volume is larger.

5. Merge the snapshot. When the merge finishes, the merged snapshot will be removed.

# lvconvert --merge /dev/ol/snap
Delaying merge since origin is open.
Merging of snapshot ol/snap will occur on next activation of ol/root.

6. Map Logical value (LV) to Physical volume (PV):

# lvs -ao +devices
LV     VG   Attr       LSize Pool  Origin Data% Meta% Move Log Cpy%Sync Convert Devices
root   ol   Owi-aos--- 9.79g                                                   /dev/sda2(307)
[snap] ol   Swi-a-s--- 512.00m      root   0.05                                /dev/sdb(0)
swap   ol   -wi-ao---                                                          /dev/sda2(0)

7. The snapshot should merge during boot and the boot should complete successfully.

# reboot
# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var

Filed Under: CentOS/RHEL 6, CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. How To Separate Each Of Syslog Client’s Messages Into Different File (CentOS/RHEL 6 and 7)
  2. CentOS/RHEL – How to Remove stale ISCSI Target Node Information from ISCSI Initiator Server
  3. How to make alias command work in bash script or bashrc file
  4. sm: command not found
  5. slapt-get: command not found
  6. “aws ses” Command Examples
  7. How to Integrate CentOS/RHEL system into an AD Domain with LDAP/Kerberos/SSSD
  8. aa-complain: command not found
  9. chroot: Run command or interactive shell with special root directory
  10. gh run: View, run and watch recent GitHub Actions workflow runs

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