Ubuntu - Extend Your Default LVM Space

So, like me, you installed Ubuntu and accepted the installers default selections for 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 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 for the concepts and sequences of commands goes to the publishers of the article that you can find by clicking the following link:

https://packetpushers.net/ubuntu-extend-your-default-lvm-space/

This first example below involves a 1TB physical drive of which Ubuntu's default partitioning only allotted 98GB to the operating volume shown as 'ubuntu–vg-ubuntu–lv' below.

First run df -h

$ 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

Next run vgdisplay

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

Next run lvdisplay

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

Switching to root user

user@svr1:~$ sudo su
root@svr1:/home/user# cd
root@svr1:~#

Run the following to extend the LV to the maximum size usable.

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.

This is a continuation of the above: now extending the file system to utilize the entire resized volume on a 1TB physical drive.

Re-established remote ssh connection and want to again switch to root user.

~$ sudo su
[sudo] password for user:
root@svr1:/home/user# cd

Run df -h to see where we are. Notice that ubuntu–vg-ubuntu–lv is still only 98G. We still need to extend the filesystem to match the resized LV.

root@svr11:~# 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

Let's check vgdisplay

root@svr1:~# 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               <929.00 GiB
  PE Size               4.00 MiB
  Total PE              237823
  Alloc PE / Size       237823 / <929.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               rF3fw2-13h2-kAiL-aeWA-KyDZ-5HQU-GwvKDe

Let's check lvdisplay

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

Now, run the following command to resize the file system to the full size of the resized volume.

root@svr1:~# 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 = 13, new_desc_blocks = 117
The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 243530752 (4k) blocks long.

root@svr1:~#

Run df -h

And notice that 'ubuntu–vg-ubuntu–lv' is now 914G

root@svr1:~# df -h
Filesystem                         Size  Used Avail Use% Mounted on
tmpfs                              791M  1.2M  790M   1% /run
/dev/mapper/ubuntu--vg-ubuntu--lv  914G  7.0G  869G   1% /
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
root@svr1:~#

End of resizing on the 1TB physical drive. IF EVERYTHING WENT WELL, THEN STOP HERE.

FOLLOWING IS ANOTHER UNRELATED EXAMPLE OF THE SECOND PART OF THE PROCESS:

Example 2:

Note: The following operations and output involves a 2TB physical drive instead of 1TB (like above). This is a different server where only the second part of this resizing job is depicted below, likewise properly finished by extending the file system on top of the block volume that you just extended.

Again, at this point we 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.

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@svr3:~# 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@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  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@svr3:~# 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.