6

I have an Ubuntu server 20.04 with an encrypted 50GB LVM root partition and I just realized the filesystem itself only shows 25GB

The install was default (apart from the encryption bit) and I don't understand why it didn't use all the space for the root partition?

How do I expand the root filesystem?

 PV                     VG        Fmt  Attr PSize  PFree
  /dev/mapper/dm_crypt-0 ubuntu-vg lvm2 a--  48.48g <24.24g

 VG        #PV #LV #SN Attr   VSize  VFree
  ubuntu-vg   1   1   0 wz--n- 48.48g <24.24g

 LV        VG        Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  ubuntu-lv ubuntu-vg -wi-ao---- 24.24g
9
  • 2
    Update your question with the output of pvs,vgs and lvs
    – GMaster
    Aug 13, 2021 at 1:41
  • Was I right about disk repair? It looks like it, due to the naming scheme.
    – Nate T
    Aug 17, 2021 at 8:14
  • @NateT No. I installed with an encrypted LVM volume for the root partition. Aug 17, 2021 at 8:26
  • That explains the single pv. Other than that, I was right. Although your question is wrong. When I answered, the output hadn't been posted. I was going off what you said. The filesystem is in the PV(s). the LV(s) contain metadata.. like a map of the PV(s).
    – Nate T
    Aug 17, 2021 at 8:36
  • 1
    @user3866319 Canonical arbitrarily decided that this "feature" should be added to the 20.04 release without telling anyone. They believed that only allocating half the disk was a good thing, in case users wanted to add or expand partitions in the future, despite the screen saying "Use full disk" during install. It only does this if LVM is selected during the partitioning stage of installation, but it doesn't tell you it's doing it unless you look closely at the final partition configuration before committing it. Personally, I think it was a terrible decision.
    – BobbyMick
    Jun 29, 2022 at 7:06

2 Answers 2

8

why it didn't use all the space for the root partition?

When the logical volume was created, only 24.24 GB was allocated for it. That can actually be a good thing: the remainder can be used to create another logical volume if you find you need one for some reason, or you can use the free space to extend an existing logical volume, even while its filesystem is mounted and in use.

Having some unallocated space held in reserve can be a good thing, as it allows you to react to unexpected future requirements easily:

  • A filesystem needs more space than expected? No problem, you can extend it on-line. (Extending a filesystem is usually much easier than shrinking one, so lowballing the expected requirements and then extending as needed can be a good strategy.)
  • You need a small filesystem with special mount options for a chroot jail? Just create a new LV for it using some of the unallocated space.

How do I expand the root filesystem?

For example, to extend it by 5 GB:

sudo lvextend --resizefs -L +5G ubuntu-vg/ubuntu-lv

Or if you want to use all the remaining unallocated capacity to extend the root filesystem:

sudo lvextend --resizefs -l +100%FREE ubuntu-vg/ubuntu-lv

If you don't use the --resizefs option, then the command will just extend the logical volume but not the filesystem inside it. Then you must use another command to tell the filesystem to take advantage of the extension: either fsadm resize /dev/mapper/ubuntu--vg-ubuntu--lv or a filesystem-specific command like resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv or xfs_growfs /.

(The --resizefs option of lvextend will actually just run the fsadm resize ... command for you once the LV is successfully extended.)

4
  • Will this work while the root fs is mounted? Aug 14, 2021 at 19:09
  • 1
    Yes, it will work. (Edited one of my sentences to hopefully make it clearer.)
    – telcoM
    Aug 15, 2021 at 23:21
  • 3
    @telcoM While I agree that reserving space for expansion is a good idea, Canonical's arbitrary decision to say "Use full disk" on the first screen of the 20.04 partition configuration, and then only allocate half of the space, is deceptive and frustrating. I had to manually expand over 50 VMs after discovering this problem on client servers. It is not mentioned anywhere during the installation or the release notes for 20.04 and all previous versions (and indeed 22.04) do not make this assumption without asking.
    – BobbyMick
    Jun 29, 2022 at 7:14
  • 2
    @BobbyMick I agree: good idea, but the implementation needs work. It would probably need better visualization and/or documentation to make it more obvious what is going to happen.
    – telcoM
    Jun 29, 2022 at 13:01
-1

CONTEXT

There should be (sort of) multiple file systems on a LVM block. This is the way a physical file system is represented in LVM (at least as far as LVM and LVM2 are concerned).

If you look at the fs with Gparted GUI, it will look different than other partitions. Whereas most partitions will be represented by a bunch of blocks laid out in a row which represents a drive, the LVM partition will be 2 blocks, one stacked on top of the other, nested within the row.

This is because LVM consists of multiple volumes, which work together to store, and give you access to, your data. Sort of like RAID, although here is where their similarities end.

And this is where it may get a bit confusing. Technically, these two drives are representing the same data, but in different ways. If you are familiar with archiving, the same abstraction can be made to work for LVM (although the terms are not interchangeable.)

LVM has logical volumes (LVs), physical volumes (PVs), and volume groups (VGs). A single volume group can hold multiple physical volumes. It will also contain a logical volume, which holds metadata for the physical volumes. In other words, it is said that the logical volume in a VG 'maps' the VG's physical volumes. This metadata is why I compared earlier to the concept of an archive.

This mapping functionality gives LVM some advantages over other file systems. For one thing, since its physical portion can be split into portions, the LVM partition, itself, can be split across more than one drive. This is not possible with, for example, Ext2,3,4 volumes.

The main disadvantage of LVM (at least in my experience) occurs in the 'applied' realm. Especially where Ubuntu is concerned.

For example, if you obtained your LVM via the "repair drive" option on the Ubuntu Live media (i.e. you used a USB boot stick to repair a broken partition, and got back a LVM2 / LUKs partition), then their is a high likelihood that it will not work.

Disclaimer: This is intended to be a very high level explanation, not a deep dive. In that regard, some of the statements are in a "more or less" format, so as to make the concepts understandable. In some places, I actually started to explain more deeply, but found the result to be hard to follow, so I changed them. For a deeper look, see here.

TO ANSWER THE QUESTION ITSELF

The filesystem itself is only a piece of your lvm partition. In each instance I have seen so far, in a LVM partition created by Ubuntu Live, there are 2 PVs. This may be editable. That said, I have worked with 5 separate blocks, all created by different users at different times and on different machines, and in my experience, 2 has always been the magic number. Take that however you want.

The best way to see the concept for yourself (on 20.04; not sure about the Gparted version) is to inspect your drive with Gparted GUI. You will see the abstraction I've laid out first hand.

5
  • Don't miss the link at the end of the first section. It provides the detail that this answer can not. Never realized how difficult LVM is to explain. If this ends up being confusing, let me know why, and I will try to fix it.
    – Nate T
    Aug 13, 2021 at 3:02
  • I don't have a Desktop installed so can't run GParted. but using cfdisk I can only find one /dev/vda3 and /dev/mapper/ubuntu--vg-ubuntu--lv, but I still don't understand anything. /dev/vda3 is ~50GB and /dev/mapper/ubuntu--vg-ubuntu--lv is ~25GB ? Aug 13, 2021 at 11:17
  • Found this command: vgdisplay, which says 24GB Alloc and 24GB free, so guess that explains that. But then how do I grow the group/partition to allocate all space? Aug 13, 2021 at 12:21
  • @NateT There is no "should be multiple filesystems on a LVM block". A LVM volume group can contain any number of logical volumes/filesystems on any number of physical volumes: it can be "one PV with multiple small LVs", "one huge LV built up of many PVs", "many LVs on many PVs" or even the trivial "just one LV and some unallocated space on one PV for now": LVM allows the filesystem to be easily expanded or moved to another PV while it is mounted. And you did not actually answer the question, "how do I expand the root filesystem?"
    – telcoM
    Aug 15, 2021 at 23:36
  • @NateT I didn't downvote your answer. Aug 16, 2021 at 23:08

You must log in to answer this question.

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