This is an old revision of the document!
Ubuntu - Extend Your Default LVM Space
So, like me, you installed Ubuntu and accepted the default use of lvm and now your operating volume is very small and the Ubuntu installer did not utilize the entire physical drive. There is a ton of free space that is not being utilized. And, possibly, your freshly installed cloud application (NextCloud) will soon exceed the allotted space within the first week or so as a result of data uploading or synchronization.
All credit goes to this article: https://packetpushers.net/ubuntu-extend-your-default-lvm-space/
$ df -h
Filesystem Size Used Avail Use% Mounted on tmpfs 791M 1.2M 790M 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 98G 7.0G 86G 8% / tmpfs 3.9G 0 3.9G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/sda2 2.0G 130M 1.7G 8% /boot tmpfs 791M 4.0K 791M 1% /run/user/1000
user@svr1:~$ sudo vgdisplay [sudo] password for user:
--- Volume group --- 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 <929.00 GiB PE Size 4.00 MiB Total PE 237823 Alloc PE / Size 25600 / 100.00 GiB Free PE / Size 212223 / <829.00 GiB VG UUID rF3fw2-13h2-kAiL-aeWA-KyDZ-5HQU-GwvKDe
user@svr1:~$ sudo lvdisplay
--- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID xUUIxr-wnDl-7ZNk-EQpK-gAwb-Wug0-a7JSTb LV Write Access read/write LV Creation host, time ubuntu-server, 2023-06-28 23:21:26 +0000 LV Status available # open 1 LV Size 100.00 GiB Current LE 25600 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0
user@svr1:~$ sudo su root@svr1:/home/user# cd root@svr1:~#
root@svr1:~# lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
Size of logical volume ubuntu-vg/ubuntu-lv changed from 100.00 GiB (25600 extents) to <929.00 GiB (237823 extents). Logical volume ubuntu-vg/ubuntu-lv successfully resized. root@svr11:~#
Run lvdisplay once more to verify that that the logical volume was successfully resized.
root@svr1:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID xUUIxr-wnDl-7ZNk-EQpK-gAwb-Wug0-a7JSTb LV Write Access read/write LV Creation host, time ubuntu-server, 2023-06-28 23:21:26 +0000 LV Status available # open 1 LV Size <929.00 GiB Current LE 237823 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 root@svr1:~#
At this point you have increased the size of the block volume where your root filesystem resides, but you still need to extend the filesystem on top of it.
First, run df -h to verify your (almost full) root file system, then run resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv to extend your filesystem, and run df -h one more time to make sure you’re successful.
Note: The following operations and output involves a 2TB physical drive instead of 1TB. Sorry, but this is a different server where the entire job was properly finished by extending the file system on top of the block volume that you just extended.
Here are the new readings for 'svr3' (using a pair of 2TB Drives on a hardware RAID-1 Array – which matters not.)
Logical volume ubuntu-vg/ubuntu-lv successfully resized. root@svr3:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID 0FjNEm-jrLm-tYWv-AzHT-TZmm-l9bx-aVWpyR LV Write Access read/write LV Creation host, time ubuntu-server, 2023-06-18 18:42:52 +0000 LV Status available # open 1 LV Size <1.82 TiB Current LE 476287 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 root@svr3:~# df -h Filesystem Size Used Avail Use% Mounted on tmpfs 1.6G 1.2M 1.6G 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 98G 12G 82G 13% / tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/sda2 2.0G 253M 1.6G 14% /boot tmpfs 1.6G 4.0K 1.6G 1% /run/user/1000
Now, run the following command to extend your filesystem.
root@nc3:~# resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
Results
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 = 13, new_desc_blocks = 233 The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 487717888 (4k) blocks long.
Run df -h again.
root@nc3:~# df -h Filesystem Size Used Avail Use% Mounted on tmpfs 1.6G 1.2M 1.6G 1% /run /dev/mapper/ubuntu--vg-ubuntu--lv 1.8T 12G 1.8T 1% / tmpfs 7.8G 0 7.8G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/sda2 2.0G 253M 1.6G 14% /boot tmpfs 1.6G 4.0K 1.6G 1% /run/user/1000 root@nc3:~#
Run vgdisplay again
root@nsvr3:~# vgdisplay --- Volume group --- VG Name ubuntu-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 3 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 <1.82 TiB PE Size 4.00 MiB Total PE 476287 Alloc PE / Size 476287 / <1.82 TiB Free PE / Size 0 / 0 VG UUID bK42QC-L9pu-bEiA-ndU0-j3v7-3XWU-tAO6R5
Run lvdisplay again
root@svr3:~# lvdisplay --- Logical volume --- LV Path /dev/ubuntu-vg/ubuntu-lv LV Name ubuntu-lv VG Name ubuntu-vg LV UUID 0FjNEm-jrLm-tYWv-AzHT-TZmm-l9bx-aVWpyR LV Write Access read/write LV Creation host, time ubuntu-server, 2023-06-18 18:42:52 +0000 LV Status available # open 1 LV Size <1.82 TiB Current LE 476287 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 root@svr3:~#
VG Size and LV Size are both <1.82 TiB
I believe we're done here.