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

[Backport release-21.05] nixos/lib/make-ext4-fs: Fix: `resize2fs -M' can leave insufficient slack #125159

Merged
merged 1 commit into from
Jul 10, 2021

Conversation

github-actions[bot]
Copy link
Contributor

@github-actions github-actions bot commented Jun 1, 2021

Description

Backport of #125121 to release-21.05.

The root filesystem resizing step, `resize2fs -M', does not provide any
control over the amount of slack left in the result.  It can produce an
arbitrarily tight fit, depending on how well the payload aligns with
ext4 data structures.

This is problematic, as NixOS must create a few files and directories
during its first boot, before the root is enlarged to match the size of
the containing SD card.

An overly tight fit can cause failures in the first stage:

    mkdir: can't create directory '/mnt-root/proc': No space left on device

or in the second stage:

    install: cannot create directory '/var': No space left on device

A previous version of `make-ext4-fs' (before PR #79368) was explicitly
"reserving" 16 MiB of free space in the final filesystem.  Manually
calculating the size of an ext4 filesystem is a perilous endeavor,
however, and the method it employed was apparently unreliable.

Reverting is consequently not a good option.

A solution would be to create some sort of "balloon" occupying inodes
and blocks in the image prior to invoking `resize2fs -M', and to remove
these temporary files/directories before the compression step.

This changeset takes the simpler approach of simply dropping the
resizing step.

Note that this does *not* result in a larger image in general, as the
current procedure does not truncate the `.img' file anyway.  In fact, it
has been observed to yield *smaller* compressed images---probably
because of some "noise" left after resizing.  E.g., before-vs-after:

    -r--r--r-- 2 root root 607M  1. Jan 1970  nixos-sd-image-21.11pre-git-x86_64-linux.img.zst

    -r--r--r-- 2 root root 606M  1. Jan 1970  nixos-sd-image-21.11pre-git-x86_64-linux.img.zst

(cherry picked from commit 7c2adb1)
@ztzg
Copy link
Contributor

ztzg commented Jun 7, 2021

@samueldr, @Mic92: Could we get this fix in 21.05?

P.-S. -- I have appended some additional details to #125121 (comment).

@markuskowa markuskowa requested a review from Mic92 June 14, 2021 19:38
Copy link
Contributor

@ck3d ck3d left a comment

Choose a reason for hiding this comment

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

If this PR would be merged, then I can get rid of nasty hacks to get small NixOS images running. What is needed to get this PR into nixos-21.05?

@Mic92 Mic92 merged commit 54db964 into release-21.05 Jul 10, 2021
@Mic92 Mic92 deleted the backport-125121-to-release-21.05 branch July 10, 2021 08:28
@ck3d
Copy link
Contributor

ck3d commented Jul 10, 2021

Great, thank you Mic92 and ztzg

@ztzg
Copy link
Contributor

ztzg commented Jul 10, 2021

Great; thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants