Friday, April 16, 2010

How to create a snapshot of a Logical Volume in linux rhel5 / Centos


Creating SNAPSHOT (Backup):

We can take the back up of any particular Logical Volumes. Snapshot will be stored in the Same volume group. Snapshot will take only 3-5% of the original size of Logical Volume.
This is the current status of our machine:

[root@vm4 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvm1 linux -wi-a- 200.00M
lvm2 linux -wi-a- 40.00M
[root@vm4 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
linux 2 2 0 wz--n- 576.00M 336.00M
redhat 2 0 0 wz--n- 576.00M 576.00M
[root@vm4 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 lvm2 -- 290.21M 290.21M
/dev/sda6 linux lvm2 a- 288.00M 248.00M
/dev/sda7 linux lvm2 a- 288.00M 88.00M
/dev/sda8 redhat lvm2 a- 288.00M 288.00M
/dev/sda9 redhat lvm2 a- 288.00M 288.00M

We have two Logical Volumes lvm1 and lvm2 mounted on /linux1 and /linux2 respectively.
We'll take the SNAPSHOT of the LV lvm1 which is mounted on /linux1
currently there are following files in /linux1 [ie in lvm1]

[root@vm4 ~]# cd /linux1
[root@vm4 linux1]# ls

a b c lost+found

Step1:
Snapshot is actually a Logical Volume only. It will be saved in the same VG. We can create lvm snapshot using command #lvcreate with options for snapshot.

The syntax is as follows

#lvcreate --size SIZE --snapshot --name Name_Of_Snapshot Path_of_the_LV

[root@vm4 linux1]# lvcreate --size 10M --snapshot --name snap /dev/linux/lvm1
Rounding up size to full physical extent 12.00 MB
Logical volume "snap" created

[root@vm4 linux1]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
lvm1 linux owi-ao 200.00M
lvm2 linux -wi-ao 40.00M
snap linux swi-a- 12.00M lvm1 0.10

[root@vm4 linux1]# vgs
VG #PV #LV #SN Attr VSize VFree
linux 2 3 1 wz--n- 576.00M 324.00M
redhat 2 0 0 wz--n- 576.00M 576.00M




Now lets mount the Snapshpot and check whether it has everything from lvm1.
Mounting snap to /snapshot

[root@vm4 linux1]# mkdir /snapshot
[root@vm4 linux1]# mount /dev/linux/snap /snapshot
[root@vm4 linux1]# cd /snapshot
[root@vm4 snapshot]# ls
a b c lost+found
It has the same and all the contents of lvm1

How to configure LVM in linux rhel5 / Centos

Logical Volume Management[LVM]
LVM is a logical volume manager for the Linux kernel; it manages disk drives and similar mass-storage devices, in particular large ones. The term "volume" refers to a disk drive or partition.
Every system contains Physical Volums[PV]. Such as hard disks, partitions or external storages. Volume management treats PVs as sequences of chunks called Physical Extents (PEs). There is an another concept also. Logical Extents(LE). Each LE maps one-to-one PE. The system pools LEs into a Volume Group (VG). We can extend this VG by adding a group of Logical extents to it from anywhere at anytime.
Uses of LVM:
  1. Extending the partitions online
  2. Grouping of hard disks
  3. Reducing the partitions / hard dsik size (offline)
  4. Increasing the performance
  5. Taking Backup (SNAPSHOT)

How to create stripped lvm volumes in linux rhel5 / centos


How to create stripped lvm volumes:

We have seen that how to configure logical volumes(lvm) in linux systems, How to create snapshot of a logical volume and how to create mirrored logical volumes. Here we see how to create stripped logical volumes. 

We can create lvms in stripped manner so that it will increase the performance. It can be done using the command #lvcreate with -i option.

The syntax is as follows:
#lvcreate -L Size -i2 -n Name_LV Name_VG 1st _LV 2nd _LV

[root@vm4 ~]# lvcreate -L 100M -i2 -n slvm redhat /dev/sda8 /dev/sda9
Using default stripesize 64.00 KB

/dev/cdrom: open failed: Read-only file system
Rounding size (25 extents) up to stripe boundary size (26 extents)
Logical volume "slvm" created

[root@vm4 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
mlvm redhat mwi-a- 100.00M mlvm_mlog 100.00
slvm redhat -wi-a- 104.00M

For extending a stripped lvm u need to extend the VG with two different PVs . Else it wont work.

How to create mirrored lvm volumes in linux redhat / centos


How to create mirrored lvm volumes:

We can create mirrored lvm(how to configure lvm) using the command #lvcreate with -m option.
The syntax is as follows:

#lvcreate -L Size -m1 -n Name_LV Name_VG Mirror_1st_leg Mirror_2nd_leg Log_Device

-m1 means its a mirrored one type. So it will have one original[1st leg]how to configure lvm one mirror[2nd leg] and a logging device for sync.

#lvcreate -L 100M -m1 -n mlvm redhat /dev/sda5 /dev/sda6 /dev/sda7


[root@vm4 ~]# lvcreate -L 100M -m1 -n mlvm redhat /dev/sda5 /dev/sda6 /dev/sda7
/dev/cdrom: open failed: Read-only file system
Logical volume "mlvm" created

[root@vm4 ~]# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
mlvm redhat mwi-a- 100.00M mlvm_mlog 100.00

For more details check the cluster_logical_volume.pdf in redhats docs.