How to Create LVM Partition in Linux – LVM Tutorial

How to Create LVM Partition in Linux - LVM Tutorial

This post will show you How to Create LVM Partition in Linux.

If you are interested in learning, Request you to go through the below recommended tutorial.

How to Create LVM Partition in Linux – LVM Tutorial

LVM – Logical Volume manager is a disk management solution that allow administrators to manage disk space more effectively. LVM allows us to to add, remove, resizing the size online in the existing volume without taking any downtime.

How to create a LVM in Linux, these are the below steps to be followed.
1. Select or Identify the correct disks to be used for LVM.
2. Create a Physical Volumes(PV) on the disk.
3. Create the Volume Group(VG) on the Physical Volumes
4. Create Logical Volumes(LV) on the Volume Group
5. Create a filesystem for the logical volumes

1. Select or Identify the correct disks to be used for LVM.

We need to identify the correct disk which are to be used in the LVM using the fdisk command or any other disk management command. For example, Lets say we have two 10GB disk /dev/sdb and /dev/sdc are available.

2. Create Physical Volumes (PV) on the disk.

Once identified the correct disk as /dev/sdb and /dev/sdc, We can create the physical volumes using pvcreate command as shown below which initialize a disk or partition for use by LVM. Physical volumes (PV) are the partitions on hard disk, or hard disk itself. PV are the base of LVM structure and referred as physical volumes.

[root@linux1 ~]# pvcreate /dev/sdb /dev/sdc
Physical volume “/dev/sdb” successfully created
Physical volume “/dev/sdc” successfully created

Two physical volumes are created.

To view the PV’s information more, we can use the below commands, each command has its own output format and its upto the administrator which one to be used.
pvscan is a command to know about the overview of the Physical volume.

[root@linux1 ~]# pvscan
PV /dev/sda2   VG rhel   lvm2 [9.51 GiB / 0    free]
PV /dev/sdb              lvm2 [10.00 GiB] => Physical Volume 1 newly created.
PV /dev/sdc              lvm2 [10.00 GiB] => Physical Volume 2 newly created.
Total: 3 [29.51 GiB] / in use: 1 [9.51 GiB] / in no VG: 2 [20.00 GiB]

pvdisplay is a command to display with attributes like size, physical extent size, total physical extent size, the free space, etc.

[root@linux1 ~]# pvdisplay /dev/sdb
“/dev/sdb” is a new physical volume of “10.00 GiB”
— NEW Physical volume —
PV Name               /dev/sdb
VG Name ==> If the disk is assigned to the any VG, that VG Name would be shown here.
PV Size               10.00 GiB ==> Size of the physical volume.
Allocatable           NO
PE Size               0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               MlcGDc-3umH-frYk-Tbbo-68v2-SJcK-ASWS2v
[root@linux1 ~]# pvdisplay /dev/sdc
“/dev/sdc” is a new physical volume of “10.00 GiB”
— NEW Physical volume —
PV Name               /dev/sdc
VG Name
PV Size               10.00 GiB
Allocatable           NO
PE Size               0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               ffN3i3-e5Fd-5RwX-uI7l-B8eD-xMqk-zha5UN

Note : PE – Physical Extents are nothing but equal-sized chunks. The default size of extent is 4MB.
If you want to view all physical volume information, we can use “pvdisplay” without any argument.

3. Create Volume Group (VG) on the Physical Volumes

Volume groups are nothing but a pool of storage that consists of one or more physical volumes. Once you create the physical volume, you can create the volume group (VG) from these physical volumes (PV).

Use the vgcreate command to create a Volumegroup on the physical volumes. We should specify the volumegroup along with the command as shown in below command.

[root@linux1 ~]# vgcreate datavg /dev/sdb /dev/sdc
Volume group “datavg” successfully created

Where “datavg” is the volume group and /dev/sdb, /dev/sdc are the physical volumes.

To view the all volumegroup information, use the “vgdisplay” command without any arguement. To view the specific volume group information, use the below command. This command will tell you the volumegroup information along with the phyical volume details.

[root@linux1 ~]# vgdisplay -v datavg
Using volume group(s) on command line.
— Volume group —
VG Name               datavg
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 ==> Number of current PV associated with the VG.
Act PV                2 ==> Number of active PV associated with the VG.
VG Size               19.99 GiB ==> Total size of VG combined with two PV.
PE Size               4.00 MiB
Total PE              5118
Alloc PE / Size       0 / 0 ==> No space is used from this VG.
Free  PE / Size       5118 / 19.99 GiB ==> 5118 PE or 19.99 GB is available in this VG.
VG UUID               SKJChS-xnNM-8sww-Ii5c-a0rI-TaeF-Qwooqm
— Physical volumes —
PV Name               /dev/sdb
PV UUID               MlcGDc-3umH-frYk-Tbbo-68v2-SJcK-ASWS2v
PV Status             allocatable
Total PE / Free PE    2559 / 2559
PV Name               /dev/sdc
PV UUID               ffN3i3-e5Fd-5RwX-uI7l-B8eD-xMqk-zha5UN
PV Status             allocatable
Total PE / Free PE    2559 / 2559

4. Create Logical Volumes (LV) on the Volume Group

After creating the volumegroup, use “lvcreate” command to create the logical volumes (LV) within the Volume group (VG).
As we have seen in the “vgdisplay -v datavg” output, 19.99GB free space available in the volumegroup “datavg”.
Lets create a Logical volume of 10GB “datavol1” using the command “lvcreate” as shown in the below.

[root@linux1 ~]# lvcreate -L 10G -n datavol1 datavg
Logical volume “datavol1” created.

Where “-L” is the option to specify the volume size and “-n” to specify the logical volume name. At last specify the volumegroup, so the new logical volume will be created under the volumegroup datavg.

To use the full free space available in the VG ie. 19.99GB, Execute the below command.

[root@linux1 ~]# lvcreate -L 19.99G -n datavol1 datavg

To view all available logical volume, use “lvdisplay” or “lvs” command. Use lvdisplay command with logical volume name as shown below, to view the specific logical volume with its attributes.

[root@linux1 ~]# lvdisplay -v /dev/datavg/datavol1
Using logical volume(s) on command line.
— Logical volume —
LV Path                /dev/datavg/datavol1
LV Name                datavol1
VG Name                datavg ==> This LV belongs to VG datavg.
LV UUID                pnxLzM-WQRv-vOsA-AV3m-20hN-ZPLR-lpvwwQ
LV Write Access        read/write
LV Creation host, time linux1.learnitguide.net, 2016-06-18 18:19:37 -0400
LV Status              available
# open                 0
LV Size                10.00 GiB ==> Size of the Logical Volume.
Current LE             2560
Segments               2
Allocation             inherit
Read ahead sectors     auto
– currently set to     8192
Block device           253:2

5. Create filesystem for the logical volumes.

Lets create a filesystem, so the logical volume will be ready to use.

[root@linux1 ~]# mkfs.ext4 /dev/datavg/datavol1

Once filesystem is created, mount the Logical volumes and start using the volume.

[root@linux1 ~]# mount /dev/datavg/datavol1 /mnt/
[root@linux1 ~]# df -h | grep mnt
/dev/mapper/datavg-datavol1  9.8G   37M  9.2G   1% /mnt

Hope you have got an idea How to Create LVM Partition in Linux Easily.

Related Content on Linux might be useful to you to improve your Linux Skills.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.

create lvm partition, how to create lvm partition in linux, create lvm in linux, create lvm disk, how to create lvm in linux, lvm tutorial, lvm explained