Saturday, February 8, 2014

Creating LVM SNAPSHOT REDHAT LINUX

 Hi Friends,

Today tried to create and learn about LVM Snap shot, yes the same process is going on, Had some questions in my mind, looking for their answers as well.

1. Decided the size of Snap shot LV comparing the size of my root file system.
2. Yes, The root Logical volume or root file system can be backed up or taken as a snap shot. below is the process.
3. The size of my root File system was 8.8 G, so decided to take some more space compared to it for root snapshot.

[root@localhost tmp]#
[root@localhost tmp]# lvcreate -L 100M -s -n tmpfilesystem /tmp
  "/tmp": Invalid path for Logical Volume
  The origin name should include the volume group.
  Run `lvcreate --help' for more information.
[root@localhost tmp]# lvcreate -L 15G -s -n rootlv /dev/mapper/VolGroup-lv_root
  Logical volume "rootlv" created
[root@localhost tmp]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  8.8G   38G  19% /
tmpfs                 935M  228K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  180M   47G   1% /home
/dev/mmcblk0p1        953M  148M  806M  16% /media/7C82-B9E9
[root@localhost tmp]# mkdir /backupofroot
[root@localhost tmp]# lvs
  LV      VG       Attr      LSize  Pool Origin  Data%  Move Log Cpy%Sync Convert
  lv_home VolGroup -wi-ao--- 50.10g                                             
  lv_root VolGroup owi-aos-- 50.00g                                             
  lv_swap VolGroup -wi-ao---  3.91g                                             
  rootlv  VolGroup swi-a-s-- 15.00g      lv_root   0.00                         
[root@localhost tmp]#
[root@localhost tmp]# mount /dev/mapper/VolGroup-rootlv /backupofroot
[root@localhost tmp]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  8.8G   38G  19% /
tmpfs                 935M  228K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  180M   47G   1% /home
/dev/mmcblk0p1        953M  148M  806M  16% /media/7C82-B9E9
/dev/mapper/VolGroup-rootlv
                       50G  8.8G   38G  19% /backupofroot
[root@localhost tmp]#


It took only one second to create the snap shot, now question arises :-

1. Can it replace the real root LV?, like if i want to boot the system with this LV then can i ?
2. How we can use this snap shot, What can or could be the scenerio?
3. Is it occupying its own space that is the space Have been allocated to it? or it is showing only a virtual space!
4. because as it is observed above the space is same as the original File System...
Ans :- It showed the same size as real root lv but at back end the 15 GB space, which was mentioned while create the snap shot lv was only used from the VG.

5. it will be better if we create a snapshot of any LV on other VG instead of using the same VG?

[root@localhost tmp]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
                       50G  8.8G   38G  19% /
tmpfs                 935M  228K  935M   1% /dev/shm
/dev/sda1             485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
                       50G  180M   47G   1% /home
/dev/mmcblk0p1        953M  148M  806M  16% /media/7C82-B9E9
/dev/mapper/VolGroup-rootlv
                       50G  8.8G   38G  19% /backupofroot
[root@localhost tmp]#
[root@localhost tmp]#
[root@localhost tmp]# umount /backupofroot/
[root@localhost tmp]# lvremove /dev/mapper/VolGroup-rootlv
Do you really want to remove active logical volume rootlv? [y/n]: y
  Logical volume "rootlv" successfully removed
[root@localhost tmp]#
[root@localhost tmp]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               297.60 GiB
  PE Size               4.00 MiB
  Total PE              76185
  Alloc PE / Size       26625 / 104.00 GiB
  Free  PE / Size       49560 / 193.59 GiB
  VG UUID               RHPHE2-Iq5r-wGPk-pUeV-oVS5-LTtW-Jbw0bQ
  
[root@localhost tmp]#
[root@localhost tmp]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  9
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               297.60 GiB
  PE Size               4.00 MiB
  Total PE              76185
  Alloc PE / Size       26625 / 104.00 GiB
  Free  PE / Size       49560 / 193.59 GiB
  VG UUID               RHPHE2-Iq5r-wGPk-pUeV-oVS5-LTtW-Jbw0bQ
  
[root@localhost tmp]# lvcreate -L 15G -s -n rootlv /dev/mapper/VolGroup-lv_root
  Logical volume "rootlv" created
[root@localhost tmp]# mount /dev/mapper/VolGroup-rootlv /backupofroot
[root@localhost tmp]# vgs
  VG       #PV #LV #SN Attr   VSize   VFree 
  VolGroup   1   4   1 wz--n- 297.60g 178.59g
[root@localhost tmp]# df -hT
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
              ext4     50G  8.8G   38G  19% /
tmpfs        tmpfs    935M  228K  935M   1% /dev/shm
/dev/sda1     ext4    485M   38M  422M   9% /boot
/dev/mapper/VolGroup-lv_home
              ext4     50G  180M   47G   1% /home
/dev/mmcblk0p1
              vfat    953M  148M  806M  16% /media/7C82-B9E9
/dev/mapper/VolGroup-rootlv
              ext4     50G  8.8G   38G  19% /backupofroot
[root@localhost tmp]#

4.

Please share your thoughts and views and help.

Love Sharing
Amit Chopra

No comments: