Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/ugrd/fs/livecd.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
__author__ = "desultory"
__version__ = "0.5.0"
__version__ = "0.5.1"

from zenlib.util import contains


@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)
Expand All @@ -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,
}
}
4 changes: 0 additions & 4 deletions src/ugrd/fs/livecd.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
modules = ["ugrd.fs.overlayfs"]

squashfs_image = 'image.squashfs'
lowerdir = "/run/squashfs"
hostonly = false

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
10 changes: 6 additions & 4 deletions src/ugrd/fs/mounts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = "desultory"
__version__ = "5.4.2"
__version__ = "5.5.0"

from pathlib import Path

Expand All @@ -14,6 +14,7 @@
"options",
"no_validate",
"no_validate_options",
"no_umount",
"base_mount",
*SOURCE_TYPES,
]
Expand Down Expand Up @@ -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
Expand All @@ -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}'")

Expand Down
23 changes: 11 additions & 12 deletions src/ugrd/fs/overlayfs.py
Original file line number Diff line number Diff line change
@@ -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"])