Resize an existing logical volume
Example: When installing Ubuntu v20 and v22 with a 32 GB drive using LVM (the default), it will create a 32 GB drive with LVM, but will only allocate 16 GB (half) of the drive. Now you need to allocate the entire space.
- Get the LV path of the drive:
1 2
$ sudo lvdisplay | grep "LV Path" LV Path /dev/ubuntu-vg/ubuntu-lv
- Extend the logical volume:
1 2 3
$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv Size of logical volume ubuntu-vg/ubuntu-lv changed from <15.00 GiB (3839 extents) to 61.99 GiB (15870 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.
- Resize the filesystem:
1 2 3 4 5
$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 8 The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 16250880 (4k) blocks long.
Add a disk to an existing volume group
- Find the device name of the new disk (“sdb”)
1 2 3 4 5 6 7 8 9 10 11
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 62M 1 loop /snap/core20/1587 loop1 7:1 0 79.9M 1 loop /snap/lxd/22923 loop2 7:2 0 47M 1 loop /snap/snapd/16292 sda 8:0 0 32G 0 disk ├─sda1 8:1 0 1M 0 part ├─sda2 8:2 0 2G 0 part /boot └─sda3 8:3 0 30G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 30G 0 lvm / sdb 8:16 0 32G 0 disk
- Find the name of the volume group (“ubuntu-vg”)
1 2
$ sudo pvscan | grep "PV" PV /dev/sda3 VG ubuntu-vg lvm2 [<30.00 GiB / 15.00 GiB free]
- Add the drive to the volume group
1 2 3
$ sudo vgextend ubuntu-vg /dev/sdb Physical volume "/dev/sdb" successfully created. Volume group "ubuntu-vg" successfully extended
- Extend the logical volume:
1 2 3
$ sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv Size of logical volume ubuntu-vg/ubuntu-lv changed from <15.00 GiB (3839 extents) to 61.99 GiB (15870 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized.
- Resize the filesystem:
1 2 3 4 5
$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv resize2fs 1.46.5 (30-Dec-2021) Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 8 The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 16250880 (4k) blocks long.