Customising UC20 kernel command line arguments

On Ubuntu Core 20, when using the default GNU GRUB bootloader, the kernel command line options can be customised (requires snapd 2.50+).

The kernel command line is formed from mode arguments set by snapd, a static element declared in the bootloader configuration script, and optional extra arguments.

For example, the run mode kernel command line is:

snapd_recovery_mode=run console=ttyS0 console=tty1 panic=-1

While the recovery mode of a system labeled 20210512 would look like this:

snapd_recovery_mode=recover snapd_recovery_system=20210512 console=ttyS0 console=tty1 panic=-1

In the above examples, the mode arguments are snapd_recovery_mode and snapd_recovery_system. The static command line element for the grub bootloader is console=ttyS0 console=tty1 panic=-1 which is defined in the snapd source code.

Customising the command line

The kernel command line can be customised by adding one of two possible files to the Gadget snap:

  1. Add a cmdline.extra file containing the extra kernel command line arguments, such as custom.option=1. These arguments are automatically appended to the command line:
    run mode:
    snapd_recovery_mode=run console=ttyS0 console=tty1 panic=-1 custom.option=1
    recovery mode of system 20210512:
    snapd_recovery_mode=recover snapd_recovery_system=20210512 console=ttyS0 console=tty1 panic=-1 custom.option=1

  2. Add a cmdline.full file containing the full kernel command line to replace the built-in static command line entirely.

    For example, if cmdline.full file has the following contents:

    # my custom option
    # use only ttyS0

    The kernel command line contain the following:
    run mode:
    snapd_recovery_mode=run custom.option=1 console=ttyS0
    recovery mode of system 20210512:
    snapd_recovery_mode=recover snapd_recovery_system=20210512 custom.option=1 console=ttyS0

Both kernel command line extension methods also apply to install mode.

The gadget can only contain either cmdline.full or cmdline.extra file. Presence of both files at the same time is treated as an error.

Extending the kernel command line using drop-in files is also supported on systems using the full disk encryption. See Full disk encryption in the Ubuntu Core documentation for more details.

Last updated 4 months ago.