nixos/lib/make-ext4-fs: always allow execution of resize2fs #86366
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is the result of an extensive investigation I have done when having an unusual build failure when building an SD card image for AArch64 with QEMU. Specifically, I was getting this:
The reason for this failure is due to the combination of three different causes:
fsck.ext4
, executed beforeresize2fs
, is executed with the-n
flag which opens the image read-only. In turn, this leads the image to have a non-updated "last check time", a timestamp present in EXT filesystems which contains the date of the last successful fsck. By default,resize2fs
checks whetherlast_check >= last_mount_time
is true -- if it isn't, it doesn't run.cptofs
which we use to copy files to the target image, has introduced a regression two years ago which broke the wall clock time, making it always start from Jan 1 1970 (UNIX epoch). Before that, the wall clock time was synchronized with the host system's time.cptofs
takes a while to run which leads it to set the mount time of the image to Jan 1 1970 00:00:02. This is enough to breakresize2fs
, since the filesystem is created with a timestamp of Jan 1 1970 00:00:01 and the check mentioned above fails, since the last mount time is greater than the time of last check.Thus there are two approaches to fix this:
-n
frome2fsck
in favor of-y
or something else. This would fix the issue as it advances the last check time, but isn't really necessary as the builder fails if fsck fails.-f
toresize2fs
which forces it to skip the last time check. This is safe, becausefsck
is invoked immediately before and after and it would fail the builder if something is wrong. Thus, the checks are redundant (and in this case would break the build).I have chosen to proceed with the second option.
Motivation for this change
Without the
-f
flag,resize2fs
checks that the last time where thefilesystem was checked is greater or equal than the last time is mounted.
This currently works due to a bug in
cptofs
(lkl/linux#488) and it breaks on slower systems
when the last mount time is greater than 1970-01-01 00:00:01.
To fix this, either we allow
fsck
to update the "last checked" timestampon the filesystem, which requires to replace the
-n
option with-y
,or we force
resize2fs
to skip these checks. Since we're only dealingwith an image file which is checked immediately before resizing, it is
safe to bypass this check as
fsck
will fail if the filesystem is unclean.Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
) tested the resulting imagenix path-info -S
before and after)