nixpkgs/nixos/lib
Damien Diederen 7c2adb1d5c nixos/lib/make-ext4-fs: Fix: `resize2fs -M' can leave insufficient slack
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
2021-05-31 21:35:51 +02:00
..
make-options-doc nixosOptionsDoc: add markdown formatting 2021-04-13 10:10:40 -07:00
test-driver nixos/test-driver: mention the elapsed time when it times out 2021-05-30 17:26:13 +02:00
build-vms.nix nixosTest: Make system.nixos.revision constant 2021-03-22 21:39:43 +01:00
eval-config.nix Merge pull request #51850 from roberth/nixos-pure 2020-08-24 04:29:37 +02:00
from-env.nix
make-channel.nix Remove incorrect sentence from make-channel comment 2018-11-04 20:45:49 +01:00
make-disk-image.nix Merge pull request #120489 from samueldr/fix/make-disk-image-auto-size 2021-04-26 10:34:15 +02:00
make-ext4-fs.nix nixos/lib/make-ext4-fs: Fix: `resize2fs -M' can leave insufficient slack 2021-05-31 21:35:51 +02:00
make-iso9660-image.nix nixos: use nativeBuildInputs in make- iso9660-image and system-tarball 2020-11-18 14:05:30 +01:00
make-iso9660-image.sh make-iso9660-image: produce stable GPT disk GUID 2020-07-20 11:16:59 +02:00
make-squashfs.nix squashfs: use -no-hardlinks for reproducible squashfs images (#114454) 2021-02-28 18:03:50 +00:00
make-system-tarball.nix nixos: use nativeBuildInputs in make- iso9660-image and system-tarball 2020-11-18 14:05:30 +01:00
make-system-tarball.sh use closure-info for building system tarball 2018-11-07 12:52:53 +08:00
qemu-flags.nix nixos/qemu-flags: add ppc64 2021-03-05 01:57:54 -08:00
testing-python.nix nixos/testing: add interactive serial stdout logs switch and dim them 2021-05-14 20:36:00 -04:00
utils.nix nixos/{containers,cri-o,podman}: move copyFile to nixos/lib/utils 2020-09-24 10:01:47 +10:00