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
- Ubuntu Core images — how image-garden makes Ubuntu Core systems
- Model, gadget and kernel — the model assertion and its grade, on the snapd map
Part of journeys
- Your own kernel or gadget on Ubuntu Core, step 3 of 5 · previous: Model, gadget and kernel · next: Trying and packing a snap
01 A kernel nobody signed
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+dangerousand26+dangerous(050-ubuntu-core.mk:4), on x86_64 and aarch64. - snapd is read at commit
880846b6for this map.
Read more
- Model, gadget and kernel on the snapd map, Ubuntu Core images.
02 Where the grade comes from
+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: dangerousis derived from the channel's name and from image-garden's TPM test treating them alike; check it withsnap model --assertion, which prints the raw model assertion (snapd cmd_model.go:83-93). - A model without a
gradeheader issigned, the default: see the model deck.
Read more
- Model, gadget and kernel on the snapd map.
03 What grade dangerous unlocks
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
checkGadgetOrKernelapplies to snaps of type gadget and kernel (snapd check_snap.go:279-293) and refuses an unasserted replacement unless the grade is dangerous (snapd check_snap.go:318-320).system.kernel.dangerous-cmdline-append(snapd kernel.go:40) is appended to the kernel command line only when the model's grade is dangerous;system.kernel.cmdline-appendis filtered by the gadget's allow list (snapd kcmdline.go:268-285).- The full list of what grade dangerous permits is in the snapd map's model deck and its reference; the command line in the kernel command line.
Read more
04 Copy, install, reboot
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 allocateforwards127.0.0.1:PORTto the guest's SSH port and prints the address (image-garden:1095-1206); Ubuntu Core's only login isubuntu/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. 5123andmy-kernel_6.8_amd64.snapare examples.
Read more
05 Gone when you discard
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);discardkills 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
- allocate, discard and ps, living with strict confinement for where the overlay lives in the snap.
06 Bake it into 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_COREand its release, such as24+dangerous(050-ubuntu-core.mk:116), soUBUNTU_CORE_24+dangerous_CLOUD_INIT_USER_DATA_TEMPLATEis tried beforeUBUNTU_CORE_CLOUD_INIT_USER_DATA_TEMPLATE(010-qemu.mk:293-298). UBUNTU_CORE_CLOUD_INIT_USER_DATA_TEMPLATEis the base Ubuntu Core template, which ends withruncmd:lines, the last bringingeth0back 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
runcmdlines, and10.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
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 usesencryptedfor grade secured andprefer-encryptedfor 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-tpmand their 26 equivalents and checks a TPM 2, Secure Boot and that the data and save mounts are onCRYPT-*devices (task.yaml:8-51).
Read more
- What is encrypted and who decides on the snapd map, Secure Boot and TPM.
08 Where to go from here
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
Read more
- On the snapd map: model and grade, trying and packing a snap, the kernel command line, what is encrypted.
- Here: allocate, Secure Boot and TPM, Ubuntu Core images.
Roads from here
UBUNTU CORE · all snaps
- Ubuntu Core with Secure Boot and a TPM — the +dangerous+tpm systems, with Secure Boot and a TPM
- Ubuntu Core images — back to the Ubuntu Core images
RUNTIME · make rules and the CLI
- image-garden allocate — the background VM this deck installs into
FIRST BOOT · cloud-init changes
- How a user-data template is chosen — how a system picks its cloud-init template
Snapd map ↗
- Trying and packing a snap — snap try, snap pack and snap install --dangerous, on the snapd map
- The kernel command line — how the kernel command line is put together, on the snapd map
- What is encrypted and who decides — what grade and storage safety decide about encryption, on the snapd map
- Model, gadget and kernel — everything else grade dangerous allows, on the snapd map