Extend LVM volume in CentOS 7 and RHEL 7

  • Post author:
  • Post category:Linux
  • Post comments:1 Comment

Dear friends in this tutorial, we will see How to extend LVM volume, and how to remove LVM volume in CentOS 7 and RHEL 7.

Currently we have two physical volume one for Operating System and second for backup. Here I am going to see you step by step how to extend our LVM backup volume which is /dev/sdb1. You can see in below output we have 2 Physical Volume.

[root@urclouds ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <14.51g 40.00m
/dev/sdb1 vg_backuplvm lvm2 a-- <4.01g 0
[root@urclouds ~]#
[root@urclouds ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <14.51g 40.00m
vg_backuplvm 1 1 0 wz--n- <4.01g 0
[root@urclouds ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <12.97g
swap centos -wi-ao---- 1.50g
vm_backupvol vg_backuplvm -wi-a----- <4.01g
[root@urclouds ~]#

Add one physical volume to extend LVM volume

Now I am going to add one more physical volume to extend our existing LVM volume. You can see we have added one more physical volume /dev/sdc in below output.

[root@urclouds ~]# fdisk -l

Disk /dev/sda: 16.1 GB, 16106127360 bytes, 31457280 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: 0x00063127

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 31457279 15215616 8e Linux LVM

Disk /dev/sdb: 4307 MB, 4307599360 bytes, 8413280 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: 0xb378c328

Device Boot Start End Blocks Id System
/dev/sdb1 2048 8413279 4205616 8e Linux LVM

Disk /dev/sdc: 2144 MB, 2144324608 bytes, 4188134 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 /dev/mapper/centos-root: 13.9 GB, 13925089280 bytes, 27197440 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 /dev/mapper/centos-swap: 1610 MB, 1610612736 bytes, 3145728 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 /dev/mapper/vg_backuplvm-vm_backupvol: 4303 MB, 4303355904 bytes, 8404992 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@urclouds ~]#

Now we need to create one partition on this physical volume. We can use fdisk /dev/sdc command to create partition on this disk. Like below:-

[root@urclouds ~]# 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 0x47405b74.

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

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

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@urclouds ~]#

We have successfully created /dev/sdc1 partition on physical volume /dev/sdc. We can check our partition using fdisk -l /dev/sdc like below.

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

Disk /dev/sdc: 2144 MB, 2144324608 bytes, 4188134 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: 0x47405b74

Device Boot Start End Blocks Id System
/dev/sdc1 2048 4188133 2093043 8e Linux LVM
[root@urclouds ~]#

Now we need to create physical volume on our newly created partition /dev/sdc1 using below commands.

[root@urclouds ~]# pvcreate /dev/sdc1
  Physical volume "/dev/sdc1" successfully created.
[root@urclouds ~]#

You can see we have successfully created physical volume in our new partition. Now we can check our existing physical volume with pvs commands like below:-

[root@urclouds ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <14.51g 40.00m
/dev/sdb1 vg_backuplvm lvm2 a-- <4.01g 0
/dev/sdc1 lvm2 --- <2.00g <2.00g
[root@urclouds ~]#

You can see we have successfully created /dev/sdc1 physical volume.

For more details about LVM Extend please click here 

Extend volume Group with newly added physical volume.

Now we are going to extend our existing volume group from newly created physical volume. You can see in above output we have /dev/sdb1 vg_backuplvm volume group which is total 4.01GB size. Now we are going to extend this volume group with the help of vgextend command like below.

[root@urclouds ~]# vgextend vg_backuplvm /dev/sdc1
  Volume group "vg_backuplvm" successfully extended
[root@urclouds ~]#

We can see in above output we have successfully extend our existing volume group.

To verify volume group we can run vgs commands. You can see, now vg_backuplvm volume group have 1.9GB free space.

[root@urclouds ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <14.51g 40.00m
vg_backuplvm 2 1 0 wz--n- 6.00g 1.99g
[root@urclouds ~]#

We can use pvscan command to display which physical disk is associated with volume group.

[root@urclouds ~]# pvscan
PV /dev/sdb1 VG vg_backuplvm lvm2 [<4.01 GiB / 0 free]
PV /dev/sdc1 VG vg_backuplvm lvm2 [1.99 GiB / 1.99 GiB free]
PV /dev/sda2 VG centos lvm2 [<14.51 GiB / 40.00 MiB free]
Total: 3 [<20.51 GiB] / in use: 3 [<20.51 GiB] / in no VG: 0 [0 ]
[root@urclouds ~]#

In below we can see our logical volume details which Volume groups are under Which Physical Volumes.

[root@urclouds ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_backuplvm/vm_backupvol
LV Name vm_backupvol
VG Name vg_backuplvm
LV UUID QstkX6-SL0T-eLs1-Lkt9-WvoV-5vzb-gM4LXb
LV Write Access read/write
LV Creation host, time urclouds, 2018-08-29 18:30:21 +0200
LV Status available
# open 0
LV Size <4.01 GiB
Current LE 1026
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2

--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Zo8pWg-YlLo-cU7w-6m7F-AYWl-gOE9-s60kEj
LV Write Access read/write
LV Creation host, time localhost, 2017-09-26 12:44:34 +0200
LV Status available
# open 2
LV Size 1.50 GiB
Current LE 384
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID ae6QrZ-fPaf-LDPr-ybgr-laz0-3jRL-TjrLGE
LV Write Access read/write
LV Creation host, time localhost, 2017-09-26 12:44:34 +0200
LV Status available
# open 1
LV Size <12.97 GiB
Current LE 3320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

[root@urclouds ~]#

In above you can see we have three LVM:- vm_backupvol, swap and root.
vm_backupvol size is 4.01GB.
swap size is 1.50GB.
root size is 12.97GG.

Now we are going to expand our lvm volume vm_backupvol. We can check our physical extend available size using vgdisplay commands like below.

[root@urclouds ~]# vgdisplay
--- Volume group ---
VG Name vg_backuplvm
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 6.00 GiB
PE Size 4.00 MiB
Total PE 1536
Alloc PE / Size 1026 / <4.01 GiB
Free PE / Size 510 / 1.99 GiB
VG UUID rOgrdU-io16-yPsj-mwLE-vJOo-jbuw-nYd413

--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <14.51 GiB
PE Size 4.00 MiB
Total PE 3714
Alloc PE / Size 3704 / <14.47 GiB
Free PE / Size 10 / 40.00 MiB
VG UUID Aizuk1-j1Ec-9KHk-ENRo-9AyI-kAUw-GhdoCa

[root@urclouds ~]#

You can see we have free expanded size is (Free  PE / Size  510 / 1.99 GiB) this, in above output.

Now we can expand our logical volume approx 1.99GB with the help of lvextend command like below.

[root@urclouds ~]# lvextend -l +510 /dev/vg_backuplvm/vm_backupvol
Size of logical volume vg_backuplvm/vm_backupvol changed from <4.01 GiB (1026 extents) to 6.00 GiB (1536 extents).
Logical volume vg_backuplvm/vm_backupvol successfully resized.
[root@urclouds ~]#

You can see in above output we have successfully expended our logical volume vm_backupvol from 4GB to 6GB.

Now we need to re-size our expended LVM volume using resize2fs commands like below.

[root@urclouds ~]# resize2fs /dev/vg_backuplvm/vm_backupvol
resize2fs 1.42.9 (28-Dec-2013)
Please run 'e2fsck -f /dev/vg_backuplvm/vm_backupvol' first.

[root@urclouds ~]# e2fsck -f /dev/vg_backuplvm/vm_backupvol
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vg_backuplvm/vm_backupvol: 11/262944 files (0.0% non-contiguous), 53386/1050624 blocks
[root@urclouds ~]#
[root@urclouds ~]# resize2fs /dev/vg_backuplvm/vm_backupvol
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vg_backuplvm/vm_backupvol to 1572864 (4k) blocks.
The filesystem on /dev/vg_backuplvm/vm_backupvol is now 1572864 blocks long.

[root@urclouds ~]#

You can see in above output we have successfully resize our lvm volume.Now we can verify our extend lvm volume with the help of lvdisplay.

[root@urclouds ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_backuplvm/vm_backupvol
LV Name vm_backupvol
VG Name vg_backuplvm
LV UUID QstkX6-SL0T-eLs1-Lkt9-WvoV-5vzb-gM4LXb
LV Write Access read/write
LV Creation host, time urclouds, 2018-08-29 18:30:21 +0200
LV Status available
# open 0
LV Size 6.00 GiB
Current LE 1536
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2

--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Zo8pWg-YlLo-cU7w-6m7F-AYWl-gOE9-s60kEj
LV Write Access read/write
LV Creation host, time localhost, 2017-09-26 12:44:34 +0200
LV Status available
# open 2
LV Size 1.50 GiB
Current LE 384
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1

--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID ae6QrZ-fPaf-LDPr-ybgr-laz0-3jRL-TjrLGE
LV Write Access read/write
LV Creation host, time localhost, 2017-09-26 12:44:34 +0200
LV Status available
# open 1
LV Size <12.97 GiB
Current LE 3320
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0

[root@urclouds ~]#

You can see in above output we have successfully extended our lvm volume vm_backupvol from 4GB to 6GB.

Our current volume status should be look like below.

[root@urclouds ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <14.51g 40.00m
/dev/sdb1 vg_backuplvm lvm2 a-- <4.01g 0
/dev/sdc1 vg_backuplvm lvm2 a-- 1.99g 0
[root@urclouds ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 2 0 wz--n- <14.51g 40.00m
vg_backuplvm 2 1 0 wz--n- 6.00g 0
[root@urclouds ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- <12.97g
swap centos -wi-ao---- 1.50g
vm_backupvol vg_backuplvm -wi-a----- 6.00g
[root@urclouds ~]#

How to remove lvm volume

Now we will see how to remove LVM volume if you want to remove lvm volume in CentOS 7 and RHEL 7.

First of all we need to delete entry of our mount point from /etc/fstab if we have mounted lvm file system.

Run the below command to disable lvm volume.

[root@urclouds ~]# lvchange -an /dev/vg_backuplvm/vm_backupvol
[root@urclouds ~]#

Remove lvm volume using below commands.

[root@urclouds ~]# lvremove /dev/vg_backuplvm/vm_backupvol
Logical volume "vm_backupvol" successfully removed
[root@urclouds ~]#

Now you have to disable volume group using below commands.

[root@urclouds ~]# vgchange -an vg_backuplvm
0 logical volume(s) in volume group "vg_backuplvm" now active
[root@urclouds ~]#

After volume group disabled, we can remove our volume group using below command.

[root@urclouds ~]# vgremove vg_backuplvm
Volume group "vg_backuplvm" successfully removed
[root@urclouds ~]#

Here I am going to remove my physical volume which is used by volume group vg_backuplvm. Physical volume can be remove using below command.

[root@urclouds ~]# pvremove /dev/sdb1 /dev/sdc1
Labels on physical volume "/dev/sdb1" successfully wiped.
Labels on physical volume "/dev/sdc1" successfully wiped.
[root@urclouds ~]#

That’s all we have successfully remove our LVM volume.

Conclusion: – In this tutorial we have seen, How to extend LVM volume and How to delete LVM volume

This Post Has One Comment

  1. GeorgeMylo

    howler what an amazing internet site truly an cyberspace potency when it comes to this issue thank you for share-out this slap-up sixth sense 🤩

Leave a Reply