Package: livefs-edit
A tool to "edit" Ubuntu live server CDsThere are a few reasons the Ubuntu live server ISOs as shipped may not
quite be what you want. Here are some examples:You want to make an ISO that does a completely automated installYou want packages that are not in the package repository by default
to be available during install, even when there is no network (or
only a very isolated network).You want to add an argument to the default kernel command line.You want to inject a new version of the subiquity snap for testing.This script aims to help you making modified versions of the
distributed ISOs with changes such as those above.Some of the things it does probably work on desktop installer ISOs too
but I haven't thought very hard about that side of things yet.DependenciesThis script is pretty Linux-dependent and requiresxorrisoandmksquashfsto be available on$PATH.  Some actions require thepython3-debianpackage to be installed andgpgcommand to be
available.It needs to be run as root (although possibly using FUSE variants for
all the mounts would allow it to run as a regular user, maybe).General invocationThe basic idea behind this tool is that you tell it where to find the
source ISO, where to put the modified ISO and a list of actions that
make up the modifications. So an invocation always looks somewhat like
this:# livefs-edit $source.iso $dest.iso [actions]Actions can be specified two ways: on the command line or in a YAML
file. Each action has a name and many of them take arguments.On the command line, actions and arguments are specified like:--action-name arg1 arg2 --next-action-nameArguments that are interpreted as boolean interpret 'on', 'yes',
'true' (case insensitively) as true.Alternatively (if shell quoting starts to get painful), the actions
can be passed as a YAML file, using the--action-yamlflag:# livefs-edit $source.iso $dest.iso --action-yaml examples/example.yamlThe YAML file should be a list of mappings. Each mapping names the
actions withnameand lists any arguments by name, for example:- name: add-cmdline-arg
  arg: autoinstall
  persist: false
- name: shell
- name: add-packages-to-pool
  packages:
    - casper
    - valgrindDirectory structureThis script does all its work in a temporary directory. Within that
directory the original ISO is mounted atold/isoand what will be
packed into the new ISO is present atnew/iso(the script uses a lot
ofoverlayfsmounts to avoid copying large amounts of data around,
and also only repack things when there are changes).Many actions require a writable emulation of the root filesystem that
the installer will run in. By default this is created atrootfsin
the main temporary directory, but this can be customized.In general, things from the original ISO are mounted inold/and are
either read-only or should be treated as such. Writable versions for
the new ISO live innew/(mostly).Actionssetup-rootfsargument:target(default:"rootfs")This action sets up a writable emulation of the root filesystem that
the installer will run in at the directory named bytarget. Changes
to this rootfs will be present in the rootfs used by installer on the
modified ISO.Many actions will do this implicitly but it may be clearer to be
explicit about the target directory name if latershellorcpactions refer to paths in the rootfs.shellargument:command(default:null)Runs a shell (bash) in the main temporary directory. Ifcommandis
present, this is the command that is run. If not, an interactive shell
is run. If the shell (command or interactive) exits with a non-zero
code, that aborts the run.cpargument:sourceargument:destCopy a file. Ifsourceordestare relative they are assumed to be
relative to the main temporary directory. So something like this:--cp /my/custom/initrd new/iso/casper/initrdto replace the initrd.inject-snapargument:snapargument:channel(default:"stable")Inject the passed snap into the rootfs the installer runs in. This is
used to test new versions of subiquity. If there is an assert
alongside the snap, this will be copied into the ISO too and the snap
set up to track the passed channel, otherwise it is installed
unasserted.add-snap-from-storeargument:snap_nameargument:channel(default:"stable")A wrapper around `--inject-snap`` that downloads the specified snap
from the store first.edit-squashfsargument:nameargument:add_sys_mounts(default:true)Mount the squashfs namednameatnew/{name}and arrange for it be
repacked if there are any changes before the new ISO is made.add_sys_mountscontrols whether the usual chroot setup stuff is done
(mounting /dev, /proc/ etc, setting up /etc/resolv.conf).add-cmdline-argargument:argargument:persist(default:true)Add an argument to the default kernel command line. Ifpersistis
true, it will be present on the default kernel command line of the
installed system as well.add-autoinstall-configargument:autoinstall_configAdd the provided autoinstall config to the ISO so it is used by
default. This also adds "autoinstall" to the default kernel command
line.autoinstall_configis the path to a YAML file which can contain
either the autoinstall config directly or a cloud-init user-data file
(in which case it can contain other configuration for the live
installer session, such as ssh keys to be used for theinstalleruser).add-debs-to-poolargument: list of deb filesAdd the passed deb files to the repository on the CD so that they are
available for installation while the installer is running, even if the
install is done offline.This will generate a new Ed25519 GPG key, sign the package repository
on the ISO with it, arrange for the public part to end up in/etc/apt/trusted.gpg.d/custom-iso-key.gpgin the installed system,
and then throw the private part away. You should be aware of this
change to the default apt configuration! Deleting this file in an
autoinstalllate-commandwould be a reasonable thing to do, unless
you want the option of using the ISO as an apt repository later on.add-packages-to-poolargument: list of package namesThis is a wrapper aroundadd-debs-to-poolwhich takes package names
rather than deb files. It downloads the listed packages and any others
needed to satisfy their dependencies from the main Ubuntu archive and
passes them toadd-debs-to-pool. Do read the note about GPG in the
description of that action.unpack-initrdargument:target(default:"new/initrd")Unpack the initrd using unmkinitramfs intotarget(contents will
likely end up in subdirectories called things likeearly,early2andmain, at least on amd64) and arrange for these to be repacked
into a replacement initrd for the modified ISO if any changes are made.