From 846d67b64b73af49b284b5ba19f62bf5598e7cc9 Mon Sep 17 00:00:00 2001 From: Zen Date: Thu, 31 Oct 2024 13:08:47 -0500 Subject: [PATCH] don't umount livecd mounts Signed-off-by: Zen --- src/ugrd/fs/livecd.py | 10 ++-------- src/ugrd/fs/livecd.toml | 4 ---- src/ugrd/fs/mounts.py | 10 ++++++---- src/ugrd/fs/overlayfs.py | 23 +++++++++++------------ 4 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/ugrd/fs/livecd.py b/src/ugrd/fs/livecd.py index a9d01ed7..9d4113e0 100644 --- a/src/ugrd/fs/livecd.py +++ b/src/ugrd/fs/livecd.py @@ -1,5 +1,5 @@ __author__ = "desultory" -__version__ = "0.5.0" +__version__ = "0.5.1" from zenlib.util import contains @@ -7,12 +7,7 @@ @contains("livecd_label", "livecd_label must be set to the label of the livecd.", raise_exception=True) def generate_livecd_mount(self): """Makes the mounts entry for livecd base.""" - self["mounts"] = {"livecd": {"label": self.livecd_label, "no_validate": True}} - - -def prepare_squashfs_mount(self) -> str: - """Create the folder for the squashfs mount in /run""" - return "edebug $(mkdir -pv /run/squashfs)" + self["mounts"] = {"livecd": {"label": self.livecd_label, "no_validate": True, "no_umount": True}} @contains("squashfs_image", "squashfs_image must be set to the path of the squashfs image to mount.", raise_exception=True) @@ -23,7 +18,6 @@ def set_squashfs_mount(self): "type": "squashfs", "options": ["loop"], "path": f"/livecd/{self.squashfs_image}", - "destination": "/run/squashfs", "no_validate": True, } } diff --git a/src/ugrd/fs/livecd.toml b/src/ugrd/fs/livecd.toml index fc5948e4..c506cf5f 100644 --- a/src/ugrd/fs/livecd.toml +++ b/src/ugrd/fs/livecd.toml @@ -1,7 +1,6 @@ modules = ["ugrd.fs.overlayfs"] squashfs_image = 'image.squashfs' -lowerdir = "/run/squashfs" hostonly = false kmod_init = ['hfsplus', 'nls_utf8', 'squashfs', 'isofs', 'loop'] @@ -9,9 +8,6 @@ kmod_init = ['hfsplus', 'nls_utf8', 'squashfs', 'isofs', 'loop'] [imports.build_pre] "ugrd.fs.livecd" = ["generate_livecd_mount", "set_squashfs_mount"] -[imports.init_early] -"ugrd.fs.livecd" = ["prepare_squashfs_mount"] - [custom_parameters] squashfs_image = "Path" # the path to the squashfs image (at runtime) livecd_label = "str" # The label of the livecd diff --git a/src/ugrd/fs/mounts.py b/src/ugrd/fs/mounts.py index 0c7e01c6..c18cb2af 100644 --- a/src/ugrd/fs/mounts.py +++ b/src/ugrd/fs/mounts.py @@ -1,5 +1,5 @@ __author__ = "desultory" -__version__ = "5.4.2" +__version__ = "5.5.0" from pathlib import Path @@ -14,6 +14,7 @@ "options", "no_validate", "no_validate_options", + "no_umount", "base_mount", *SOURCE_TYPES, ] @@ -211,10 +212,11 @@ def generate_fstab(self, mount_class="mounts", filename="/etc/fstab") -> None: def umount_fstab(self) -> list[str]: - """Generates a function to unmount all mounts in the fstab.""" + """Generates a function to unmount all mounts which are not base_mounts + and do not have no_umount set""" mountpoints = [] for mount_info in self["mounts"].values(): - if mount_info.get("base_mount"): + if mount_info.get("base_mount") or mount_info.get("no_umount"): continue if str(mount_info.get("destination")) == str(self["mounts"]["root"]["destination"]): continue @@ -223,7 +225,7 @@ def umount_fstab(self) -> list[str]: if not mountpoints: return [] - out = [f"einfo 'Unmounting filesystems: {' ,'.join(mountpoints)}'"] + out = [f"einfo 'Unmounting filesystems: {', '.join(mountpoints)}'"] for mountpoint in mountpoints: out.append(f"umount {mountpoint} || ewarn 'Failed to unmount: {mountpoint}'") diff --git a/src/ugrd/fs/overlayfs.py b/src/ugrd/fs/overlayfs.py index 43a26f80..4d986343 100644 --- a/src/ugrd/fs/overlayfs.py +++ b/src/ugrd/fs/overlayfs.py @@ -1,22 +1,21 @@ +__version__ = "0.1.0" + from zenlib.util import unset -@unset('lowerdir', "lowerdir is already set, skipping detection.") + +@unset("lowerdir", "lowerdir is already set, skipping detection.") def detect_lowerdir(self): """Detect the lowerdir using the mounts['root']['destination']""" - self['lowerdir'] = self.mounts['root']['destination'] - self.logger.info("Detected lowerdir: %s" % self['lowerdir']) + self["lowerdir"] = self.mounts["root"]["destination"] + self.logger.info("Detected lowerdir: %s" % self["lowerdir"]) -def init_overlayfs(self) -> list[str]: +def init_overlayfs(self) -> str: """Returns bash lines to create the upperdir and workdir Uses /run/upperdir and /run/workdir.""" - return ["edebug $(mkdir -pv /run/upperdir /run/workdir)"] - -def mount_overlayfs(self) -> list[str]: - """Returns bash lines to mount the overlayfs based on the lowerdir""" - return [ - "einfo $(mount -t overlay overlay -o lowerdir=%s,upperdir=/run/upperdir,workdir=/run/workdir $(readvar SWITCH_ROOT_TARGET))" % self['lowerdir'] - ] - + return "edebug $(mkdir -pv /run/upperdir /run/workdir)" +def mount_overlayfs(self) -> str: + """Returns bash lines to mount the overlayfs based on the defined lowerdir""" + return 'edebug "[%s] Mounting overlayfs at $(readvar SWITCH_ROOT_TARGET)): $(mount -t overlay overlay -o lowerdir=%s,upperdir=/run/upperdir,workdir=/run/workdir $(readvar SWITCH_ROOT_TARGET))"' % (self["lowerdir"], self["lowerdir"])