Allowing snapd debug options to be set on kernel cmdline


When developing Ubuntu Core images for devices it is often useful to get debug logs from snapd …
To achieve this today you need to hack the image rootfs to inject environment variables (SNAPD_DEBUG=1 SNAPD_DEBUG_HTTP=7) into the boot process (typically either by editing /etc/environment or by injecting an override systemd unit for snapd).

On some devices with internal disk devices (MMC, NAND flash etc) injecting such stuff is really non-trivial (on some you actually need to modify the image before flashing).

While modifying the rootfs is usually very hard when not using an SD card, it is typically very easy to stop the boot at bootloader level with a serial console and adjust the kernel cmdline instead of modifying the rootfs.

It would be great if snapd could parse /proc/cmdline and read debug options from there to avoid having to edit the actual disk image.


We could do this fairly easily by having the implementation of osutil.GetenvBool and GetenvInt64 also look in the kernel commandline if running on core.


Because these are set via the environment, you can use the systemd.setenv kernel option to set it: systemd.setenv=SNAPD_DEBUG=1 and possibly also systemd.setenv=SNAPD_DEBUG_HTTP=7, say.


OOOH !!!