Changing a +dangerous Ubuntu Core system

your own kernel or gadget for users for contributors

The +dangerous systems boot the dangerous-stable Ubuntu Core images, whose model has grade dangerous, so snapd lets you replace the signed kernel or gadget with one you built, installed with snap install --dangerous, and append any kernel argument. Allocate the VM, copy the snap in, install, reboot; discard to start clean, or bake the snap in with a template.

On the map: ubuntu core

▶ Watch this deck — 8 scenes, ~5 min

Worth seeing first

Part of journeys

01 A kernel nobody signed

YOUR OWN KERNEL my-kernel_6.8_amd64.snap built by you, signed by nobody a signed model: grade signed snapd refuses the swap grade dangerous: allowed ubuntu-core-22+dangerous · ubuntu-core-24+dangerous · ubuntu-core-26+dangerous this deck: ubuntu-core-24+dangerous.x86_64, in a VM you can throw away
A kernel snap you built cannot replace the signed kernel on a production device: snapd refuses. A model with grade dangerous lets it. image-garden's +dangerous systems are Ubuntu Core 22, 24 and 26 with such a model; this deck uses ubuntu-core-24+dangerous.x86_64

On grade dangerous snapd accepts a kernel or gadget you built. image-garden's +dangerous systems are Ubuntu Core 22, 24 and 26 with such a model.

You've built a kernel snap, or a gadget, and you want to boot it. On a production device you can't: snapd refuses to replace a signed kernel or gadget with one nobody signed. That's the point of signing. For development there's a way out: a model with grade dangerous. image-garden ships such systems, the +dangerous variants of Ubuntu Core 22, 24 and 26. This deck installs your own kernel snap on ubuntu-core-24+dangerous, inside a VM you can throw away, and then shows how to keep it there for every test run.

Details and sources

Details

  • snapd refuses to replace a kernel or gadget that has a snap ID with one that has none, "cannot replace signed %s snap with an unasserted one", unless the model's grade is dangerous (snapd check_snap.go:318-320).
  • The +dangerous releases are 22+dangerous, 24+dangerous and 26+dangerous (050-ubuntu-core.mk:4), on x86_64 and aarch64.
  • snapd is read at commit 880846b6 for this map.

Read more

02 Where the grade comes from

WHERE THE GRADE COMES FROM the brand model assertion built into the image ubuntu-core-24 ← …/24/stable/ 24+dangerous ← …/24/dangerous-stable/ image-garden does not read the model: check it in the VM $ snap model --assertion | grep grade grade: dangerous a +dangerous system grade: signed a plain one: signed, or no grade at all
The brand signs the model assertion, which is built into the image. The +dangerous systems download the image from the dangerous-stable channel instead of stable. image-garden does not read the model: inside the VM, snap model --assertion shows grade: dangerous on a +dangerous system and grade: signed, or no grade, on a plain one

+dangerous images come from …/dangerous-stable/current/. Check with snap model --assertion | grep grade.

Where does the grade come from? Not from image-garden. A model assertion is signed by its brand and built into the image, and the +dangerous systems simply download a different image: the one published in the dangerous-stable channel, next to the stable one. image-garden doesn't read the model, so check for yourself. Inside the VM, snap model with the assertion option prints the whole model. Look for the grade header. On a +dangerous system it should say dangerous. On a plain one it says signed, or nothing, which means the same.

Details and sources

Details

  • The +dangerous downloads come from https://cdimage.ubuntu.com/ubuntu-core/R/dangerous-stable/current/, the plain ones from …/R/stable/current/ (050-ubuntu-core.mk:216-251). image-garden itself sets no grade and reads no model.
  • That the dangerous-stable images carry a model with grade: dangerous is derived from the channel's name and from image-garden's TPM test treating them alike; check it with snap model --assertion, which prints the raw model assertion (snapd cmd_model.go:83-93).
  • A model without a grade header is signed, the default: see the model deck.

Read more

03 What grade dangerous unlocks

WHAT DANGEROUS UNLOCKS current kernel your new kernel snapd compares snap-id: from the store snap-id: none, you built it error: cannot replace signed kernel snap with an unasserted one unless grade is dangerous: allowed $ sudo snap set system system.kernel.dangerous-cmdline-append="…" kernel arguments the gadget's allow list would refuse; dangerous models only more in the model deck ↗
snapd compares a new kernel or gadget with the current one: the current one has a snap ID from the store, the new one has none; snapd refuses with cannot replace signed kernel snap with an unasserted one, unless the model's grade is dangerous. The same grade enables system.kernel.dangerous-cmdline-append, which skips the gadget's allow list

checkGadgetOrKernel refuses an unasserted kernel or gadget over a signed one unless the grade is dangerous. system.kernel.dangerous-cmdline-append is used only on dangerous models.

