10

I recently installed Ubuntu 20.04 server*, and after a while got into trouble because of "no space left on device". It was only then when I realized that the Ubuntu install had not used the available disk space in full:

$ lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
[...]
nvme0n1                   259:0    0 931.5G  0 disk 
├─nvme0n1p1               259:1    0   1.1G  0 part /boot/efi
├─nvme0n1p2               259:2    0   1.5G  0 part /boot
└─nvme0n1p3               259:3    0   929G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0   100G  0 lvm  /

As I understand the output, the partition nvme0n1p3 has a size of 929 GB, but Ubuntu uses only 100 GB of that. I don't know why that happened, as I have an older Ubuntu 20.04 Server installation that looks as I would expect it:

$ lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
[...]
nvme0n1                   259:0    0 953.9G  0 disk
├─nvme0n1p1               259:1    0   512M  0 part /boot/efi
├─nvme0n1p2               259:2    0     1G  0 part /boot
└─nvme0n1p3               259:3    0 952.4G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0 952.4G  0 lvm  /

I found this answer and this answer and tried it, but the response was:

$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv 929G 
resize2fs 1.45.5 (07-Jan-2020)
The containing partition (or device) is only 26214400 (4k) blocks.
You requested a new size of 243531776 blocks.

So it tells me that the containing partition is only 100 GB in size, while lsblk obviously tells me something different.

How can I make Ubuntu use all of the available 929 GB?


*The same still happens with Ubuntu 22.04.1 LTS server, although I'm sure I told the installer to use all available disk space.

1 Answer 1

24

Because Ubuntu uses an LVM volume, the size of the volume needs to be changed first before the resize2fs can increase the size of the underlying file system.

This can be done using lvextend like so:

$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
  Size of logical volume ubuntu-vg/ubuntu-lv changed from 100.00 GiB (25600 extents) to <928.96 GiB (237813 extents).
  Logical volume ubuntu-vg/ubuntu-lv successfully resized.

The -l +100%FREE option tells lvextend to add all of the free space of the containing volume group to the logical volume.

Now we can use resize2fs to modify the filesystem so it uses all available space:

~$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv
resize2fs 1.45.5 (07-Jan-2020)
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 243520512 (4k) blocks long.

And indeed now:

$ lsblk
NAME                      MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
[...]
nvme0n1                   259:0    0 931.5G  0 disk 
├─nvme0n1p1               259:1    0   1.1G  0 part /boot/efi
├─nvme0n1p2               259:2    0   1.5G  0 part /boot
└─nvme0n1p3               259:3    0   929G  0 part 
  └─ubuntu--vg-ubuntu--lv 253:0    0   929G  0 lvm  /

I found the solution at How to resize the root LVM partition of Ubuntu. I recommend the article for more detailed background information.


You can also do the extend/resize in one step:

sudo lvextend -l +100%FREE -r /dev/mapper/ubuntu--vg-ubuntu--lv
1
  • Wow, thanks a lot. Why is this information so hard to find!? I literally searched for hours. Sep 8, 2023 at 0:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .