From c2f8b5d71fa487c28f8d6580573efaef7151af28 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Wed, 6 Jan 2021 23:27:02 +0100 Subject: [PATCH] make-btrfs-fs: start with 4G and auto-shrink --- make-btrfs-fs.nix | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/make-btrfs-fs.nix b/make-btrfs-fs.nix index 10acc68..2762bc3 100644 --- a/make-btrfs-fs.nix +++ b/make-btrfs-fs.nix @@ -58,13 +58,9 @@ pkgs.stdenv.mkDerivation { # Make a crude approximation of the size of the target image. # If the script starts failing, increase the fudge factors here. numInodes=$(find ./rootImage | wc -l) - numDataBlocks=$(du -s -c -B 4096 --apparent-size ./rootImage | tail -1 | awk '{ print int($1 * 1.10) }') - bytes=$((2 * 4096 * $numInodes + 4096 * $numDataBlocks)) - echo "Creating a btrfs image of $bytes bytes (numInodes=$numInodes, numDataBlocks=$numDataBlocks)" - truncate -s $bytes $img - - faketime -f "1970-01-01 00:00:01" fakeroot mkfs.btrfs -L ${volumeLabel} -U ${uuid} -r ./rootImage $img + truncate -s 4G $img + faketime -f "1970-01-01 00:00:01" fakeroot mkfs.btrfs --shrink -L ${volumeLabel} -U ${uuid} -r ./rootImage $img if [ ${builtins.toString compressImage} ]; then echo "Compressing image"