• 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 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. cp: omitting directory – error while copying a directory in Linux
  2. How to Restrict su Access to a User Only by PAM in Linux
  3. How To Find When The Spfile Was Created On Linux Server
  4. Beginners Guide to NFS in CentOS / RHEL
  5. How To Check World Wide Port Names (WWPN) of Tape Drives Attached to Linux host
  6. How to Disable “Predictable Network Interface Device Names” in CentOS/RHEL 7
  7. dar: command not found
  8. How to Setup VNC Server for New User in CentOS/RHEL 5
  9. apt-key Command Examples in Linux
  10. How To Check Current Values for Kernel Tuning Parameters in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • fprintd-delete Command Examples in Linux
  • fprintd-delete: command not found
  • foreman: command not found
  • foreman Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright