Temporary restore LVM snapshot of root

backuplvmrhelsnapshot

I have a snapshot of the root filesystem that I want to boot with – bring the machine into a state it was a few days ago, run some tests and then go back to where I am right now.

I tried editing fstab and just setting the snapshot to boot as root, but it seems that nothing happened – the snapshot was mounted, but the state of the filesystem didn't change, I'm still at the current state.

Edit:
There are no other partitions except root. The snapshot is RHEL 6.2, the current state is RHEL 6.3 (so there is a new kernel). I edited intrd by following this blog article and it seems now that the lvms don't get activated at boot. Dracut writes that all of them are inactive by inherit and freezes.

Best Answer

I found a nice and easy solution (uthers solution somehow didn't work for me, I'm not sure why). Rename the lv_root to something like lv_root_old and then rename the snapshot to lv_root.

 $ lvrename /dev/VolGroup/lv_root /dev/VolGroup/lv_root_old
 $ lvrename /dev/VolGroup/snapshot /dev/VolGroup/lv_root

Then add rd_LVM_LV=VolGroup/lv_root_old into the kernel line in grub.conf, so it gets activated (apparently, the snapshot doesn't work if the origin is inactive at boot, since it only contains changes relative to the origin). This is how my grub entry looks like now:

root (hd0,0)
kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto quiet rd_LVM_LV=VolGroup/lv_root rd_LVM_LV=VolGroup/lv_root_old KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM elevator=deadline processor.max_cstate=1
initrd /initramfs-2.6.32-220.el6.x86_64.img

Warning - if you upgraded your kernel between taking the snapshot and now, don't forget to boot the kernel that was used when the snapshot was taken.

Related Question