LVM Resize
Resizing a partition is extremely easy to do with LVM as it can be done on the fly with no downtime needed. You can perform it on a mounted volume without interruption. In order to increase the size of a logical volume, the volume group that it is in must have free space available.
To view the free space of your volume group, run vgdisplay
command as shown below and look at the “Free PE / Size” field.
┌(foo@bar)─(07:44 PM Sun Nov 25)─(~) └> sudo vgdisplay --- Volume group --- VG Name vg_sys System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 6 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 20.74 GiB PE Size 4.00 MiB Total PE 5309 Alloc PE / Size 4030 / 15.74 GiB Free PE / Size 1280 / 5.00 GiB VG UUID VvG6Sp-wIgb-LTh0-szdU-s9R1-a6K9-qHassI
In this example we have 5GB of free space in the volume group, as shown by “Free PE / Size 1280 / 5.00 GiB”.
Note: If you do not have any or enough free space in the volume group, you will first need to expand the volume group to complete the resize. Alternatively if you have multiple LVM partitions, you could shrink a different logical volume first to create space within the volume group.
Now that we have confirmed there is space free within the volume group, confirm the name of the logical volume you want to increase as well as how much space you plan on adding. The below lvdisplay command will show all logical volumes and their current size. It will also show the volume group that the logical volume is a member of, so ensure that the correct volume group has been checked for enough space with vgdisplay as previously mentioned to prevent trying to increase a logical volume that is inside some other volume group.
As shown in the example below, we are going to be working with the logical volume “lv_var” which is in volume group “vg_sys”, the volume group we saw in vgdisplay. In this example we only have just the one volume group, but you may have more so you need to check.
┌(foo@bar)─(07:46 PM Sun Nov 25)─(~) └> sudo lvdisplay --- Logical volume --- LV Path /dev/vg_sys/lv_var LV Name lv_var VG Name vg_sys LV UUID 7PNgg2-ZmnG-a26g-zRoT-PRVM-RDc1-oq6J4M LV Write Access read/write LV Creation host, time bar, 2018-11-25 07:50:25 +1000 LV Status available # open 0 LV Size 5.00 GiB Current LE 1280 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
Now it’s time to expand the logical volume. In the below example we are using the -L flag to increase by a size specified (M for Megabytes, G for Gigabytes, T for Terabytes). You can alternatively remove the + to increase to the amount specified rather than by the amount specified.
┌(foo@bar)─(07:48 PM Sun Nov 25)─(~) └> sudo lvextend -L+5G /dev/vg_sys/lv_var Rounding size to boundary between physical extents: 4.90 GiB Size of logical volume vg_sys/lv_var changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents). Logical volume lv_var successfully resized
The above command will increase the logical volume /dev/vg_sys/lv_var by 5GB. Currently it is already 5GB so this will increase it to a total of 10GB. You could achieve the same with lvextend -L 10G /dev/vg_sys/lv_var
which will increase the logical volume to 10GB as well, as this is what was specified with no +. Alternatively if you instead want to just use all free space in the volume group rather than specifying a size to increase to, run lvextend -l +100%FREE /dev/vg_sys/lv_var
.
We can run the below lvdisplay
command shown below to check that the extend completed as expected.
┌(foo@bar)─(07:50 PM Sun Nov 25)─(~) └> sudo vgdisplay --- Logical volume --- LV Path /dev/vg_sys/lv_var LV Name lv_var VG Name vg_sys LV UUID 7PNgg2-ZmnG-a26g-zRoT-PRVM-RDc1-oq6J4M LV Write Access read/write LV Creation host, time bar, 2018-11-25 07:50:25 +1000 LV Status available # open 0 LV Size 10.00 GiB Current LE 2560 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2
Now that the logical volume has been extended, we can resize the file system. This will extend the file system so that it takes up the newly created space inside the logical volume. The command may differ depending on the type of file system you are using.
- Ext3/4
resize2fs /dev/vg_sys/lv_var
- XFS
xfs_growfs /dev/vg_sys/lv_var
Double check that everything is sized as you expected by running df -h
.
┌(foo@bar)─(07:51 PM Sun Nov 25)─(~) └> df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_sys-lv_root 9.8G 1.4G 8.5G 14% / devtmpfs 908M 0 908M 0% /dev tmpfs 914M 0 914M 0% /dev/shm tmpfs 914M 8.6M 905M 1% /run tmpfs 914M 0 914M 0% /sys/fs/cgroup /dev/sda1 511M 156K 402M 20% /boot/efi /dev/mapper/vg_sys-lv_var 10G 33M 10G 1% /var
See more tips and how-to's in our Linux , Networking , and ZFS sections.