git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/lib/make-ext4-fs: fall back to resize2fs -M if exact resize fails
db894cbRichard Marko
nixos/lib/make-ext4-fs.nix+3−16
@@ -64,7 +64,7 @@ pkgs.stdenv.mkDerivation {
64 echo "copying files to image..."
64 echo "copying files to image..."
65 cptofs -t ext4 -i $img ./files/* /
65 cptofs -t ext4 -i $img ./files/* /
66
66
67−
67+ export EXT2FS_NO_MTAB_OK=yes
68 # I have ended up with corrupted images sometimes, I suspect that happens when the build machine's disk gets full during the build.
68 # I have ended up with corrupted images sometimes, I suspect that happens when the build machine's disk gets full during the build.
69 if ! fsck.ext4 -n -f $img; then
69 if ! fsck.ext4 -n -f $img; then
70 echo "--- Fsck failed for EXT4 image of $bytes bytes (numInodes=$numInodes, numDataBlocks=$numDataBlocks) ---"
70 echo "--- Fsck failed for EXT4 image of $bytes bytes (numInodes=$numInodes, numDataBlocks=$numDataBlocks) ---"
@@ -72,21 +72,8 @@ pkgs.stdenv.mkDerivation {
72 return 1
72 return 1
73 fi
73 fi
74
74
75− (
75+ echo "Resizing to minimum allowed size"
76− # Resizes **snugly** to its actual limits (or closer to)
76+ resize2fs -M $img
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− )
90
77
91 # And a final fsck, because of the previous truncating.
78 # And a final fsck, because of the previous truncating.
92 fsck.ext4 -n -f $img
79 fsck.ext4 -n -f $img