Professional Documents
Culture Documents
How To Extend and Reduce LVM Logical Volume in Linux
How To Extend and Reduce LVM Logical Volume in Linux
Table of Contents
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 1/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
In case if you are using SAN storage follow Scanning for attached SAN LUN’s to scan SAN disks.
Prepare/Partition the New Disk for LVM
This article only focusing on Extend and Reduce LVM. However, to prepare the disks refer our existing article FDISK to partition
the disks in Linux
Make sure to use the type of disk as (LVM) by choosing (8e) while creating the partition.
[root@client1 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
|-sda1 8:1 0 1G 0 part /boot
-sda2 8:2 0 19G 0 part
|-centos-root 253:0 0 17G 0 lvm /
-centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 100G 0 disk
-sdb1 8:17 0 100G 0 part
-vg01_data-lv_data 253:2 0 100G 0 lvm /data
sdc 8:32 0 100G 0 disk
sr0 11:0 1 906M 0 rom
[root@client1 ~]#
[root@client1 ~]# df -hP /data/
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg01_data-lv_data 99G 81G 19G 82% /data
[root@client1 ~]#
We are done with creating a physical volume to extend the volume group.
Extend the Volume Group
Now it’s time to extend the existing Volume Group by adding the physical volume created from /dev/sdc1. Let’s list the PV, VG and
get to know the size and more information before starting with extending the VG.
To print the current size of a Physical Volume, Volume Group or to know more information use
# pvs
# vgs
# vgdisplay vg01_data
Extend the size of Volume Group vg01_data by adding a new disk to it.
# vgextend vg01_data /dev/sdc1
After adding the /dev/sdc1 disk to the volume group (vg01_data) verify by running “pvs” command and we are able to see
/dev/sdc1 used under vg01_data.
[root@client1 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- <19.00g 0
/dev/sdb1 vg01_data lvm2 a-- 99.99g 0
/dev/sdc1 vg01_data lvm2 a-- 99.99g 99.99g
[root@client1 ~]#
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 3/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
Once extended the size of Logical Volume (LV) we can use any one of below command to print the information of logical volume.
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 4/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
# lvs /dev/mapper/vg01_data-lv_data
# lvs
The Units can be mentioned with MegaByte (MB), GigaByte (GB) and TeraByte (TB).
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 5/15
Resize or Grow the file-system
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
After completed with extending the logical volume next step is extent the file-system. To extend/grow the FS we required to run
anyone of command and it depends on the filesystem type we are creating.
We have created with an EXT4 filesystem so we need to use the resize2fs command by pointing to the logical volume.
# resize2fs /dev/mapper/vg01_data-lv_data
If you are using XFS as your filesystem just try to extend the FS by running xfs_growfs by pointing the mount point.
# xfs_growfs /data/
# xfs_growfs /dev/mapper/vg01_data-lv_data
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 6/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
We have done with extending the filesystem. As we mentioned before extending filesystem is super easy and done on the fly
without unmounting the filesystem.
Click NEXT to continue reading for How to Reduce/Shrink Logical Volume Management.
Un-mount the file-system.
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 7/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
# umount -v /data/
-ff option to force the file system check even though it’s clean.
While running the check it should pass all the 5 checks. In case any check failed it’s strongly advised to fix it before performing
with LV Shrink.
Output from Shell
[root@client1 ~]# e2fsck -ff /dev/mapper/vg01_data-lv_data
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/mapper/vg01_data-lv_data: 13/13107200 files (0.0% non-contiguous), 24463708/52424704 blocks
[root@client1 ~]#
Verify the logical volume and underlying volume group to make sure you are reducing the right LVM.
# pvs
# vgs
# lvs
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 8/15
Resize the fileSystem
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
Now it’s time to reduce the file system by running “resize2fs” to our desired size. Currently consumed size under /data is 91 GB
but the logical volume size is 200 GB for some other requirement we need to reduce 50 GB from the total volume size. So,
after reducing it should be 150 GB.
# resize2fs /dev/mapper/vg01_data-lv_data 150G
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 9/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 10/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
Now we got the total size in MB, divide it using our PE size 8MB so we will get the physical extend of 50 GB.
51,200 MB / 8 PE = 6,400 PE = 50 GB
So, the total physical extend we are going to reduce is 6,400 PE which is equal to 50 GB. Follow all the steps but resizing FS
required only after shrinking the LV.
Unmount the filesystem and force check for file system error
# umount -v /data/
# e2fsck -ff /dev/mapper/vg01_data-lv_data
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 11/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
That’s it we have completed with reducing a file system using physical Extends (PE). By completing this guide we are good with
how to perform an Extend and Reduce of LVM.
Continue reading LVM Series: Shrink a Volume Group in Logical Volume Management (LVM)
Conclusion:
Managing logical volume is a very important topic and required in our day to day sysadmin tasks. Understanding LVM is much
required for a good sysadmin. Hope this guide provides you with a brief understanding of Extend and Reduce Logical volume
management. Subscribe to our newsletter for more interesting upcoming topics about LVM. Your feedback and questions are
most welcome and we are happy to assist you.
Previous: Ansible tasks for Sysadmins with 25 examples Next: Shrink a Volume Group in Logical Volume Management
(LVM2)
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 12/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
ka10k says:
July 24, 2019 at 3:43 pm
lvextend -r . Resizefs is not necessary.
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 13/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
YEMANAUNG says:
July 23, 2019 at 12:27 pm
support and protect secure system issues for my account.
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 14/15
24/12/2022, 23:48 How to Extend and Reduce LVM Logical Volume in Linux
https://www.linuxsysadmins.com/extend-and-reduce-lvm-in-linux/ 15/15