Default Ubuntu installation comes default volume group and logical volume and the volume group includes the logical group as it is listed below.
root@erycld:~# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 795M 1.3M 794M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 196G 179G 7.8G 96% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 974M 253M 654M 28% /boot
tmpfs 795M 4.0K 795M 1% /run/user/0
In our case, the root partition (/) was almost full and I started getting notifications regarding this issue. In the environment, the allocated space was increased to 1TB and ready to be viewed on the volume group. Listing volume groups can be viewed using the vgdisplay command on the terminal.
root@erycld:~# vgdisplay
VG Name ubuntu-vg
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size <999.00 GiB
PE Size 4.00 MiB
Total PE 255743
Alloc PE / Size 51200 / 200.00 GiB
Free PE / Size 204543 / <799.00 GiB
VG UUID NsEVii-XBL8-VnhO-ID4j-TvtM-29wm-JCXEnG
The previously printed pieces of information show us that the machine detected the new allocated size from the hypervisor and the currently allocated space and free space are listed above. Let’s see the logical volume using lvdisplay
root@erycld:~# lvdisplay
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID qKlB7B-qe8t-53in-1c4f-3SXU-VsMU-GTPf6V
LV Write Access read/write
LV Creation host, time ubuntu-server, 2022-08-15 18:12:43 +0000
LV Status available
# open 1
LV Size 200.00 GiB
Current LE 51200
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
As you see there are many of information about the logical group. It shows us where it is located and the path, status, size, and more. In the second printed-out information the allocated size from the server was 999GB and 799GB of free space was left on the volume group. We would like to use all allocated space from the hypervisor that is already detected by the volume group for the VM. Let’s use the following command and extend the logical group. We need to use LV Path which is shown on the last printed-out information.
root@erycld:~# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 200.00 GiB (51200 extents) to <999.00 GiB (255743 extents).
Logical volume ubuntu-vg/ubuntu-lv successfully resized.
Yes, we successfully resized the volume. Let’s see using the lvdisplay command.
root@erycld:~# lvdisplay
LV Path /dev/ubuntu-vg/ubuntu-lv
LV Name ubuntu-lv
VG Name ubuntu-vg
LV UUID qKlB7B-qe8t-53in-1c4f-3SXU-VsMU-GTPf6V
LV Write Access read/write
LV Creation host, time ubuntu-server, 2022-08-15 18:12:43 +0000
LV Status available
# open 1
LV Size <999.00 GiB
Current LE 255743
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
LV Size increased to 999GB from 200GB, but it is not done yet. If you check df -h you will see that your partitioning is still the same and nothing changed. At this point, we also need to resize the file system containing the logical volume.
root@erycld:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing required
old_desc_blocks = 25, new_desc_blocks = 125
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 261880832 (4k) blocks long.
Okay, block size has been changed and we can see the result using the df -h command.
root@erycld:~# df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 795M 1.3M 794M 1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv 983G 179G 763G 19% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/sda2 974M 253M 654M 28% /boot
tmpfs 795M 4.0K 795M 1% /run/user/0
If you have more volume and logical groups these simple commands will help you to solve your problem. Thanks for your time and for reading my article. I wish you a good and successful day.
Hasan