How to resize a logical volume with 5 simple LVM commands

Have you ever wondered how to extend your root or home directory file system partition using LVM? You might have low storage space and you need to increase the capacity of your partitions. This article looks at how to extend storage in Linux using Logical Volume Manager (LVM).

Process summary

The process is straightforward. Attach the new storage to the system. Next, create a new Physical Volume (PV) from that storage. Add the PV to the Volume Group (VG) and then extend the Logical Volume (LV).

Look at the picture below. The red line mark shows the original size of the root mount point. The xvdc disk is the new disk attached to it. Extend the root partition to make it 60G in size.

lsblk

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-55-37.png

Create a Physical Volume

[root@sysadmin ~]# pvcreate /dev/xvdc
  Physical volume "/dev/xvdc" successfully created.

When you attach the new storage /dev/xvdc, you need to use the pvcreate command in order for the disk to be initialized and be seen by the Logical Volume Manager (LVM).

Identify the Volume Group

Next, you need to identify the Volume Group (VG) to which you are extending the new disk with the vgs command. Mine is called centos, and that's the only VG available currently on my LVM.

vgs

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-56-33.png

Extend the Volume Group

The vgextend command allows you to add one or more initialized Physical Volumes to an existing VG to extend its size.

 

As you can see, you want to extend the centos Volume Group.

$ vgextend centos /dev/xvdc

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-56-54.png

After extending it, type the vgs or vgdisplay commands for a more detailed overview of the VG.

The vgs command shows only the VG in with a few lines.

$ vg

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-57-17.png

The vgdisplay shows all the VGs in the LVM and displays the complete information about them.

$ vgdisplay

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-57-45.png

As you can see from the image above, marked with red, you have 10GB free. You can decide to extend all or some amount of storage size to it.

Identify the Logical Volume

The lvs or lvdisplay command shows the Logical Volume associated with a Volume Group. Use the lvs command, and the Logical Volume you're trying to extend is the root, which belongs to the centos VG. As you can see above, you've already extended the VG. Next, extend the Logical Volume.

$ lvs

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-58-12.png

Extend the Logical Volume

Extend the LV with the lvextend command. The lvextend command allows you to extend the size of the Logical Volume from the Volume Group.

[root@sysadmin ~]# lvextend -l +100%FREE /dev/centos/root.

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-58-45.png

Extend the filesystem

You need to confirm the file system type you're using, Red Hat uses the XFS file system, but you can check the file system with lsblk -f or df -Th.

Resize the filesystem on the Logical Volume after it has been extended to show the changes. Resize the XFS filesystem by using the xfs_growfs command.

$ xfs_growfs /dev/centos/root

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-59-28.png

Finally, verify the size of your extended partition.

$ df -h

https://sive.host/titfombe/repository/Screenshot%20from%202022-05-30%2010-59-54.png

Wrap up

You can extend any other partition with the steps shown. You just have to ensure you're using LVM and know the partition you're extending.

 

 

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

12 Useful “df” Commands to Check Disk Space in Linux

Useful df Command Examples This article explain a way to get the full information of Linux disk...

How to Disable SELinux

How to Disable SELinux You’ve setup a new system, or installed something new on your Linux...

How to set a Static IP in Ubuntu Linux

How to set a Static IP in Ubuntu LinuxOpen the terminal command line application or ssh into the...

Linux Check Disk Space Command To View System Disk Usage

Linux Check Disk Space Command To View System Disk Usage Linux command to check disk space...