I use docker to make changes to the Ubuntu installer live CD. It contains a casper/filesystem.squashfs
that is similar to a chroot
environment; i.e., it is a complete root filesystem that gets written to the target filesystem during installation. I make changes to the filesystem.squashfs
like this:
# extract installer iso
$ osirrox -indev ubuntu-18.04.4-desktop-amd64.iso -extract ./ ./ubuntu-18.04.4-desktop-amd64.d
# extract filesystem squashfs
$ unsquashfs ubuntu-18.04.4-desktop-amd64.d/casper/filesystem.squashfs
# create filesystem tarball
$ tar -cf squashfs-root.tar -C squashfs-root .
# create docker image
$ docker image import squashfs-root.tar squashfs-root:latest
# create docker container, make changes inside
$ docker run --name squashfs-mine squashfs-root sh -c 'touch /etc/my.conf'
At this point, the now-stopped container squashfs-mine
contains the original filesystem, along with any modifications performed during its run
. You can now export
the container's filesystem as a tar archive:
# extract filesystem tarball
$ docker export -o squashfs-mine.tar squashfs-mine
In my case, I would want to generate a new filesystem.squashfs
into the original *.iso
contents and re-pack the *.iso
:
# populate filesystem directory
$ tar -xf squashfs-mine.tar --one-top-level
# create filesystem squashfs
$ mksquashfs squashfs-mine ubuntu-18.04.4-desktop-amd64.d/casper/filesystem.squashfs
# re-pack iso
$ xorriso -as mkisofs ... -o ubuntu-18.04.4-desktop-amd64.iso ubuntu-18.04.4-desktop-amd64.d
...but your needs are probably different.
chroot /location/of/filesystem /usr/bin/app-inside-chroot --flags
. The reason is we have an old OS (updates are in the works but won't be done in time for what we are trying to develop) that needs to run a newer version of an app we are developing. Said app is not compatible with the host OS, but it is compatible with the chroot environment.chroot /path/to/filesystem /bin/bash
will block, but you might be able to turn the work after that into a script that you execute at that point.