How to Create LVM in Linux CentOS 7 / RHEL 7

How to Create LVM in Linux CentOS 7 / RHEL 7

In this tutorial I will show you, how to Create LVM in Linux CentOS 7 / RHEL 7 servers.


In LVM we can merge many hard drives & make it as a single hard drive. In previous we cannot resize the file system. Also we have some partition limit in rhel 5 and 6.

If you make a hard drive of 10G using simple partition technique and somehow your drive get full so here we cannot expand it or reduce it. So we use LVM to get those advantages of reducing and expanding drives.

Here we create 8 physical volume and using it we generate 1 Volume Group 1 TB. And we use 700G to create three logical volume and there is 300G remains in VG. The first LV get full so we use remaining 300G to extend that LV so such a way we can create LV and use it.


PV-> Physical volume
VG-> Volume Group
LV -> Logical Volume

Configure LVM (Logical Volume Management) Disc Management on CentOS/RHEL/Scentific Linux/Oracle Linux 7/6/5

Step-I (Make new partition)

[root@linuxmasters]# fdisk /dev/sda

e extended
p primary partition (1-4)

Make extended partition and then create partition using it.
First cylinder:
second cylinder :+5G
Create 3 more partition like this.

Then toggle it. To toggle type t

t: (x) (y) (z) (8e)
[root@linuxmasters]# partx -a /dev/sda
[root@linuxmasters]# pvcreate /dev/sdax


[root@linuxmasters]# pvcreate /dev/sdax /dev/sday /dev/sdaz

Now create physical volume to create it

[root@linuxmasters]# pvdisplay


[root@linuxmasters]# pvs /dev/sdax

Now create VG.

Step-II (Vgcreate vgname pvname(list))

[root@linuxmasters]# vgcreate myvol /dev/sdax /dev/sday /dev/sdaz
[root@linuxmasters]# vgdisplay


[root@linuxmasters]# vgs myvol

Step-III (Now create Logical Volume)

lvcreate -L lvsize -n Lvname vgname

[root@linuxmasters]# lvcreate -L 2G -n lv1 myvol
[root@linuxmasters]# lvdisplay

Now Assign file system.

[root@linuxmasters]# mkfs.ext4 /dev/myvol/lv1
[root@linuxmasters]# mkdir /data

[root@linuxmasters]# vim /etc/fstab
/dev/myvol/lv1 /data ext4 defaults 0 0
[root@linuxmasters]# mount –a
[root@linuxmasters]# df -hT

Step-IV (Remove LVM partition)

[root@linuxmasters]# umount /data
[root@linuxmasters]# vim /etc/fstab

Remove entry

[root@linuxmasters]# lvremove /dev/myvol/lv1

Step-V (For to remove VG)

First remove all active LVM then remove VG.

[root@linuxmasters]# vgremove myvol
[root@linuxmasters]# pvremove /dev/sdax /dev/sday /dev/sdaz
[root@linuxmasters]# fdisk /dev/sda

Delete all Partition.

Step-VI (Create swap LVM)

[root@linuxmasters]# lvcreate -L +2G -n lv2 myvol
[root@linuxmasters]# mkswap /dev/myvol/lv2
[root@linuxmasters]# vim /etc/fstab
/dev/myvol/lv2 swap swap default 0 0
[root@linuxmasters]#swapon -a
[root@linuxmasters]# cat /proc/swaps

Step-VII (To remove swap)

[root@linuxmasters]# swapof -a

Step-VIII (Extend LV)

[root@linuxmasters]# vgs myvol

Spaces are remaining then extend LV.

[root@linuxmasters]# lvextend -L +5G /dev/myvol/lv1
[root@linuxmasters]#resize2fs /dev/myvol/lv1

Step-IX (Reduce LV)

-Cannot reduce LVM partition on online mode
-Only free space can reduce

[root@linuxmasters]# umount /data
[root@linuxmasters]# df -hT
[root@linuxmasters]# fsck.ext4 -f /dev/myvol/lv1

Step-X (resize2fs LVname targated size)

[root@linuxmasters]# resize2fs /dev/myvol/lv1 7G

lvreduce -L size (targeted size) LVname

[root@linuxmasters]# lvreduce -L 7G /dev/myvol/lv1
[root@linuxmasters]# mount -a
[root@linuxmasters]# df -hT

Step-XI (Using Physical extent and logical extent)

[root@linuxmasters]# vgcreate -s 8G myvol /dev/sdax

[root@linuxmasters]#  lvcreate   -l   20   -n   lv3  myvol.

Congratulations LVM is now Configured.
Enjoyed this video?
How to Create LVM in Linux CentOS 7 / RHEL 7
"No Thanks. Please Close This Box!"