Here's the rule in snapd. When you install a kernel or a gadget, snapd compares it with the one the device has. If the current one has a snap ID, because it came from the store, and the new one has none, because you built it, snapd refuses: cannot replace signed kernel snap with an unasserted one. Unless the model's grade is dangerous. Then it goes ahead. The same grade opens a second door: the dangerous cmdline append setting, which adds kernel arguments the gadget doesn't allow. The snapd map's model deck lists everything else dangerous permits.

Details and sources

Details

04 Copy, install, reboot

COPY, INSTALL, REBOOT $ image-garden allocate ubuntu-core-24+dangerous.x86_64 localhost:5123 $ scp -P 5123 my-kernel_6.8_amd64.snap ubuntu@localhost: password ubuntu $ sudo snap install --dangerous ./my-kernel_6.8_amd64.snap snapd restarts the machine $ uname -r $ snap list my-kernel rev x1 ubuntu-core-24+dangerous.x86_64.5123.serial.log if it doesn't come back
The loop: image-garden allocate ubuntu-core-24+dangerous.x86_64 prints localhost:PORT; scp -P PORT copies the snap in as ubuntu; sudo snap install --dangerous installs it; snapd restarts the machine; uname -r shows the new kernel and snap list shows revision x1; the serial log shows why when it does not come back

image-garden allocate ubuntu-core-24+dangerous.x86_64, scp -P PORT my-kernel.snap ubuntu@localhost:, sudo snap install --dangerous ./my-kernel.snap, reboot, uname -r.

Here's the whole loop. Make the system and allocate it in the background, which prints a port. Copy your snap in with scp on that port, as ubuntu, password ubuntu. Log in, and install it with sudo snap install --dangerous. For a kernel, snapd restarts the machine to finish; log in again, and uname -r shows your kernel. snap list shows its revision as x1, the mark of a snap that came from a file. If it doesn't come back, the serial log next to the image shows why.

Details and sources

Details

  • image-garden allocate forwards 127.0.0.1:PORT to the guest's SSH port and prints the address (image-garden:1095-1206); Ubuntu Core's only login is ubuntu/ubuntu (050-ubuntu-core.mk:22-26).
  • Inside, the machine's host name is ubuntu-core-24-dangerous: the + of the system name becomes -, as a host name label allows no + (050-ubuntu-core.mk:141, 010-qemu.mk:94-97).
  • The serial console of an allocated machine is written to SYSTEM.PORT.serial.log (image-garden:1153-1163).
  • Derived, from snapd's behaviour as described on the snapd map: a snap installed from a file gets a local revision such as x1, and installing a kernel on Ubuntu Core ends with snapd restarting the device; see trying and packing a snap. Not run for this map.
  • 5123 and my-kernel_6.8_amd64.snap are examples.

05 Gone when you discard

GONE WHEN YOU DISCARD the prepared image read only while -snapshot is on temporary overlay: your kernel reboot in the guest same QEMU process: the overlay stays $ image-garden discard localhost:5123 the overlay goes; the next allocate starts clean QEMU_SNAPSHOT_OPTION="" image-garden allocate … or bake it into the image
allocate runs QEMU with -snapshot: the prepared image stays clean and the kernel install lands in a temporary overlay; a reboot inside the guest keeps it, because QEMU keeps running; discard removes the overlay and the next allocate starts clean; QEMU_SNAPSHOT_OPTION set to empty, or a baked image, keeps a state

With -snapshot your install lives in a temporary overlay: it survives a guest reboot and goes away on discard. QEMU_SNAPSHOT_OPTION="" keeps changes.

Where did that kernel go? allocate starts QEMU in snapshot mode, so the install landed in a temporary overlay, not in the prepared image. A reboot inside the guest is fine: it's the same QEMU process, and the overlay stays. When you discard the machine, the overlay goes with it, and the next allocate starts from the clean image again. That's what you want while you iterate on a kernel. To keep a state, set QEMU_SNAPSHOT_OPTION to empty, or bake the snap into the image itself.

Details and sources

Details

  • allocate runs the launcher with ${QEMU_SNAPSHOT_OPTION=-snapshot} (image-garden:1153-1163); discard kills the QEMU process by its pid file (image-garden:1221-1275).
  • Derived, from QEMU's -snapshot: writes go to a temporary overlay that lasts as long as the QEMU process; a reboot inside the guest does not end the process, because the launcher passes no -no-reboot.
  • QEMU_SNAPSHOT_OPTION="" makes allocate's changes persist in the system's .qcow2.

Read more

06 Bake it into the image

BAKE IT IN group UBUNTU_CORE, release 24+dangerous define UBUNTU_CORE_24+dangerous_CLOUD_INIT_USER_DATA_TEMPLATE $(UBUNTU_CORE_CLOUD_INIT_USER_DATA_TEMPLATE) - curl -o /tmp/k.snap http://10.0.2.2:8000/my-kernel.snap - snap install --dangerous /tmp/k.snap endef illustrative: the runcmd lines are appended to the Ubuntu Core template's provisioning boot: paid once edit .image-garden.mk: a new image
In .image-garden.mk, define UBUNTU_CORE_24+dangerous_CLOUD_INIT_USER_DATA_TEMPLATE, starting with the Ubuntu Core template and appending runcmd lines that fetch the snap from a web server on the host and install it with --dangerous; the provisioning boot does it once, and editing the file rebuilds the image

