summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2023-06-25 09:52:27 -0400
committerAndrew Cady <d@jerkface.net>2023-06-25 12:45:52 -0400
commit60f8cbcdd073854e6ea804b3129010dffbf0cdef (patch)
tree17d97635f04d9b2679c2695e2601a78b7dccafa3
parent041fde012385cd83876573edd97e30d25f4fb893 (diff)
Store all btrfs images in local subvolumes
Most btrfs images were stored in `_build`, but some were stored in the yaml source directory. Those in the yaml source directory are moved to the yaml source directory subdirectory `_filesystem`. The code that creates `_filesystem` creates a btrfs subvolume. The code to create the `_build` directory has been changed to create a subvolume as well. Using subvolumes for image file directories allows them to be excluded from backup snapshots, which is highly desirable for these very large files.
-rw-r--r--fsmgr.hs46
1 files changed, 33 insertions, 13 deletions
diff --git a/fsmgr.hs b/fsmgr.hs
index 2ee7c7c..8036734 100644
--- a/fsmgr.hs
+++ b/fsmgr.hs
@@ -127,12 +127,11 @@ aptListFiles AptListCfg{..} =
127 [ "httpredir.debian.org_debian_dists_bullseye_InRelease" 127 [ "httpredir.debian.org_debian_dists_bullseye_InRelease"
128 , "httpredir.debian.org_debian_dists_bullseye_main_binary-amd64_Packages" 128 , "httpredir.debian.org_debian_dists_bullseye_main_binary-amd64_Packages"
129 , "httpredir.debian.org_debian_dists_bullseye_main_i18n_Translation-en" 129 , "httpredir.debian.org_debian_dists_bullseye_main_i18n_Translation-en"
130 -- , "httpredir.debian.org_debian_dists_sid_InRelease" 130 , "security.debian.org_debian-security_dists_bullseye-security_InRelease"
131 -- , "httpredir.debian.org_debian_dists_sid_main_binary-amd64_Packages" 131 , "security.debian.org_debian-security_dists_bullseye-security_main_binary-amd64_Packages"
132 -- , "httpredir.debian.org_debian_dists_sid_main_i18n_Translation-en" 132 , "security.debian.org_debian-security_dists_bullseye-security_main_i18n_Translation-en"
133 , "security.debian.org_dists_bullseye-security_InRelease" 133 , "security.debian.org_debian-security_dists_bullseye-security_non-free_binary-amd64_Packages"
134 , "security.debian.org_dists_bullseye-security_main_binary-amd64_Packages" 134 , "security.debian.org_debian-security_dists_bullseye-security_non-free_i18n_Translation-en"
135 , "security.debian.org_dists_bullseye-security_main_i18n_Translation-en"
136 ] 135 ]
137 136
138buildRoot :: DiskImageConfig -> FilePath -> Action () 137buildRoot :: DiskImageConfig -> FilePath -> Action ()
@@ -165,8 +164,11 @@ buildRoot config@DiskImageConfig{..} finalOut = do
165 cmd_ "selfstrap" (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint, "--release", releaseCodename aptListCfg]) (dynamicNames <$> packageNames) 164 cmd_ "selfstrap" (("--unpack" `consWhen` unpackOnly) ["-t", mountpoint, "--release", releaseCodename aptListCfg]) (dynamicNames <$> packageNames)
166 when (not $ null debs) $ do 165 when (not $ null debs) $ do
167 need debs 166 need debs
168 cmd_ (AddEnv "DEBIAN_FRONTEND" "noninteractive") 167 ignoreErrors $
169 ["dpkg"] [if unpackOnly then "--unpack" else "--install"] ["--root", mountpoint] debs 168 cmd_ (AddEnv "DEBIAN_FRONTEND" "noninteractive")
169 ["dpkg"] [if unpackOnly then "--unpack" else "--install"] ["--root", mountpoint] debs
170 cmd_ "chroot" [mountpoint] "/bin/sh -c" ["DEBIAN_FRONTEND=noninteractive apt -f install"]
171
170 {- 3. binaries -} 172 {- 3. binaries -}
171 let go b = do 173 let go b = do
172 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b) 174 p <- fromMaybe (fail $ "not found in ${PATH}: " ++ b) <$> liftIO (pathLocate b)
@@ -472,29 +474,47 @@ earlyFail = do
472 Stdout () <- cmd (Traced []) "which selfstrap" 474 Stdout () <- cmd (Traced []) "which selfstrap"
473 return () 475 return ()
474 476
477ioUnless :: MonadIO m => IO Bool -> m () -> m ()
478ioUnless test act = liftIO test >>= (`unless` act)
479
480needSubvolume :: FilePath -> Action ()
481needSubvolume path = ioUnless (IO.doesDirectoryExist path) $ cmd_ "btrfs subvolume create" [path]
482
475shakeRules :: Rules () 483shakeRules :: Rules ()
476shakeRules = do 484shakeRules = do
477 "_build/*.yaml.canon" %> \out -> do 485 "_build/*.yaml.canon" %> \out -> do
486 needSubvolume "_build"
478 let yaml = dropDirectory1 $ dropExtension out 487 let yaml = dropDirectory1 $ dropExtension out
479 need [yaml] 488 need [yaml]
480 cfg <- readCfg yaml 489 cfg <- readCfg yaml
481 writeFileChanged out (show cfg) 490 writeFileChanged out (show cfg)
482 "_build/*.btrfs" %> \out -> do 491 "_build/*.btrfs" %> \out -> do
492 needSubvolume "_build"
483 let cfgFile = (out -<.> "yaml.canon") 493 let cfgFile = (out -<.> "yaml.canon")
484 need [cfgFile] 494 need [cfgFile]
485 cfg <- readEither <$> readFile' cfgFile 495 cfg <- readEither <$> readFile' cfgFile
486 either (error . (("Error parsing file: " ++ cfgFile ++ ": ") ++)) (flip buildRoot out) cfg 496 either (error . (("Error parsing file: " ++ cfgFile ++ ": ") ++)) (flip buildRoot out) cfg
497
487 priority 2 $ "*.seed.btrfs" %> \out -> do 498 priority 2 $ "*.seed.btrfs" %> \out -> do
488 let tmp = out <.> "tmp" 499 needSubvolume "_build"
489 inp = dropExtension out -<.> ".btrfs" 500 needSubvolume "_filesystem"
501 let inp = dropExtension out -<.> ".btrfs"
502 fso = "_filesystem" </> out
503 tmp = fso <.> "tmp"
490 need [inp] 504 need [inp]
491 cmd_ "cp --reflink=always" [inp, tmp] 505 cmd_ "cp --reflink=always" [inp, tmp]
492 setupLoopDevices ("_build" </> inp <.> "btrfs") 506 setupLoopDevices ("_build" </> inp <.> "btrfs")
493 cmd_ "btrfs-shrink" [tmp] 507 cmd_ "btrfs-shrink" [tmp]
494 cmd_ "btrfstune -f -S1" [tmp] 508 cmd_ "btrfstune -f -S1" [tmp]
495 cmd_ (WithStderr False) "mv -i" [tmp, out] 509 cmd_ (WithStderr False) "mv -i" [tmp, fso]
510 cmd_ (WithStderr False) "ln -s -i" [fso, out]
496 511
497 priority 1 $ "*.btrfs" %> \out -> do 512 priority 1 $ "*.btrfs" %> \out -> do
498 need ["_build" </> out] 513 needSubvolume "_build"
514 needSubvolume "_filesystem"
515 let b = "_build" </> out
516 f = "_filesystem" </> out
517 need [b]
499 -- WithStderr False needed for `cp` to interact with the tty 518 -- WithStderr False needed for `cp` to interact with the tty
500 cmd_ (WithStderr False) "cp --reflink=always -i" ["_build" </> out, out] 519 cmd_ (WithStderr False) "cp --reflink=always -i" [b, f]
520 cmd_ (WithStderr False) "ln -s -i" [f, out]