Skip to content

Instantly share code, notes, and snippets.

@Jip-Hop
Last active July 22, 2024 08:54
Show Gist options
  • Save Jip-Hop/d7a8fa6ed08d6121c77ef8840d466be7 to your computer and use it in GitHub Desktop.
Save Jip-Hop/d7a8fa6ed08d6121c77ef8840d466be7 to your computer and use it in GitHub Desktop.
Temporarily extend available packages in TrueNAS SCALE using systemd-sysext. For educational purposes. Use at your own risk!
#!/usr/bin/env bash
# Specify destination for extension rootfs
ROOTFS_PATH=/mnt/tank/some/dataset/ext/rootfs
# List of packages to install
PACKAGES="usbutils"
# Download minimal debian base rootfs
mkdir -p "$ROOTFS_PATH"
curl -L https://github.com/debuerreotype/docker-debian-artifacts/raw/dist-amd64/bookworm/slim/rootfs.tar.xz | tar -xJ -C "$ROOTFS_PATH" --numeric-owner
# Ensure we don't ship an os-release file
mkdir -p "$ROOTFS_PATH"/usr/lib/extension-release.d/
rm "$ROOTFS_PATH"/etc/os-release
mv "$ROOTFS_PATH"/usr/lib/os-release "$ROOTFS_PATH"/usr/lib/extension-release.d/extension-release.Jip-Hop
# Install desired packages (use the iX apt sources from host to match versions)
systemd-nspawn -D "$ROOTFS_PATH" --bind-ro=/etc/apt --bind-ro=/etc/ssl/certs apt-get update
systemd-nspawn -D "$ROOTFS_PATH" --bind-ro=/etc/apt --bind-ro=/etc/ssl/certs apt-get -y --no-install-recommends install $PACKAGES
# Optional cleanup to reduce size of extension rootfs
rm -rf "$ROOTFS_PATH"/var/cache/*
rm -rf "$ROOTFS_PATH"/var/lib/apt/lists/*
# Make extension discoverable temporarily (repeat after reboot)
mkdir -p /run/extensions
ln -s "$ROOTFS_PATH" /run/extensions/Jip-Hop
systemd-sysext list # should show the Jip-Hop extension
# Actually merge the extension with the host OS!
systemd-sysext merge
systemd-sysext status # should show Jip-Hop after /usr
# Now you can run the commands provided by the installed packages (e.g. lsusb) from the TrueNAS shell!
# It will be available temporarily (rebooting will restore the host OS to the original state)
# Do the work you need to do here
# Restore the host OS to the original state
systemd-sysext unmerge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment