I primarily use Ubuntu distribution when I need some Linux flavor. The reason is the enterprise support if needed. I very often use virtual machines, therefore there is not a big problem to expand the disk on the hardware level. However, changing size of virtual disk in the infrastructure is not enough. Disk must be resized also within the operating system. In this blog post, I'm showing how to do it in Ubuntu world.
In my example, I have disk 30G, but the root LV is only 13.5G, so there is likely free space inside the LVM volume group.
dpasek@k0s3:/var/log$lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 2.9G 0 rom nvme0n1 259:0 0 30G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot/efi ├─nvme0n1p2 259:2 0 2G 0 part /boot └─nvme0n1p3 259:3 0 26.9G 0 part └─ubuntu--vg-ubuntu--lv 252:0 0 13.5G 0 lvm / dpasek@k0s3:/var/log$
To expand root (mount point / ) to all remaining free LVM space use command ,,,
sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
dpasek@k0s3:/var/log$sudo lvextend -r -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv[sudo: authenticate] Password: File system ext4 found on ubuntu-vg/ubuntu-lv mounted at /. Size of logical volume ubuntu-vg/ubuntu-lv changed from 13.47 GiB (3449 extents) to <26.95 GiB (6898 extents). Extending file system ext4 to <26.95 GiB (28932308992 bytes) on ubuntu-vg/ubuntu-lv... resize2fs /dev/ubuntu-vg/ubuntu-lv resize2fs 1.47.2 (1-Jan-2025) Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 4 The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 7063552 (4k) blocks long. resize2fs done Extended file system ext4 on ubuntu-vg/ubuntu-lv. Logical volume ubuntu-vg/ubuntu-lv successfully resized. dpasek@k0s3:/var/log$
And now we can double check that LVM root mount point has been resized.
dpasek@k0s3:/var/log$lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS sr0 11:0 1 2.9G 0 rom nvme0n1 259:0 0 30G 0 disk ├─nvme0n1p1 259:1 0 1G 0 part /boot/efi ├─nvme0n1p2 259:2 0 2G 0 part /boot └─nvme0n1p3 259:3 0 26.9G 0 part └─ubuntu--vg-ubuntu--lv 252:0 0 26.9G 0 lvm / dpasek@k0s3:/var/log$
Here we go. Now we can use the whole disk capacity.
No comments:
Post a Comment