Define UBUNTU_CORE_24+dangerous_CLOUD_INIT_USER_DATA_TEMPLATE in .image-garden.mk: $(UBUNTU_CORE_CLOUD_INIT_USER_DATA_TEMPLATE) first, then your runcmd lines.

If every test needs your kernel, install it while the image is prepared. An Ubuntu Core system picks its user-data template by group and release, and the group is ubuntu core. So in your .image-garden.mk, define a template for ubuntu core, release 24 +dangerous. Start it with the Ubuntu Core template, then append run commands: fetch your snap from a web server on the host and install it with --dangerous. The provisioning boot pays for that once. Editing the file rebuilds the image, so a new kernel build means a new image.

Details and sources

Details

  • An Ubuntu Core system picks its template with group UBUNTU_CORE and its release, such as 24+dangerous (050-ubuntu-core.mk:116), so UBUNTU_CORE_24+dangerous_CLOUD_INIT_USER_DATA_TEMPLATE is tried before UBUNTU_CORE_CLOUD_INIT_USER_DATA_TEMPLATE (010-qemu.mk:293-298).
  • UBUNTU_CORE_CLOUD_INIT_USER_DATA_TEMPLATE is the base Ubuntu Core template, which ends with runcmd: lines, the last bringing eth0 back up (050-ubuntu-core.mk:131-179).
  • The user-data depends on .image-garden.mk, so editing it makes a new image (line 115).
  • Illustrative, not run for this map: the two runcmd lines, and 10.0.2.2, the address under which QEMU's user networking shows the host to the guest (derived). A kernel installed during provisioning would finish on the next boot, after the provisioning boot powers off; check that in your own setup.

07 Dangerous, and still encrypted

STILL ENCRYPTED storage-safety not set: secured → encrypted signed, dangerous → prefer-encrypted ubuntu-core-24+dangerous+tpm swtpm: a TPM 2.0 ubuntu-data, ubuntu-save encrypted, keys sealed spread-demo/tests/smoke/tpm: +tpm and +dangerous+tpm, CRYPT-* devices an unsigned kernel, with full disk encryption · what decides it ↗
A model without storage-safety defaults to encrypted for grade secured and prefer-encrypted otherwise, including dangerous; on ubuntu-core-24+dangerous+tpm the first boot finds swtpm's TPM, encrypts ubuntu-data and ubuntu-save and seals the keys, as +tpm does; image-garden's TPM smoke test checks both

Without storage-safety, a dangerous model means prefer-encrypted. ubuntu-core-24+dangerous+tpm encrypts ubuntu-data and ubuntu-save like +tpm.

Grade dangerous doesn't switch off encryption. The model's storage safety decides that, and when a dangerous model doesn't set it, it means prefer encrypted: encrypt when the hardware can. On +dangerous+tpm, it can. The first boot finds the TPM that swtpm emulates, encrypts the data partitions and seals the keys to it, just as plain +tpm does. image-garden's own TPM test checks both. So you can try an unsigned kernel together with full disk encryption, and the snapd map explains what decides it.

Details and sources

Details

  • When a model does not set storage-safety, snapd uses encrypted for grade secured and prefer-encrypted for the others (snapd model.go:1103-1122).
  • image-garden's TPM smoke test runs on ubuntu-core-24-plus-tpm, ubuntu-core-24-plus-dangerous-plus-tpm and their 26 equivalents and checks a TPM 2, Secure Boot and that the data and save mounts are on CRYPT-* devices (task.yaml:8-51).

08 Where to go from here

ROADS +dangerous systems Model and grade ↗ on the snapd map Try and pack ↗ install from a file Kernel command line ↗ on the snapd map allocate the background VM Secure Boot and TPM the +tpm systems
Roads from +dangerous systems: on the snapd map the model and grade, snap try and pack, and the kernel command line; on this map allocate and Secure Boot and TPM

Next: on the snapd map the model, snap try and pack, and the kernel command line; here, allocate and Secure Boot and TPM.

So a +dangerous system lets you swap in your own kernel or gadget, try it in a VM you throw away, and bake it in when every test needs it. The snapd map takes it from here: the model deck for everything grade dangerous allows, the snap try and pack deck for building and installing from a file, and the kernel command line deck. Back on this map, allocate has the details of the background VM, and the +tpm deck covers Secure Boot.

Details and sources

Roads from here

UBUNTU CORE · all snaps

RUNTIME · make rules and the CLI

FIRST BOOT · cloud-init changes

Snapd map ↗