Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bib: improve the "/" size calculation for LVM #750

Merged
merged 4 commits into from
Dec 9, 2024

Conversation

mvo5
Copy link
Collaborator

@mvo5 mvo5 commented Dec 6, 2024

This commit improves the rootfs size calculation for advanced
partitioning. Just like for the tranditional filesystem
customization where we use updateFilesystemSizes() to ensure
that the rootfs is at least the two times size of the container
we need to do the same for the advanced disk partitioning.

The disk library will need a RequiredMinSizes parameter
(see gh#748) to know what sizes to pick. So far we did not
pass this which can leads to a "0B" root partition.

The naive fix was to just include a hardcoded:

requiredDirectorySizes = map[string]uint64{
        "/":    1 * datasizes.GiB,
        "/usr": 2 * datasizes.GiB,
}

but of course that is not ideal because we calculate the
size of disk based on 2x the container size. We set this
for the rootfs so the entire disk is big enough. However
because in advanced partitioning "/" is not automatically
expanded we end up with a potentially too small "/".

This commit tweaks the calculcation so that it sets the
requiredDirectorySizes for "/" to be at least 2x container
size.

Note that a custom "/usr" is not supported in image mode so splitting
rootfsMinSize between / and /usr is not a concern.

Closes: #748

mvo5 added 2 commits December 6, 2024 11:06
This commit adds a regression test for the manifest creation
when custom disk are used. When just adding a swap device the
rootlv size is not set/updated correctly which leads to a
manifest like:
```
...
        {
          "type": "org.osbuild.lvm2.create",
          "options": {
            "volumes": [
              {
                "name": "swaplv",
                "size": "2147483648B"
              },
              {
                "name": "rootlv",
                "size": "0B"
              }
            ]
          },
...
```
for a config like:
```
"customizations": {
            "disk": {
                "partitions": [
                    {
                        "type": "lvm",
                        "minsize": "10 GiB",
                        "logical_volumes": [
                            {
                                "minsize": "2 GiB",
                                "fs_type": "swap",
                            }
                        ]
                    }
                ]
            }
```
When creating custom partitions, include a hardcoded
requiredDirectorySizes (taken from images) to get some sensible
defaults when the user has no minsizes set for e.g. "/" or "/usr".
@achilleas-k
Copy link
Member

Note that for users with a custom "/usr" but no "/" this may lead to
large "/" but the users can tweak it easily by adding "/".

I wonder... does /usr actually work on a separate filesystem? I know we don't block it in the policy, but is it a valid configuration? (quick test shows it's probably not).

@mvo5 mvo5 force-pushed the tweak-lvm-calculations branch from ffb5f27 to f639cc6 Compare December 6, 2024 11:46
@mvo5 mvo5 force-pushed the tweak-lvm-calculations branch 2 times, most recently from ba1d513 to 9f71ee5 Compare December 6, 2024 11:57
@mvo5 mvo5 marked this pull request as ready for review December 6, 2024 11:58
@mvo5 mvo5 force-pushed the tweak-lvm-calculations branch from 9f71ee5 to 367f4ca Compare December 6, 2024 12:07
@mvo5
Copy link
Collaborator Author

mvo5 commented Dec 6, 2024

Note that for users with a custom "/usr" but no "/" this may lead to
large "/" but the users can tweak it easily by adding "/".

I wonder... does /usr actually work on a separate filesystem? I know we don't block it in the policy, but is it a valid configuration? (quick test shows it's probably not).

Excellent point, I now remember we disallow /usr in image-mode (c.f. https://github.com/osbuild/bootc-image-builder/blob/main/bib/cmd/bootc-image-builder/image_test.go#L165) so I updated the description and went with making LVM respect minRootSize (I had a bit of an internal debate if the users choice on lvm root for "/" and "minsize" should always trump "rootfsMinSize" but I think it makes most sense to handle this like filesystem customizations and the updateFilesystemSizes there.

Sorry for the flip-flopping and the force pushes, I really wanted to get this done before the weekend so maybe was a bit rushing it.

@mvo5 mvo5 force-pushed the tweak-lvm-calculations branch 2 times, most recently from a56043f to dc1956f Compare December 6, 2024 15:59
ondrejbudai
ondrejbudai previously approved these changes Dec 6, 2024
Copy link
Member

@ondrejbudai ondrejbudai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks awesome! :)

@ondrejbudai ondrejbudai enabled auto-merge December 6, 2024 16:31
This commit improves the rootfs size calculation for advanced
partitioning.  Just like for the tranditional filesystem
customization where we use `updateFilesystemSizes()` to ensure
that the rootfs is at least the two times size of the container
we need to do the same for the advanced disk partitioning.

The disk library will need a `RequiredMinSizes` parameter
(see gh#748) to know what sizes to pick. So far we did not
pass this which can leads to a "0B" root partition.

The naive fix was to just include a hardcoded:
```
requiredDirectorySizes = map[string]uint64{
        "/":    1 * datasizes.GiB,
        "/usr": 2 * datasizes.GiB,
}
```
but of course that is not ideal because we calculate the
size of disk based on 2x the container size. We set this
for the rootfs so the entire disk is big enough. However
because in advanced partitioning "/" is not automatically
expanded we end up with a potentially too small "/".

This commit tweaks the calculcation so that it sets the
requiredDirectorySizes for "/" to be at least 2x container
size.

Note that a custom "/usr" is not supported in image mode so splitting
rootfsMinSize between / and /usr is not a concern.
@mvo5
Copy link
Collaborator Author

mvo5 commented Dec 6, 2024

The run failed with:

...
2024-12-06T17:32:50.2211320Z LVM2: using vg name '1d1a2221-7acf-4759-a066-9df765ea01ea'
2024-12-06T17:32:50.2211651Z   Physical volume "/dev/loop0" successfully created.
2024-12-06T17:32:50.2211982Z   Creating devices file /etc/lvm/devices/system.devices
2024-12-06T17:32:50.2212370Z   Volume group "1d1a2221-7acf-4759-a066-9df765ea01ea" successfully created
2024-12-06T17:32:50.2212971Z   WARNING: Logical volume 1d1a2221-7acf-4759-a066-9df765ea01ea/var_loglv not zeroed.
2024-12-06T17:32:50.2213355Z   Logical volume "var_loglv" created.
2024-12-06T17:32:50.2213708Z   WARNING: Logical volume 1d1a2221-7acf-4759-a066-9df765ea01ea/swaplv not zeroed.
2024-12-06T17:32:50.2214078Z   Logical volume "swaplv" created.
2024-12-06T17:32:50.2214374Z   Size is not a multiple of 512. Try using 3132294144 or 3132294656.
2024-12-06T17:32:50.2214692Z   Invalid argument for --size: 3132294152B
2024-12-06T17:32:50.2214955Z   Error during parsing of command line.

it seems we will need osbuild/images#1092 too so that we correctly align when EnsureSize() is called becaue of the requiredMinSizes calculations.

Mainly to get osbuild/images#1092 to fix
the lvm alignment calculation.

Co-authored-by: Ondřej Budai <[email protected]
@ondrejbudai ondrejbudai force-pushed the tweak-lvm-calculations branch from 0600441 to 4a6c798 Compare December 7, 2024 11:45
@ondrejbudai
Copy link
Member

osbuild/images#1092 got released as 0.105.0, so I force-pushed a new go.mod. This should be now ready to go. :)

Copy link
Member

@ondrejbudai ondrejbudai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I would like a "cross-approval" since I was the last one who touched this. :)

@ondrejbudai ondrejbudai added this pull request to the merge queue Dec 7, 2024
@ondrejbudai ondrejbudai removed this pull request from the merge queue due to a manual request Dec 7, 2024
@mvo5 mvo5 added this pull request to the merge queue Dec 9, 2024
@mvo5
Copy link
Collaborator Author

mvo5 commented Dec 9, 2024

Looks good, but I would like a "cross-approval" since I was the last one who touched this. :)

Looks good to me as well, thank you!

Merged via the queue into osbuild:main with commit beee195 Dec 9, 2024
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bib failed to generate raw image when config.json contains disk.swap customization
3 participants