summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-10-12 14:25:10 -0400
committerAndrew Cady <d@jerkface.net>2020-10-12 14:25:10 -0400
commitb19d7bb1f5257cfd07c3389bc9b8bf728e00a9f5 (patch)
tree105f0fe60421b0e5700f6a901855ab2f9f8a6155
parent757e35df1bc571cbe414b62cce1d6d3b0eca93b5 (diff)
build shrunken .seed.btrfs images internally
-rw-r--r--Makefile2
-rw-r--r--fsmgr.hs14
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)
5build: 5build:
6 stack build 6 stack build
7 7
8executables = ~/.local/bin/$(binary) ./selfstrap 8executables = ~/.local/bin/$(binary) ./selfstrap ./btrfs-shrink
9 9
10install: build 10install: build
11 stack install 11 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
241 cmd_ "mount -t btrfs" [out] mountpoint 241 cmd_ "mount -t btrfs" [out] mountpoint
242 242
243 SeededImage n f -> do 243 SeededImage n f -> do
244 let parent = "_build" </> f -<.> "btrfs" 244 let parent = f -<.> "seed.btrfs"
245 need [parent] 245 need [parent]
246 246
247 devices <- either (const []) lines . readEither <$> liftIO (readFileOptional (parent <.> "devices.txt")) 247 devices <- either (const []) lines . readEither <$> liftIO (readFileOptional (parent <.> "devices.txt"))
@@ -464,7 +464,17 @@ shakeRules = do
464 need [cfgFile] 464 need [cfgFile]
465 cfg <- readEither <$> readFile' cfgFile 465 cfg <- readEither <$> readFile' cfgFile
466 either (error . (("Error parsing file: " ++ cfgFile ++ ": ") ++)) (flip buildRoot out) cfg 466 either (error . (("Error parsing file: " ++ cfgFile ++ ": ") ++)) (flip buildRoot out) cfg
467 "*.btrfs" %> \out -> do 467 priority 2 $ "*.seed.btrfs" %> \out -> do
468 let tmp = out <.> "tmp"
469 inp = dropExtension out -<.> ".btrfs"
470 need [inp]
471 cmd_ "cp --reflink=always" [inp, tmp]
472 cmd_ "btrfstune -f -S0" [tmp]
473 cmd_ "btrfs-shrink" [tmp]
474 cmd_ "btrfstune -f -S1" [tmp]
475 cmd_ (WithStderr False) "mv -i" [tmp, out]
476
477 priority 1 $ "*.btrfs" %> \out -> do
468 need ["_build" </> out] 478 need ["_build" </> out]
469 -- WithStderr False needed for `cp` to interact with the tty 479 -- WithStderr False needed for `cp` to interact with the tty
470 cmd_ (WithStderr False) "cp --reflink=always -i" ["_build" </> out, out] 480 cmd_ (WithStderr False) "cp --reflink=always -i" ["_build" </> out, out]