git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/lib/make-ext4-fs: fall back to resize2fs -M if exact resize fails

See also - https://bugs.launchpad.net/ubuntu/+source/e2fsprogs/+bug/1415077/comments/4 - https://github.com/NixOS/nixpkgs/pull/62262

commitdb894cb8ce2be173250c6e423cbc2622881e4496 authorRichard Marko <srk@48.io> dateWed 5 Feb 2020, 15:29 (7 years ago) parent8a14852
1 file changed+3−16
nixos/lib/make-ext4-fs.nix+3−16
nixos/lib/make-ext4-fs.nix+3−16
@@ -64,7 +64,7 @@ pkgs.stdenv.mkDerivation {
6464 echo "copying files to image..."
6565 cptofs -t ext4 -i $img ./files/* /
6666
67−
67+ export EXT2FS_NO_MTAB_OK=yes
6868 # I have ended up with corrupted images sometimes, I suspect that happens when the build machine's disk gets full during the build.
6969 if ! fsck.ext4 -n -f $img; then
7070 echo "--- Fsck failed for EXT4 image of $bytes bytes (numInodes=$numInodes, numDataBlocks=$numDataBlocks) ---"
@@ -72,21 +72,8 @@ pkgs.stdenv.mkDerivation {
7272 return 1
7373 fi
7474
75− (
76− # Resizes **snugly** to its actual limits (or closer to)
77− free=$(dumpe2fs $img | grep '^Free blocks:')
78− blocksize=$(dumpe2fs $img | grep '^Block size:')
79− blocks=$(dumpe2fs $img | grep '^Block count:')
80− blocks=$((''${blocks##*:})) # format the number.
81− blocksize=$((''${blocksize##*:})) # format the number.
82− # System can't boot with 0 blocks free.
83− # Add 16MiB of free space
84− fudge=$(( 16 * 1024 * 1024 / blocksize ))
85− size=$(( blocks - ''${free##*:} + fudge ))
86−
87− echo "Resizing from $blocks blocks to $size blocks. (~ $((size*blocksize/1024/1024))MiB)"
88− EXT2FS_NO_MTAB_OK=yes resize2fs $img -f $size
89− )
75+ echo "Resizing to minimum allowed size"
76+ resize2fs -M $img
9077
9178 # And a final fsck, because of the previous truncating.
9279 fsck.ext4 -n -f $img