What is LVM.? How to Create LVM Linux (Logical Volume Manager)

what is LVM.? How to create LVM Linux

LVM = Logical Volume Manager, Simply telling definition is not enough we should know the purpose and advantages to use further. 

If we take an example of standard Linux partitions are not flexible to increase and decrease file system when required, In this case we can’t use standard file system in production environment which is having high data growth rate. 

Standard partitions can be used where there is no high data growth, which partitions are used to store data and delete data later on. 

Advantages of LVM

  • Very easy to create partitions 
  • Increasing and decreasing file system size online is made easy
  • Adding more than one HDD will increase performance
  • LVM will support larger size of file system (100TB single partition)

What is LVM

We can create Logical Volumes using single HDD OR multiple HDD see the below example how they works

how to create LVM Logical Volume Manager

Multiple HDD LVM Logical Volumes

As per the above example we are going to combine multiple HDD as a single Volume Group then create required size of Logical Volumes. Here we can achieve more performance compare to single HDD standard partition.

Example: One member job is divided into multiple members ultimately work should complete faster. Adding multiple disks as Physical Volumes will increase reading / writing headers.

what is LVM How to create LVM Logical Volume Manager

Single HDD Logical Volumes

As per above example Single HDD is divided into multiple Physical Volumes and combined as Volume group then created Logical volumes. Here we may not see more performance compare to above multiple disks. Here we get flexibility to create and manage file system.

How to Create LVM Linux (Logical Volume Manager)

Procedure for creating LVM first Create Physical Volume –> Volume Group –> Logical Volume. Let’s see practically how it goes, for this example i have taken 20GB HDD (/dev/sdc).

 

[root@TechTutorials ~]# fdisk -l /dev/sdc

Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

[root@TechTutorials ~]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xe62ccdf8.

Command (m for help): n
Partition type:
 p primary (0 primary, 0 extended, 4 free)
 e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe62ccdf8

Device Boot Start End Blocks Id System
/dev/sdc1 2048 4196351 2097152 83 Linux

Repeat above step will create one more partition, After completion of creating required partitions we have to change its partition type to ‘Linux LVM’

Command (m for help): t
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): t
Partition number (1,2, default 2): 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xe62ccdf8

Device Boot Start End Blocks Id System
/dev/sdc1 2048 4196351 2097152 8e Linux LVM
/dev/sdc2 4196352 8390655 2097152 8e Linux LVM

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

Now required partitions are created and converted into Linux LVM type, after creating partitions update kernel

[root@TechTutorials ~]# partprobe /dev/sdc

Creating Physical Volume

Using pvcreate command we can create PV

[root@TechTutorials ~]# pvcreate /dev/sdc1
 Physical volume "/dev/sdc1" successfully created
[root@TechTutorials ~]# pvcreate /dev/sdc2
 Physical volume "/dev/sdc2" successfully created

[root@TechTutorials ~]# pvdisplay /dev/sdc*
 "/dev/sdc2" is a new physical volume of "2.00 GiB"
 --- NEW Physical volume ---
 PV Name /dev/sdc2
 VG Name
 PV Size 2.00 GiB
 Allocatable NO
 PE Size 0
 Total PE 0
 Free PE 0
 Allocated PE 0
 PV UUID ViWQYD-Qjte-fdPi-YgUd-mGBW-3ep3-R6xffx

"/dev/sdc1" is a new physical volume of "2.00 GiB"
 --- NEW Physical volume ---
 PV Name /dev/sdc1
 VG Name
 PV Size 2.00 GiB
 Allocatable NO
 PE Size 0
 Total PE 0
 Free PE 0
 Allocated PE 0
 PV UUID YtPDk4-sBDF-ryBW-cqIo-ndym-9nfR-a7f9nn

Creating Volume Group

As per below example VG0 is VG name and /dev/sdc1 and /dev/sdc2 are the Physical Volumes

[root@TechTutorials ~]# vgcreate VG0 /dev/sdc1 /dev/sdc2
 Volume group "VG0" successfully created
[root@TechTutorials ~]# vgdisplay VG0
 --- Volume group ---
 VG Name VG0
 System ID
 Format lvm2
 Metadata Areas 2
 Metadata Sequence No 1
 VG Access read/write
 VG Status resizable
 MAX LV 0
 Cur LV 0
 Open LV 0
 Max PV 0
 Cur PV 2
 Act PV 2
 VG Size 3.99 GiB
 PE Size 4.00 MiB
 Total PE 1022
 Alloc PE / Size 0 / 0
 Free PE / Size 1022 / 3.99 GiB
 VG UUID LSzoLa-C5vq-ilBm-j9hZ-b2Am-y2Ye-K6Cgsn

How to Create LVM Linux (Logical Volume Manager)

[root@TechTutorials ~]# lvcreate -n lvm1 -L 3G VG0
 Logical volume "lvm1" created.
[root@TechTutorials ~]# lvdisplay /dev/VG0/lvm1
 --- Logical volume ---
 LV Path /dev/VG0/lvm1
 LV Name lvm1
 VG Name VG0
 LV UUID 6KoIMO-SRJW-g0S0-bxrt-ABK1-pbjr-qPxRwF
 LV Write Access read/write
 LV Creation host, time TechTutorials, 2016-08-06 22:07:16 +0530
 LV Status available
 # open 0
 LV Size 3.00 GiB
 Current LE 768
 Segments 2
 Allocation inherit
 Read ahead sectors auto
 - currently set to 8192
 Block device 253:3

As per above command output lv has been created LVM name is lvm1 and its size is 3GB from Volume group VG0

LVM creation has been completed. Now let’s see how to create file system in LVM

How to Make file system in LVM

[root@TechTutorials ~]# mkfs.ext4 /dev/VG0/lvm1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
196608 inodes, 786432 blocks
39321 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=805306368
24 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
 32768, 98304, 163840, 229376, 294912

Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done

[root@TechTutorials ~]# mkdir /data1

[root@TechTutorials ~]# mount /dev/VG0/lvm1 /data1

[root@TechTutorials ~]# df -h /data1
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VG0-lvm1 2.9G 9.0M 2.8G 1% /data1

Logical Volume has been formatted with EXT4 file system. Mounted to /data1

That’s about Logical Volume Manager

Conclusion

Creating and using Logical volumes using multiple HDD’s will give more performance and flexibility.

Related Articles

Linux File System

Access Control List in Linux

Swap File System in Linux

RHCSA certification Complete Road Map

what is lvm.? what is lvm.? How to create LVM Linux How to create LVM Linux How to create LVM Linux

Thanks for your wonderful Support and Encouragement

Stay Connected with us. Learn More and Earn More

ARK

My Name is ARK. Expert in grasping any new technology, Interested in Sharing the knowledge. Learn more & Earn More

You may also like...

Leave a Reply