Thomas Bechtold: Streamline Root Filesystem Modifications with chimg

During the last year I developed as a side project a new tool called chimg . That tool is useful to modify a given rootfs chroot directory in a declarative way. It can replace a kernel within a chroot, preseed snaps, install debian packages, add PPAs and more (documentation is in git but not yet published).
The nice thing about this is, that this tool can be integrated into livecd-rootfs (the tool that is usually used to build Ubuntu images) or future tools which might use the craft framework to build images. chimg automatically detects already bind-mounted filesystems (eg. /sys, /proc, …), detects already preseeded snaps and usually does that same thing that livecd-rootfs currently does when eg. replacing an already installed kernel.
Install chimg with:
sudo snap install chimg –classic
An example configuration (eg. config.yaml) to modify a rootfs chroot directory looks like this:
—
kernel: linux-aws
debs:
– name: shim-signed
– name: grub-pc
– name: grub2-common
– name: ubuntu-cloud-minimal
snap:
assertion_brand: canonical
assertion_model: aws-classic
snaps:
– name: hello
channel: latest/stable
files:
–
destination: /etc/default/grub.d/70-mysettings.cfg
content: |+
GRUB_TIMEOUT=0
cmds_post:
–
cmd: |
echo “Everything done”
This config (stored in config.yaml in this example) can be applied to a newly created (or existing) root filesystem directory. Let’s create one in /tmp/chimg-noble:
sudo mmdebstrap –variant=apt –verbose noble /tmp/chimg-noble
Let’s apply the config changes now:
sudo chimg –log-console chrootfs config.yaml /tmp/chimg-noble
That’s it. The modifications are now applied to the /tmp/chimg-noble directory.