Cyberithub

How to Extend LVM Partition Using lvextend command in Linux (RedHat/CentOS 7/8)

In this article, I will take you through the Steps to extend LVM Partition using lvextend command in Linux. lvextend is a part of LVM utilities which is used to extend the size of LVM Partition. Many times it happened that your LVM partition gets filled up and now you need to add more space to the partition. This is more frequent on LVM based backup environment where lvextend utility becomes very handy and comes to our rescue. In this session, I will take you through the steps to extend LVM Partition using lvextend command.

How to Extend LVM Partition Using lvextend command in Linux (RedHat/CentOS 7/8) 1

Extend LVM Partition Using lvextend Command

Also Read: How to Install and Use telnet command in Linux (RedHat/CentOS 7/8) Using 5 Easy Steps

Step 1: Check Currently Allocated LVM Partition Size

First you need to check the current allocated and free space in LVM partition. In this example, we are using a logical partition /dev/mapper/vol_grp-log-grp1 which is currently mounted on /u01 mount point. As  you can see total size is currently showing 190M (actual partition size is 200MB) so we will go ahead and increase the size of this partition by 200MB more.

[root@localhost ~]# df -h
Filesystem                   Size Used  Avail Use% Mounted on
devtmpfs                     484M   0   484M   0%    /dev
tmpfs                        496M   0   496M   0%  /dev/shm
tmpfs                        496M  6.8M 489M   2%    /run
tmpfs                        496M   0   496M   0%  /sys/fs/cgroup
/dev/mapper/centos-root      37G   1.5G 36G    4%     /
/dev/sda1                    1014M 193M 822M   19%   /boot
tmpfs                        100M    0  100M    0% /run/user/0
/dev/mapper/vol_grp-log_grp1 190M  1.6M 175M    1%   /u01

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to User.

Step 2: Unmount the Volume

It is always a good idea to unmount the volume before we go ahead with extending the partition. You can unmount the partition by running umount /u01 command as shown below.

[root@localhost ~]# umount /u01/

You can quickly check if it is unmounted or not by using df -h command as shown in below output.

[root@localhost ~]# df -h
Filesystem               Size Used  Avail Use% Mounted on
devtmpfs                 484M   0   484M  0% /dev
tmpfs                    496M   0   496M  0% /dev/shm
tmpfs                    496M  6.8M 489M  2% /run
tmpfs                    496M   0   496M  0% /sys/fs/cgroup
/dev/mapper/centos-root  37G   1.5G 36G   4% /
/dev/sda1                1014M 193M 822M  19% /boot
tmpfs                    100M   0   100M  0% /run/user/0

Step 3: Check logical volume size

You can check the current size and other details about logical volume log_grp1 by running lvdisplay command as shown below. If you want to know more about below parameters you can check this on How to Configure LVM in Linux(pvcreate, vgcreate and lvcreate) using 6 Easy Steps.

[root@localhost ~]# lvdisplay /dev/vol_grp/log_grp1
--- Logical volume ---
LV Path /dev/vol_grp/log_grp1
LV Name log_grp1
VG Name vol_grp
LV UUID NNGFmr-slo3-HQtG-lxwI-TSnl-Tbia-sTVlNa
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2020-05-08 01:42:24 -0400
LV Status available
# open 0
LV Size 200.00 MiB
Current LE 50
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4

Step 4: Extend the Logical Volume Size Using lvextend Command

Now you can extend the logical volume by 200MB more using lvextend -L +200M /dev/vol_grp/log_grp1 command as shown below.

[root@localhost ~]# lvextend -L +200M /dev/vol_grp/log_grp1
Size of logical volume vol_grp/log_grp1 changed from 200.00 MiB (50 extents) to 400.00 MiB (100 extents).
Logical volume vol_grp/log_grp1 successfully resized.

-L : Additional partition size which needs to be added.

Step 5: Resize the Partition using resize2fs command

Once partition size is extended you need to resize the extended partition with ext4 filesystem to let the System know about additional partition. One of the most popular tool which can used for resizing the partition is resize2fs. You can simply use resize2fs /dev/vol_grp/log_grp1 command to resize the partition.

[root@localhost ~]# resize2fs /dev/vol_grp/log_grp1
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vol_grp/log_grp1 to 409600 (1k) blocks.
The filesystem on /dev/vol_grp/log_grp1 is now 409600 blocks long.

Sometimes you might get error Please run ‘e2fsck -f /dev/vol_grp/log_grp1’ first”. In those cases you might need to run below command first and then run above resize2fs command to resize the partition.

[root@localhost ~]# e2fsck -f /dev/vol_grp/log_grp1
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/vol_grp/log_grp1: 11/51200 files (0.0% non-contiguous), 12115/204800 blocks

Step 6: Scan and detect Logical Volume disk using lvscan command

Make sure to run lvscan command after extending the LVM partition to check the System visibility of extended partition. Here you can see we have increased the partition size by 200MB and previous size was also 200MB so that makes it a total of 400MB.

[root@localhost ~]# lvscan
ACTIVE '/dev/vol_grp/log_vol1' [12.00 MiB] inherit
ACTIVE '/dev/vol_grp/log_grp' [2.00 GiB] inherit
ACTIVE '/dev/vol_grp/log_grp1' [400.00 MiB] inherit
ACTIVE '/dev/centos/swap' [2.00 GiB] inherit
ACTIVE '/dev/centos/root' [36.99 GiB] inherit

Step 7: Check Logical Volume Size using lvdisplay command

It is also recommended to verify the Logical Volume size and other useful parameters through lvdisplay command as shown below. As you can see from below output Current LE is 100 and PE size is usually 4MB so LV Size will be 100 x 4MB = 400MB. To know more about LE and PE Size you can visit How to Configure LVM in Linux(pvcreate, vgcreate and lvcreate) using 6 Easy Steps.

[root@localhost ~]# lvdisplay /dev/vol_grp/log_grp1
--- Logical volume ---
LV Path /dev/vol_grp/log_grp1
LV Name log_grp1
VG Name vol_grp
LV UUID NNGFmr-slo3-HQtG-lxwI-TSnl-Tbia-sTVlNa-lvextend
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2020-05-08 01:42:24 -0400
LV Status available
# open 1
LV Size 400.00 MiB
Current LE 100
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:4

Step 8: Mount the Volume

Now you can mount the LVM partition again by running mount /dev/vol_grp/log_grp1 /u01 command as shown below.

[root@localhost ~]# mount /dev/vol_grp/log_grp1 /u01

Then check again if the volume is mounted or not by using df -h command as shown below. You can now see that 384MB is available in /u01 mount point for our usages. You cannot get entire 400MB due to the creation of filesystem over the partition which occupies few MBs.

[root@localhost ~]# df -h
Filesystem                   Size Used  Avail Use% Mounted on
devtmpfs                     484M   0   484M   0%   /dev
tmpfs                        496M   0   496M   0%  /dev/shm
tmpfs                        496M  6.8M 489M   2%    /run
tmpfs                        496M   0   496M   0%  /sys/fs/cgroup
/dev/mapper/centos-root      37G   1.5G 36G    4%     /
/dev/sda1                    1014M 193M 822M   19%   /boot
tmpfs                        100M   0   100M   0%  /run/user/0
/dev/mapper/vol_grp-log_grp1 384M  2.3M 358M   1%   /u01

 

 

 

Popular Recommendations:-

12 Best Examples of tail command in Linux for Beginners

How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8

10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)

9 useful w command in Linux with Examples

12 Most Popular rm command in Linux with Examples

25 Useful Linux SS Command Examples to Monitor Network Connections

Configure LVM in Linux

Configure LVM: Complete Administration

lvextend Man Page

Leave a Comment