January 31, 2013

Redhat 6: how to make a snapshot of root logical volume and rollback it

Posted in Linux at 2:20 pm by alessiodini

RHEL6 introduces new features about LVM. One of these is the snapshots.

I wanted to test it for rollback purpose. I will think about it for a patching task ūüėČ

For this test I maked a screenshot of root logical volume , I deleted /etc directory and restored it from the sreenshot. All worked !

[root@localhost ~]# df -h
 Filesystem Size Used Avail Use% Mounted on
 23G 3.1G 18G 15% /
 tmpfs 498M 0 498M 0% /dev/shm
 /dev/sda1 485M 33M 427M 8% /boot

[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rootvg 1 2 0 wz–n- 24.51g 0

I saw no free space on rootvg so i added a new disk

[root@localhost ~]# sfdisk -l /dev/sdb

Disk /dev/sdb: 652 cylinders, 255 heads, 63 sectors/track
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start     End   #cyls    #blocks   Id  System
/dev/sdb1          0+    651     652-   5237158+  8e  Linux LVM
/dev/sdb2¬†¬†¬†¬†¬†¬†¬†¬†¬† 0¬†¬†¬†¬†¬†¬† –¬†¬†¬†¬†¬†¬† 0¬†¬†¬†¬†¬†¬†¬†¬†¬† 0¬†¬†¬† 0¬† Empty
/dev/sdb3¬†¬†¬†¬†¬†¬†¬†¬†¬† 0¬†¬†¬†¬†¬†¬† –¬†¬†¬†¬†¬†¬† 0¬†¬†¬†¬†¬†¬†¬†¬†¬† 0¬†¬†¬† 0¬† Empty
/dev/sdb4¬†¬†¬†¬†¬†¬†¬†¬†¬† 0¬†¬†¬†¬†¬†¬† –¬†¬†¬†¬†¬†¬† 0¬†¬†¬†¬†¬†¬†¬†¬†¬† 0¬†¬†¬† 0¬† Empty

[root@localhost ~]# pvcreate /dev/sdb1
Writing physical volume data to disk “/dev/sdb1”
Physical volume “/dev/sdb1” successfully created

[root@localhost ~]# vgextend rootvg /dev/sdb1
Volume group “rootvg” successfully extended

[root@localhost ~]# vgs
VG     #PV #LV #SN Attr   VSize  VFree
rootvg¬†¬† 2¬†¬† 2¬†¬† 0 wz–n- 29.50g 4.99g

Nice. After i maked a screenshot with all free space on the vg.

[root@localhost ~]# lvcreate -l 100%FREE –snapshot –name rootsnap /dev/rootvg/rootvol
Logical volume “rootsnap” created
[root@localhost ~]# lvs
LV       VG     Attr     LSize  Pool Origin  Data%  Move Log Copy%  Convert
rootsnap rootvg swi-a-s-  4.99g      rootvol   0.00
rootvol  rootvg owi-aos- 22.46g
swapvol¬† rootvg -wi-ao–¬† 2.05g

s attribute said to me that rootsnap is a snapshot !

[root@localhost ~]# lvdisplay /dev/rootvg/rootvol
— Logical volume —
LV Path                /dev/rootvg/rootvol
LV Name                rootvol
VG Name                rootvg
LV UUID                MgWa8V-yUnK-hqC0-Kv6X-strT-eccc-Kiwt8S
LV Write Access        read/write
LV Creation host, time localhost.localdomain, 2013-01-29 19:04:19 +0100
LV snapshot status     source of
rootsnap [active]

LV Status              available
# open                 1
LV Size                22.46 GiB
Current LE             5750
Segments               1
Allocation             inherit
Read ahead sectors     auto
Рcurrently set to     256
Block device           253:1

First test I did:

[root@localhost ~]# dd if=/dev/zero of=test.img bs=1024k count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 80.6583 s, 13.0 MB/s


[root@localhost ~]# lvs
LV       VG     Attr     LSize  Pool Origin  Data%  Move Log Copy%  Convert
rootsnap rootvg swi-a-s-  4.99g      rootvol  18.21
rootvol  rootvg owi-aos- 22.46g
swapvol¬† rootvg -wi-ao–¬† 2.05g

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
23G  4.2G   17G  20% /
tmpfs                 498M     0  498M   0% /dev/shm
/dev/sda1             485M   33M  427M   8% /boot

After i erased /etc directory!

[root@localhost ~]# rm -rf /etc
[root@localhost ~]# cd /etc
-bash: cd: /etc: No such file or directory
[root@localhost ~]# df -h
df: cannot read table of mounted file systems: No such file or directory

I did a reboot and as expected the system was not able to boot up.
So , I used rescue mode from CD and I ran on the shell:

lvconvert –merge rootvg/rootsnap

At next boot the system came up without any problem/warning!

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
23G  3.1G   18G  15% /
tmpfs                 498M     0  498M   0% /dev/shm
/dev/sda1             485M   33M  427M   8% /boot

[root@localhost ~]# cd /root
[root@localhost ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog

( The 1 gb file does not exist anymore )

[root@localhost ~]# lvs
LV      VG     Attr     LSize  Pool Origin Data%  Move Log Copy%  Convert
rootvol rootvg -wi-ao– 22.46g
swapvol rootvg -wi-ao–¬† 2.05g

( the snapshot is not present )
With this i saw that the system was rollbacked with success.
So i will use this method on RHEL6 for rollingback after a patching!


  1. Kiran M.S said,

    Good one

  2. Kiran M.S said,

    Would like to know more in 6 ūüôā

    • alessiodini said,

      Thank you !
      I want too to know more about RHEL 6 ūüėÄ

  3. Venkat said,

    Hello Allessio,

    If we do patching on current “rootvol” & if got issue after patching…. Also, assume we took snam of rootvol before patching.. If we merge with the “snapvol”, does it overwrite the data on “rootvol” or how the merge mechanism will work ??

    Many thanks for your assistance.


    • alessiodini said,

      Hi Venkat and thanks for your question ūüôā
      Well if u read the documentation they mean about “merging”. Due to this task u will have your rootvol in pre-patching state.
      You can be sure at 100% merge will work , i tested and tested it many times. By the way be careful with Redhat release , merge works only for RHEL 6!
      For merging in RHEL 5 read this from Redhat https://access.redhat.com/site/solutions/58510
      For any other question just ask! I’m facing patching and rollback issues from 2 months so i’m fresh of procedures ūüôā

      • Venkat said,

        Thanks for your quick options. I’ve project to upgrade the “SLES10 SP2” & SLES 11 SP1 ==> to “SLES11SP2” . Our all servers run root VG under hardware raid. I would like to know what is best way to do this upgrade & Specificaly roll back procedure if any issue with the new version.

        Thank you so much for your assistance.



      • alessiodini said,

        In your scenario i suggest you:

        1) Use your RAID HW ( best case is to have RAID-1 ). Before the upgrade u can extract one disk and test the boot of the disk inside.
        After run init 0 , extract the current internal disk and replace it with the first you left. Test the boot again with this second disk.
        If all goes fine u have a solid backup! In the worst case after the upgrade just replace the internal disk and u will have a original system

        2) Use dd ( in my case I use it everytime i can because it’s one of the first quicks methods for rollbacking the system )

        3) Any other backup software ( example: Legato Networker )

        For point 1 be sure to have raid utilities installed so you can gather data about raid hardware without entering the bios ūüôā
        For more details you can read my last post on this blog

      • Venkat said,

        Hello Allesio,

        Thank u for your suggestion.

        All servers we do (globally) remote support for our customer. Do you have any idea(like RHEL 6+ snapshot method) roll-back method can able to perform remotely instead of dependent on onsite ppl.
        Looking forward for your best option here.




      • alessiodini said,

        Hi Venkat,
        for global remote support , if you have a physical server to work with, you could think about backup and restore via device/filesystem ( dd for example ). Virtual systems are more easy to deal with ( virtual snapshosts ).
        For physical systems using dd or snapshot method , in worst case u should need a cd/dvd for boot in rescue mode. ( This is reasonable )
        Let me know if u have more questions,i hope to help u a bit ūüėČ

  4. Gaye said,

    I drop a leave a response each time I especially enjoy a post on a website or I have
    something to contribute to the conversation. It’s a result of the sincerness displayed in the article I
    looked at. And on this post Redhat 6: how to make a snapshot of root logical volume and
    rollback it | Alessio dini’s Blog. I was moved enough to post a thought ūüėČ I do have a few questions for you if you tend not to mind.
    Could it be just me or does it give the impression like a few of the comments look as if they are written by brain dead people?
    ūüėõ And, if you are posting at other social sites, I’d like to keep up with everything
    fresh you have to post. Would you list every one of your public pages like your linkedin profile, Facebook page or twitter feed?|

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: