How is the size of the LVM container decided?

I have noticed that when the Ubuntu Server installer ‘curtin’ creates an LVM container, it does not use all of the available drive space. It seems that, when the created partition is fairly small, it selects half for the LVM container, and when the partition is bigger, for example 1 TB, it selects a smaller fraction, in a reported case 200 GB, in other words approximately 20%.

Please explain why and how the size is decided like that.

From subiquity/controllers/filesystem.py:

    # There's no point using LVM and unconditionally filling the
    # VG with a single LV, but we should use more of a smaller
    # disk to avoid the user running into out of space errors
    # earlier than they probably expect to.
    if vg.size < 10 * (2 << 30):
        # Use all of a small (<10G) disk.
        lv_size = vg.size
    elif vg.size < 20 * (2 << 30):
        # Use 10G of a smallish (<20G) disk.
        lv_size = 10 * (2 << 30)
    elif vg.size < 200 * (2 << 30):
        # Use half of a larger (<200G) disk.
        lv_size = vg.size // 2
    else:
        # Use at most 100G of a large disk.
        lv_size = 100 * (2 << 30)

The rationale is that LVM is a volume management layer; there’s no point in using LVM if your intent is to only have a single filesystem that uses the whole partition. Furthermore, it is trivial for the user to expand a volume post-install, but very difficult to shrink a volume post-install if more space is needed.

The above logic maximizes the chances that LVM will be useful to the user, while also being mindful of disk space issues.

1 Like

Though it’s worth pointing out the code and comments don’t quite match.

10 * (2 << 30) == 21474836480 == 20 GiB

But the first comment discusses it as “10G”.
Do we keep the current behavior (larger LVs by default) or change the code to match the comment intent?

1 Like

In huge disks the size is 200 GB which matches the comment by @dbungert.

@vorlon,

Were the comments made forgetting that

2 << n in python matches

2^(n+1) in bc and 2 ** (n+1) in python?

Or was the programming made with the intent of the comments but overlooking the result?

Given the size requirements of a default Ubuntu server install, I think 10GiB is a better minimum LV size instead of 20GiB, and it’s the code that should be fixed to match the comments.

1 Like

@vorlon,

Do you want a bug report from @dbungert or me, or will you take the intiative to modify the code?

@nio-wiklund - While a bug report would be fine, I don’t think we have to have one as I already have a PR open consistent with @vorlon’s recommendation.

https://github.com/canonical/subiquity/pull/1097

1 Like