Hubba's Blog

Notes from a Linux/Unix Engineer

Archive for November 2026

Using Linux LVM snapshots (RHEL)

Posted on Thu, Nov 12, 2026 at 16:06 by Hubertus A. Haniel

This was mainly tested on RHEL8 with some tests on RHEL9 and 10:

LVM snapshots are not like what most people may have seen with snapshots in things like VMware etc where the original file system gets frozen and all the changes are written to another file and when the snapshot is deleted the changes are committed to the original file system.

With LVM changes are still being written to the original volume/file system but the original blocks that are being changed are being pushed out to a snapshot volume. - This means that we can create snapshots and delete them at will without having to play back the changes but it means that we will have increased I/O when we roll back a snapshot for a certain amount of time until everything gets synced again.

When taking a snapshot there are however a few considerations to take:

  • While there is a snapshot in place for a logical volume / file system the logical volume can not be resized so if we run out of space on the file system we need to delete the snapshots first before we can resize it.
  • The snapshot volume will have a size associated with it as well - Now the snapshot volume does not have to be the same size as the actual original volume but it has to be big enough to hold all the changes which may be written to it. It is possible to resize the snapshot volume and there are ways to have it increase it's size automatically but if the volume group runs out of space the snapshot will still become stale if it fills up.
  • If a snapshot volume fills up it will become invalid and should not be rolled back to. - Rolling back to an invalid snapshot will corrupt the original volume but if that snapshot is deleted no harm will come to the original volume.
  • For rollback the file system/original volume must be unmounted. In the case of the root file system the rollback can be initiated while running but to actually roll back a reboot is required.
  • In the case of patching - /boot is not part of LVM generally and in case of EFI boot the EFI partition will not be either so that will have to be taken care off in another way.

In this example I am assuming all file systems for the root file system are on one logical volume - If this is not the case things get a little bit more tricky to make sure that all the correct file systems are in sync - For example if /var is on a separate volume which is the case in some environment as historically people thing /var contains nothing important. Well on RPM based systems like Redhat the rpm database is kept in /var and if it becomes out of sync with the rest of the system it can create some drastic problems going forward so if / is rolled back then /var needs to be rolled back as well.

The creation of a snapshot is quite simple - on my test system I have rootvg/rootlv as the root file system:

lvcreate -L 10G -s -n rootlv_snapshot /dev/rootvg/rootlv

This will create a 10Gb snapshot of my 20Gb rootlv of which I am currently using 10%.
I can inspect this with lvs:

[root@kvm-testvm:~]# lvs
  LV              VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  rootlv          rootvg owi-aos--- 25.00g
  rootlv_snapshot rootvg swi-a-s--- 10.00g      rootlv 0.03
  swaplv          rootvg -wi-ao----  4.00g
[root@kvm-testvm:~]#

This is where we can see the usage of the space in the snapshot as well as the "Attr" column which will become important if the usage (Data%) gets to 100% as a "I" will indicate that the snapshot has become invalid. I am now going to write some data to this disk with something like:

dd if=/dev/zero of=/bigfile1 bs=1024 count=5000000

This will create a file which is about 5Gb in size and while that was going on some other things where running but lvs now show that I am using 58.6% of that snapshot:

[root@kvm-testvm:~]# lvs
  LV              VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  rootlv          rootvg owi-aos--- 25.00g
  rootlv_snapshot rootvg swi-a-s--- 10.00g      rootlv 58.06
  swaplv          rootvg -wi-ao----  4.00g

This space will not be claimed back even though if I remove the file while it may free up file system space on the original volume:

[root@kvm-testvm:~]# rm /bigfile1
rm: remove regular file '/bigfile1'? y
[root@kvm-testvm:~]# lvs
  LV              VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  rootlv          rootvg owi-aos--- 25.00g
  rootlv_snapshot rootvg swi-a-s--- 10.00g      rootlv 58.09
  swaplv          rootvg -wi-ao---- 4.00g

This shows that the blocks that have changed in the logical volume have been pushed out to the snapshot so I can write data again to the same blocks and it will not necessarily increase the usage on the snapshot.

We could now just delete the snapshot with "lvremove /dev/rootvg/rootlv" if we want to discard it but for the sake of it I will recreate the file and revert the snapshot the snapshot which is done with "lvconvert" which will require a reboot (after which the file will be gone again as well):

[root@kvm-testvm:~]# lvconvert --merge /dev/rootvg/rootlv_snapshot
  Delaying merge since origin is open.
Merging of snapshot rootvg/rootlv_snapshot will occur on next activation of rootvg/rootlv.

If this is done in a patching situation it is important to remember which kernel we are currently running or where running when the snapshot is taken as /boot may still contain a different kernel but none of the kernel modules for any newer kernel will be on the snapshot so the system will not be able to boot into a kernel that was not present when the snapshot was taken.

The once the system is booted "lvs" will show that the snapshot volume is gone and we are back on the normal system while e in the back ground the syncing is still taking place which can be seen with "dmsetup":

[root@kvm-testvm:~]# dmsetup status
rootvg-rootlv: 0 52428800 snapshot-merge 10140208/20971520 39464
rootvg-rootlv-real: 0 52428800 linear
rootvg-rootlv_snapshot: 0 52428800 error
rootvg-rootlv_snapshot-cow: 0 20971520 linear
rootvg-swaplv: 0 8388608 linear
[root@kvm-testvm:~]# dmsetup status
rootvg-rootlv: 0 52428800 snapshot-merge 6373616/20971520 24808
rootvg-rootlv-real: 0 52428800 linear
rootvg-rootlv_snapshot: 0 52428800 error
rootvg-rootlv_snapshot-cow: 0 20971520 linear
rootvg-swaplv: 0 8388608 linear

The command has been run twice here with a small break in between and it shows the snapshot-merge going on in the background which may impact performance at the moment and it is not recommended to create any new snapshots while this is in progress but we can see the blocks that are remaining decreasing at a steady rate and the OS will take care of the rest once this is complete and the output will get back to something like:

[root@kvm-testvm:~]# dmsetup status
rootvg-rootlv: 0 52428800 linear
rootvg-swaplv: 0 8388608 linear

On Redhat there is a tools called boom-boot which will let you boot directly into a snapshot as you can not mount a snapshot at the same time while you have the file system actual file system open.

Booting into a snapshot using boom:

This may not work correctly if the root file system is split into multiple file systems (like separate var) and it may need additional tweaking.

To do this we need to install the boom-boot package first with "yum install boot-boom" - For this to be integrated into grub after the installation of that package we need to regenerate the grub config file with "grub2-mkconfig -o /boot/grub2/grub.cfg" on an EFI system depending on the Redhat version the grub config may be in another location such as /boot/efi/EFI/redhat/grub.cfg but on modern versions of RHEL this file is just a hook back to the original so do not overwrite the wrong file.

Now we need to create the boom OS profile with "boom profile create --from-host --uname-pattern el8" which can then be queried with "boom profile list"

"boom list" should now list the usual grub entries. So we are now in the position to create a boot entry on the fly:

    
  boom create --title "Snapshot before changes" --rootlv rootvg/rootlv_snap

--backup can be specified on the above line so the kernel and initramfs will get backed up as well but I am going beyond on what this post was originally for.





Edited on: Mon, Nov 16, 2026 16:06

Posted in HowTo (RSS), System - Linux (RSS)