From 7d1fc7d6ca032700b8fbddca6fe5ef59cb07ebf8 Mon Sep 17 00:00:00 2001 From: bugclerk <40872210+bugclerk@users.noreply.github.com> Date: Thu, 21 Nov 2024 08:30:38 -0800 Subject: [PATCH] Build `/usr/share/truenas/sysext-extensions/functioning-dpkg.raw` (#768) (cherry picked from commit b5fa4840eadf20b13b06eed27d9e2e18d8527cbd) (cherry picked from commit 37cb4257fdc4d04410814e7dd6dcad1fb9d39828) Co-authored-by: themylogin --- scale_build/image/update.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scale_build/image/update.py b/scale_build/image/update.py index 75a43d84..1e8364e6 100644 --- a/scale_build/image/update.py +++ b/scale_build/image/update.py @@ -5,6 +5,7 @@ import textwrap import shutil import stat +import tempfile from scale_build.config import SIGNING_KEY, SIGNING_PASSWORD from scale_build.utils.manifest import get_manifest @@ -174,13 +175,33 @@ def custom_rootfs_setup(): shutil.rmtree(tmp_systemd) run_in_chroot(['depmod'], check=False) - # /usr will be readonly and so we want the ca-certificates directory to + # /usr will be readonly, and so we want the ca-certificates directory to # symlink to writeable location in /var/local local_cacerts = os.path.join(CHROOT_BASEDIR, "usr/local/share/ca-certificates") os.makedirs(os.path.join(CHROOT_BASEDIR, "usr/local/share"), exist_ok=True) shutil.rmtree(local_cacerts, ignore_errors=True) os.symlink("/var/local/ca-certificates", local_cacerts) + # Build a systemd-sysext extension that, upon loading, will make `/usr/bin/dpkg` working. + # It is necessary for `update-initramfs` to function properly. + sysext_extensions_dir = os.path.join(CHROOT_BASEDIR, "usr/share/truenas/sysext-extensions") + os.makedirs(sysext_extensions_dir, exist_ok=True) + with tempfile.TemporaryDirectory() as td: + os.makedirs(f"{td}/usr/bin") + shutil.copy2(f"{CHROOT_BASEDIR}/usr/bin/dpkg", f"{td}/usr/bin/dpkg") + + os.makedirs(f"{td}/usr/local/bin") + with open(f"{td}/usr/local/bin/dpkg", "w") as f: + f.write("#!/bin/bash\n") + f.write("exec /usr/bin/dpkg \"$@\"") + os.chmod(f"{td}/usr/local/bin/dpkg", 0o755) + + os.makedirs(f"{td}/usr/lib/extension-release.d") + with open(f"{td}/usr/lib/extension-release.d/extension-release.functioning-dpkg", "w") as f: + f.write("ID=_any\n") + + run(["mksquashfs", td, f"{sysext_extensions_dir}/functioning-dpkg.raw"]) + def clean_rootfs(): to_remove = get_manifest()['base-prune']