Post date: Oct 09, 2018 8:28:37 PM
In this post I'll detail how I use a simple shell script I wrote as a dracut module to implement systems snapshot on a Linux VM using LVM. It does require free / extra space in the volume group for the snapshot volume pool, if you're working with virtual system, this can easily be added but on physical systems may require some forethought when building the system to not allocate all the space in the volume group up front.
To use this module, first extract the files into /usr/lib/dracut/modules.d:
cd /usr/lib/dracut/modules.d
tar xvf snapreset.tar
Now edit /etc/dracut.conf, add the liine:
add_dracutmodules+="snap-reset"
Next, you need to set the variables in /usr/lib/dracut/modules.d/40snap-reset/snap-reset.sh
set VG to be the name of your root volume group
THINLV will be the name of the thinpool volume that gets created
VOLS needs to be set to space separated list of all logical volumes that need to be snapshot
ROOTVOL needs to be the name of the logical volume for /
After those variables are set, we need to make a copy of /etc/fstab to be used for mounting snapshot volumes:
cd /etc
cp fstab fstab.snap
vi fstab.snap (edit each volume mount and add "_snap" to each logical volume name, remove /boot mount here if desired)
Now we'll want to add new boot options to grub menu:
vi /etc/grub2.conf
add "ORIGINAL" to running configuration label
copy running configuration, change ORIGINAL to SNAPSHOT and change all lvm volumes to include "_snap", and add kernel parameter snapCOW
copy running configuration, change ORIGINAL to SNAPRESET and change all lvm volumes to include "_snap", and add kernel parameter snapreset
now we need to install the new configuration:
grub2-install /dev/sda (or whatever your boot disk is)
We need to rebuild the initrd now to include the new dracut module
cp initramfs-3.10.0-862.el7.x86_64.img initramfs-3.10.0-862.el7.x86_64.img.bak (replace initrd filename with your current, from grub config)
dracut -v -f initramfs-3.10.0-862.el7.x86_64.img (replace file name with your current , from grub config)
From here, boot order is important because systemd will hang if the logical volumes specified on the kernel commandline don't exist. Boot ORIGINAL, then SNAPRESET to build snapshots, then from there you boot SNAPSHOT unless you want to revert back (SNAPRESET), or alter original volume state (ORIGINAL).