Creating Logical Volume Manager (LVM) in Linux
Logical Volume Management (LVM) makes it easier to manage disk space. If a file system needs more space, it can be added to its logical volumes from the free spaces in its volume group and the file system can be re-sized as we wish. If a disk starts to fail, replacement disk can be registered as a physical volume with the volume group and the logical volumes extents can be migrated to the new disk without data loss.
Have a look at flow doagram of lvm and we can say components of lvm.
I think some of above pictures will create some understanding for lvm. As visualization makes better picture of anything.
In a modern world every Server needs more space day by day for that we need to expand depending on our needs. Logical volumes can be use in RAID, SAN. A Physical Disk will be grouped to create a volume Group. Inside volume group we need to slice the space to create Logical volumes. While using logical volumes we can extend across multiple disks, logical volumes or reduce logical volumes in size with some commands without reformatting and re-partitioning the current disk. Volumes can stripes data across multiple disks this can increase the I/O stats.
My Server Setup – Requirements
My Server Setup – Requirements
- Operating System – CentOS 6.5 with LVM Installation
- Server IP – 192.168.0.199
Creating LVM Disk Storage in Linux
Here, is the description of each parameters shown in above screenshot.
- Physical Disk Size (PV Size)
- Disk which used was Virtual Disk sdb.
- Volume Group Size (VG Size)
- Volume Group name (vg1)
- Logical Volume name (kvitlvm, lalitlvm)
Friends for any real time environment on servers , it is used in a condition when we need to make up or add more space or reduce some space, which is only effective with this method lvm.So,for practical purpose , we are creating here lvm to make you feel like a real environment.
As i have done this practical on virtula machine on Oracale Virtual Box.You can also practice on virtual machine.
Add virtual harddisk in virtual box
1. Create a Centos/Rhel based machine on virtual box.
2. Select a machine settings and go to storage section.
3. Add virtual harddisk of any size as you want, here in this practical i have added 30GB virtual harddisk.
4. Follow the options .
5. Give the name to added hardisk.
These are all the above method to add virtual hard disk on virtual machine .Now we have to move on for further practical.
2.. Convert them into physical volumes.
3 Combine physical volumes into volume group.
4. Finally create a logical volume from the volume group.
Note:Green color is color which is showing my machine, dont be confused for this.As in all my practicals, you will be shown like this.This is linux mint mahine which i used in my daily use for desktop purpose.
Step 2:Check Added hard disk
Here you can see additional harddisk has been added as /dev/sdb and of which i have created three partitions of /dev/sdb1 , /dev/sdb2, /dev/sdb3 of equal 10GB each from /dev/sdb (30GB).
Disk /dev/sdb: 32.6 GB, 32635994112 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 1306 10490413+ 83 Linux
/dev/sdb2 1307 2612 10490445 83 Linux
/dev/sdb3 2613 3918 10490445 83 Linux
Step 3: Create 3 partitions .
Step 4: Create Physical Volume
root@lvmserver ~]# yum install lvm2
Step-2. Create Physical Volumes
# pvcreate /dev/sdb1 /dev/sdb2 /dev/sdb3
Physical volume “/dev/sdb1” successfully created
Physical volume “/dev/sdb2” successfully created
Physical volume “/dev/sdb3” successfully created
You can see that Phycal volumes has been created.
pvs is a command which will display you all physical volumes.
root@lvmserver ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 lvm2 — 10.00g 10.00g
/dev/sdb2 lvm2 — 10.00g 10.00g
/dev/sdb3 lvm2 — 10.00g 10.00g
You can use these commands to check physical volumes.
Create Volume Group and Logical Volume
root@lvmserver ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 /dev/sdb3
Volume group “vg1” successfully created
[root@lvmserver ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 3 0 0 wz–n- 30.00g 30.00g
[root@lvmserver ~]# vgscan
Reading all physical volumes. This may take a while.
Found volume group “vg1” using metadata type lvm2 .
Step-6. Create Logical Volume
[root@lvmserver ~]# lvcreate -L 200M vg1 -n lv1
Logical volume “lv1” created
Gives the size to allocate for the new logical volume. A size suffix of B for bytes, S for sectors as 512 bytes, K for kilobytes, M for megabytes, G for gigabytes, T for terabytes, P for petabytes or E for exabytes is optional Default unit is megabytes.
-n, –name LogicalVolume
Sets the name for the new logical volume. Without this option a default name of “lvol#” will be generated where # is the LVM internal number of the logical volume.
[root@lvmserver ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a—– 200.00m
Step-7. Format the logical volume
Step 8: Mount the logical volume
Step 9: Check the mounted directory
Step 10: For temporary and permanent mounting
It’s now temporarily mounted, for permanent mount we need to add the entry in fstab, for that let us get the mount entry from mtab using
# cat /etc/mtab
We need to make slight changes in fstab entry while entering the mount entry contents copies from mtab, we need to change the rw to defaults
# vim /etc/fstab
Our fstab Entry want to be similar to below sample. Save and exit from fstab using wq!.
Before permanent mounting, umount /mnt.
Keep the entries and save the file.
Then you can check by:
# mount -a ( Whether mounting is correct or not )
# df -h ( will show you mount point )
In my upcoming future articles, I will see how to extend the volume group, logical volumes, reducing logical volume, taking snapshot and restore from snapshot. Till then stay updated to linuxgateway.in for more such awesome articles in linux for linux lovers.
For any queries and information , mail us at email@example.com or firstname.lastname@example.org.