snapshot volume:create and configure snapshot volume in Red Hat Enterprse Linux

Posted: April 29, 2015 in RAID and LVM
Tags: , , , , , ,

This tutorial is all about LVM SNAPSHOT .Please Don’t think that it is a substitute of media backup,no it’s not.LVM Snapshot features provides the ability to  create virtual images of device at a particular instant without causing any service interruption. so you can also say that Snapshot copies of a file system are just a virtual copy and not a media backup for file system.snapshot features requires a minimal amount of storage.3-5% of the original capacity is enough to store and maintain snapshot data.

Now what happen when change is made to original device after a snapshot is taken?

Answer is snapshot features make a copy of the changed data area as it was prior to the changes so that it can reconstruct the state of the device.

Now i am going to show you how to create snapshot volume in Linux.I have performed this Lab in RHEL6.Here i assume that you already know how to create partition in Linux and change partition or disk id to LVM type using fdisk command.

 

Step1:Create physical Volumes using pvcreate command.

[root@localhost ~]# pvcreate /dev/sda{5,6,7,8}
 Physical volume "/dev/sda5" successfully created
 Physical volume "/dev/sda6" successfully created
 Physical volume "/dev/sda7" successfully created
 Physical volume "/dev/sda8" successfully created

 

See the attributes of Physical Volumes using pvs command line tool:

 [root@localhost ~]# pvs
 PV         VG   Fmt  Attr PSize   PFree
 /dev/sda5       lvm2 a-   196.76m 196.76m
 /dev/sda6       lvm2 a-   203.92m 203.92m
 /dev/sda7       lvm2 a-   407.87m 407.87m
 /dev/sda8       lvm2 a-   203.92m 203.92m

 

Step2: Create Volume Group using vgcreate command line tool.

 [root@localhost ~]# vgcreate vg00 /dev/sda{5,6,7,8}
 Volume group "vg00" successfully created

Check Volume Group Attributes using vgs.

 [root@localhost ~]# vgs
 VG   #PV #LV #SN Attr   VSize   VFree
 vg00   4   0   0 wz--n- 996.00m 996.00m

 

Step3:Create lvm using lvcreate command line tool.

[root@localhost ~]# lvcreate -L 200M -n lv00 vg00
 Logical volume "lv00" created

 

To see lvm attributes use lvs command.

 [root@localhost ~]# lvs
 LV         VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
 lv00       vg00 owi-a- 200.00m

Step4:Now create file system for lvm and mount it for use.

 [root@localhost ~]# mkdir /lv00
 [root@localhost ~]# mount     /dev/vg00/lv00      /lv00/
 [root@localhost ~]# df -Th
 Filesystem    Type    Size  Used Avail Use% Mounted on
 /dev/sda1     ext4    9.7G  2.8G  6.4G  31% /
 tmpfs        tmpfs    504M  524K  504M   1% /dev/shm
 /dev/mapper/vg00-lv00
 ext4    194M  5.6M  179M   4% /lv00
 [root@localhost ~]# cd /lv00/
[root@localhost lv00]# touch {a..z}
 [root@localhost lv00]# ls
 a       b  d  f  h  j  l           m  o  q  s  u  w  y
 c  e  g  i  k  lost+found  n  p  r  t  v  x  z

 

Step5:Now create snapshot of original volume and name it snap.

[root@localhost ~]# lvcreate -L 200M -s -n snap /dev/vg00/lv00
 Logical volume "snap" created

 

Above command has created a snapshot logical volume that is 200mb in size name /dev/vg00/snap .

/dev/vg00/snap is the snapshot of original logical volume /dev/vg00/lv00

Check lvm attributes again after creating snapshot of  original lvm.

 [root@localhost ~]# lvs
 LV   VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
 lv00 vg00 owi-ao 200.00m
 snap vg00 swi-a- 200.00m lv00     0.01

 

Step6:Now mount and test working of snapshot volume.

 [root@localhost ~]# mount   /dev/vg00/snap     /snap/
 [root@localhost ~]# df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/sda1             9.7G  2.8G  6.4G  31% /
 tmpfs                 504M  524K  504M   1% /dev/shm
 /dev/mapper/vg00-lv00
 194M  5.6M  179M   4% /lv00
 /dev/mapper/vg00-snap
 194M  5.6M  179M   4% /snap
 [root@localhost ~]# cd  /snap
 [root@localhost snap]# ls
 a       b  d  f  h  j  l           m  o  q  s  u  w  y
 c  e  g  i  k  lost+found  n  p  r  t  v  x  z

 

 

Now its time to check whether snapshot volume proper working or not?

TEST AND TROUBLESHOOT

 [root@localhost ~]# umount /snap/ /lv00
 [root@localhost ~]# df -h
 Filesystem            Size  Used Avail Use% Mounted on
 /dev/sda1             9.7G  2.8G  6.4G  31% /
 tmpfs                 504M  524K  504M   1% /dev/shm
 [root@localhost ~]# rm -rf /lv00/*

 

After deleting everything from original logical volume /dev/vg00/lv00 through above commands, Now we want to get it back and we can do it by using below commands.

 

[root@localhost ~]# lvconvert   --merge    /dev/vg00/snap
 Merging of volume snap started.
 lv00: Merged: 0.0%
 Merge of snapshot into logical volume lv00 has finished.
 Logical volume "snap" successfully removed

 

[root@localhost ~]# lvs
 LV   VG   Attr   LSize   Origin Snap%  Move Log Copy%  Convert
 lv00 vg00 -wi-a- 200.00m
 [root@localhost ~]# mount   /dev/vg00/lv00    /lv00/
 [root@localhost ~]# cd /lv00
 [root@localhost lv00]# ls
 a       b  d  f  h  j  l           m  o  q  s  u  w  y
 c  e  g  i  k  lost+found  n  p  r  t  v  x  z



Leave a Reply

Please log in using one of these methods to post your comment:

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