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.

  • Do you have separate partitions for /usr, /var, /home, and the like? If you mounted a snapshot of /, but the other partitions are not snapshots created at the same time, that could be the unchanged state you are experiencing. – George M May 15 '12 at 14:08
  • And your operating sytem and distribution is? – Nils May 15 '12 at 14:13
  • I don't have separate partitions for this machine, only root. I'm using RHEL 6.2 – M.K. May 15 '12 at 14:23

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.

  • Good find. It's interesting you were having problems. I performed the same steps on my RHEL 6.2 system and was able to boot into the snapshot repeatedly without adding the "rd_LVM_LV=" line. – George M May 16 '12 at 16:41

Although you have already created the snap, I will go through the steps for clarity.

Create the snap.

# lvcreate --size 100M --snapshot --name lv_root_snap /dev/vg_linux/lv_root
# lvs
 LV           VG           Attr   LSize   Origin  Snap%  Move Log Copy%  Convert
 lv_home      vg_linux    -wi-ao  11.72g                                       
 lv_opt       vg_linux    -wi-ao   4.00g                                       
 lv_root      vg_linux     owi-ao   2.00g                                       
 lv_root_snap vg_linux     swi-a- 100.00m lv_root   2.52  

If desired, mount the snap and verify.

# mount /dev/vg_linux/lv_root_snap /mnt

Add an entry to /etc/grub.conf that tells the kernel to use the snapshot root filesystem. (/etc/grub.conf is a symlink to /boot/grub/grub.conf, so it is not affected by the snapshot of /)

title RHEL 6.2 Snap
    root (hd0,0)
    kernel /vmlinuz-2.6.32-220.13.1.el6.x86_64 ro root=/dev/mapper/vg_linux-lv_root_snap ....

Alternately, if you do not want to make a grub entry, you can specify the root fs during boot by entering the grub menu and editing the entry changing root= to point to the snap. This will be temporary and will not persist when the system is booted again.

  • It's the kernel command line you need to have grub change; /etc/fstab is not used for locating the root fs. – psusi May 16 '12 at 2:15
  • I should have mentioned that I did a upgrade to RHEL 6.3 in between taking the snapshot and the current state. It seems that lv_root is set in the initrd file, so it still uses it, somehow trying to boot from the newer kernel that isn't in the snapshot...or something. Kernel panic. I guess I'll find out how initramfs and initrd work... – M.K. May 16 '12 at 13:41
  • @psusi You are right. Thanks for pointing that out. – George M May 16 '12 at 13:50
  • @M.K.You should edit your question and add that information to it. – George M May 16 '12 at 14:04
  • So I edited intrd by following this blog.linuxbox.co.nz/2010/11/booting-lvm-snapshot-of.html 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. – M.K. May 16 '12 at 15:47

/etc/fstab isn't used to locate the root fs. At the grub menu, press e to edit the entry and change the root= kernel command line argument to point to the snapshot. This will boot from the snapshot just this one time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.