How to extend LVM partition
LVM is a Logical Volume Manager, and it does not support extending partitions using a traditional extending procedure. LVM consists of physical volume, volume group, and logical volume, and the first one needs to be created, while the last two needs to be extended. Before extending an LVM partition, you should add either another physical or virtual disk to your setup. This guide presumes that the disk is already added. In the example, the new disk is referred to as a /dev/sdb with a size of 40GB. Login into your server console and type the following commands to identify the physical volume, volume group, and logical volume that needs to be extended.
# pvdisplay --- Physical volume --- PV Name /dev/sda1 VG Name rl PV Size 38,41 GiB / not usable 2,00 MiB Allocatable yes (but full) PE Size 4,00 MiB Total PE 9833 Free PE 0 Allocated PE 9833 PV UUID WE8Xbp-Fkuh-iLqN-LpzZ-QQrG-65BL-owKia1 # vgdisplay --- Volume group --- VG Name rl 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 38,41 GiB PE Size 4,00 MiB Total PE 9833 Alloc PE / Size 9833 / 38,41 GiB Free PE / Size 0 / 0 VG UUID 6O96JD-ex54-dTH1-nFk3-gPYZ-xhWa-2OA9mo # lvdisplay --- Logical volume --- LV Path /dev/rl/swap LV Name swap VG Name rl LV UUID 2ceJdW-z2bf-jOfh-7Pre-v8HG-TOFj-q5Yogl LV Write Access read/write LV Creation host, time home.cph.sefnet.int, 2022-11-21 18:07:55 +0100 LV Status available # open 2 LV Size <3,83 GiB Current LE 980 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 --- Logical volume --- LV Path /dev/rl/root LV Name root VG Name rl LV UUID M8Yoc9-sMpR-wRbA-ZKXr-5xMt-OQJK-csme7J LV Write Access read/write LV Creation host, time home.cph.sefnet.int, 2022-11-21 18:07:55 +0100 LV Status available # open 1 LV Size 34,58 GiB Current LE 8853 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
The pvdisplay command lists the physical disk groups. Basically, you will need to create a new physical disk group consisting of the newly added disk, so do the following:
# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created
After the physical disk group is created, we proceed with the extension of the volume disk group. In this example, we will extend the “rl” volume group. After you have identified the volume group you need to extend, do the following:
# vgextend rl /dev/sdb Volume group "rl" successfully extended
Now we need to extend the logical volume. In this example, we will extend the /dev/rl/root logical volume. After you have identified the logical volume you need to extend, do the following:
# lvextend -l +100%FREE /dev/rl/root Logical volume root successfully resized
The last step is to resize the file system, and depending on the filesystem format you have used under installation, you will need to use the appropriate command. To identify the correct file system, check your /etc/fstab file. In this example, the filesystem is formatted with xfs:
# xfs_growfs /dev/rl/root
Now you can confirm that the available free space is increased using the df -h command.