When you are working in your lab, you regularly need to reinstall your virtual machine to start a new configuration.
If you use a tool like Virtual Box, you can save virtual machine images and restore them.
But if you use KVM, you can’t do that, and it takes time to reinstall the system.
To avoid this waste of time, you can set up your virtual machine inside a unique volume group (here vg_root with at least 1GB of free space) and use the snapshot feature available since RHEL6. This way, you only need to reboot and wait one or two minutes (the time for the snapshot to be restored).
The command is called snap and takes one parameter:
– begin: to start the snapshot,
– rollback: to destroy the snapshot and remove all the previous changes,
– commit: to destroy the snapshot and keep the changes.
#!/bin/sh if [ "$#" -ne "1" ]; then echo "Syntaxe: snap [begin|commit|rollback]" exit fi case $1 in begin) lvcreate --size 1G -s --name lv_snap /dev/vg_root/lv_root ;; commit) lvremove -f /dev/vg_root/lv_snap ;; rollback) lvconvert --merge /dev/vg_root/lv_snap ;; esac