From b19d7bb1f5257cfd07c3389bc9b8bf728e00a9f5 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Mon, 12 Oct 2020 14:25:10 -0400 Subject: build shrunken .seed.btrfs images internally --- Makefile | 2 +- fsmgr.hs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index fd6aa0b..b146673 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ sudo := $(shell [ "$(id -u)" = 0 ] || echo sudo) build: stack build -executables = ~/.local/bin/$(binary) ./selfstrap +executables = ~/.local/bin/$(binary) ./selfstrap ./btrfs-shrink install: build stack install diff --git a/fsmgr.hs b/fsmgr.hs index dca488e..2aff987 100644 --- a/fsmgr.hs +++ b/fsmgr.hs @@ -241,7 +241,7 @@ buildInitialImage DiskImageConfig{..} mountpoint out = do cmd_ "mount -t btrfs" [out] mountpoint SeededImage n f -> do - let parent = "_build" f -<.> "btrfs" + let parent = f -<.> "seed.btrfs" need [parent] devices <- either (const []) lines . readEither <$> liftIO (readFileOptional (parent <.> "devices.txt")) @@ -464,7 +464,17 @@ shakeRules = do need [cfgFile] cfg <- readEither <$> readFile' cfgFile either (error . (("Error parsing file: " ++ cfgFile ++ ": ") ++)) (flip buildRoot out) cfg - "*.btrfs" %> \out -> do + priority 2 $ "*.seed.btrfs" %> \out -> do + let tmp = out <.> "tmp" + inp = dropExtension out -<.> ".btrfs" + need [inp] + cmd_ "cp --reflink=always" [inp, tmp] + cmd_ "btrfstune -f -S0" [tmp] + cmd_ "btrfs-shrink" [tmp] + cmd_ "btrfstune -f -S1" [tmp] + cmd_ (WithStderr False) "mv -i" [tmp, out] + + priority 1 $ "*.btrfs" %> \out -> do need ["_build" out] -- WithStderr False needed for `cp` to interact with the tty cmd_ (WithStderr False) "cp --reflink=always -i" ["_build" out, out] -- cgit v1.2.3