1049 Commits

Author SHA1 Message Date
Alfonso Sánchez-Beato
cd49a62ea5 boot: introduce parameter for optional kernel command line
in functions used to update it.
2023-02-27 15:47:07 +01:00
Alex Lewontin
9cf75d31bf bootloader: format recovery boot.sel to mirror gadget boot.sel
Signed-off-by: Alex Lewontin <alex.lewontin@canonical.com>
2023-02-22 17:24:56 +01:00
Alex Lewontin
041b90b183 bootloader: handle uboot envs both with and without header flag byte
Allows snapd to handle uboot envs for uboots with
CONFIG_SYS_REDUNDAND_ENV=n

Signed-off-by: Alex Lewontin <alex.lewontin@canonical.com>
2023-02-22 17:24:56 +01:00
Alfonso Sánchez-Beato
7ddcd46e10 many: use partition role instead of LaidOutStructure in Observe
We do not need the full LaidOutStructure in ContentObserver.Observe,
just pass the structure role. This simplifies some tests.
2023-02-15 17:06:43 +00:00
Michael Vogt
9175d834df boot: on classic+modes MarkBootSuccessfull does not need a base
This commit fixes a a bug in master that will prevent
`MarkBootSuccessful` from working. The issue is that on classic+modes
the modeenv no longer contains a `base=` field but the
MarkBootSuccessful code will fail if it is missing. This results
in a system that never marks the boot as successful on classic+modes.
2023-02-08 17:44:40 +01:00
Michael Vogt
6014c8892d boot: do not include base= in modeenv for classic+modes installs (#12537)
* boot: do not include `base=` in modeenv for classic+modes installs

This is a followup for the PR#12532. Right now the system does
put the `base` into the modeenv on `classic+modes` system. But
here there is no need to keep track of the base as it is not
used for booting, the deb based classic system is used for that.

* boot: clarify comment in makeRunnableSystem
2023-02-06 10:18:23 +01:00
Miguel Pires
d097436c1c many: fix formatting w/ gofmt 1.19
Go 1.19 includes some changes to gofmt which intend to make lists and
heading clearer when rendered (https://go.dev/doc/go1.19). This commit
is the result of running the new gofmt and manually fixing some of it.
This was necessary because the new gofmt assumed lines beginning w/ tabs
to start lists or examples. While this is often true in our codebase,
we occasionally also use tabs to indent the lines after a TODO or FIXME
prefix or in yaml (e.g., excerpts of a snap.yaml). This meant that a lot of the
reformatted comments were broken and had to be fixed manually.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-01-16 14:23:11 +01:00
alfonsosanchezbeato
b479af62f2 boot: avoid reboot loop if there is a bad try kernel (#12425)
In case a bad try kernel was in the disk (i.e. by just a simple
dangling symlink try-kernel.efi), we entered a boot loop. Avoid that.

* tests: add test that checks that there is no boot loop

when we have a dangling try-kernel.efi symlink.

* boot: return status when asking for kernel revisions

Return status when asking for kernel revisions even if there is no try
kernel. It will still be useful. Also, add some clarifying comments to
genericInitramfsSelectSnap.

* boot: clarify comments and traces

* boot: add test for bad try status with no try kernel

* cmd/snap-bootstrap: adapt error string in tests

Due to changes in bootstate.
2022-12-15 11:38:25 +01:00
Alfonso Sánchez-Beato
1d3796ac7e boot: add unit test to check that aborted kernel installation
do the clean-up as expected.
2022-12-13 15:31:34 +00:00
Alfonso Sánchez-Beato
ad07e504a9 boot: remove leftovers on kernel installation abort
When we were aborting a kernel installation before a reboot happened,
a proper clean-up of left-overs was not happening. To fix that, make
sure that current kernels in modeenv is always set appropriately and
also make sure that the try-kernel.efi symbolic link used by the grub
bootloader is removed.
2022-12-13 15:31:34 +00:00
Alfonso Sánchez-Beato
3e7d7ef603 gadget,overlord: add accessors for some fields in LaidOutStructure
Use accessors to access fields from LaidOutStructure.VolumeStructure,
concretely the fields that have the same name as in OnDiskStructure,
so we can transition more easily to the latter when we include it in
the LaidOutStructure struct.
2022-12-08 12:55:04 +01:00
Alfonso Sánchez-Beato
b21f0ff615 many: make VolumeStructure a normal member of LaidOutStructure
Instead of embedding it.
2022-12-08 12:55:04 +01:00
Samuele Pedroni
6854896d63 boot: SnapTypeParticipatesInBoot calls IsClassicBoot on its own 2022-11-30 13:31:45 +01:00
Samuele Pedroni
9c7891074b boot: fix InUse for classic with modes 2022-11-30 13:31:45 +01:00
Alfonso Sánchez-Beato
9ca092b631 boot: add methods to mock sealing a key
So it can be mocked by unit tests for other packages.
2022-11-29 16:29:28 +01:00
Alfonso Sánchez-Beato
34bede3e78 boot: add directory for data on install 2022-11-17 12:34:28 +01:00
Samuele Pedroni
78a3721ab7 many: avoid automatic system restarts on classic through new overlord/restart logic (#12228)
* o/state: fix pendingChangeByAttr initialisation when loading state

* o/restart,o/state: introduce restart.FinishTaskWithRestart

this combines setting the status of a task being finished and requesting a
restart

it will also replace rebooting the system on classic with setting the task into
HoldStatus until a manual system restart occurs

moving the task from HoldStatus to DoneStatus is implemented with
RestartManager.StartUp logic based on extra state attributes to track reboot on
such task and its change

to avoid such pending changes to be pruned prematurely a predicate
RestartManager.PendingForSystemRestart is registered with
State.RegisterPendingChangeByAttr

* overlord: delegate from snapstate.FinishTaskWithRestart to restart

this gives us the right behavior on classic now

adjust tests to the expected behavior, fixing previous XXXs

* o/snapstate: switch around NoErrorOrHold to IsErrAndNotHold

this way fewer places need to negate it

thanks MiguelPires

* o/restart: simplify things a bit turning held-for-system-restart into just a flag

on the Change, instead of a full counter

* o/restart: try to clarify FinishTaskWithRestart behavior in comment

* o/state: do not attempt to run tasks in WaitStatus

the lack of this logic was causing a panic,
given that for now we expect the new status to be used
only on new system revert is not an issue. But if we started
using WaitStatus in preexisting system/scenarios we would
have to think how to deal with this backward incompatibility

* overlord: switch logic to use WaitStatus instead of HoldStatus

* tests: enable kernel refresh testing

the gadget case is still not working, needs more investigation

* tests/fde-on-classic: re-enable test for gadget updates

which was failing because two reboots were happening as the kernel
command line from the manually written grub.cfg was not matching the
one shipped by snapd.

* tests/fde-on-classic: make sure that modeenv kernel command line

matches the one in snapd/grub.cfg.

* tests: check in fde-on-classic test that remote host has no reboot scheduled

* boot: add debug about cmdline updates

* tests: cherry pick https://github.com/snapcore/snapd-testing-tools/pull/33

* tests: update nested fde-on-classic cmdline to match what grub-recovery.cfg writes

Co-authored-by: Alfonso Sánchez-Beato <alfonso.sanchez-beato@canonical.com>
Co-authored-by: Michael Vogt <mvo@ubuntu.com>
2022-11-17 09:25:17 +01:00
Alfonso Sánchez-Beato
9e51d73b58 boot/seal: add debug traces for bootchains 2022-10-24 12:21:46 +01:00
Samuele Pedroni
79fe81dc17 boot,o/devicestate: extend HasFDESetupHook to consider unrelated kernels
Merge pull request #12235 from pedronis/has-fde-setup-hook-standalone

we need to check for hook presence also in kernels that are not the currently installed kernel if any
2022-10-06 18:16:44 +02:00
Samuele Pedroni
3786e8c514 boot: cleanups
thanks @alfonsosanchezbeato
2022-10-06 14:55:02 +02:00
Samuele Pedroni
797798c191 boot: fix typo 2022-10-06 10:36:30 +02:00
Samuele Pedroni
f174f71273 boot: fix filenames written in modeenv for base/gadget
the paths might not have the right filename form as they could be for
unasserted snaps etc
2022-10-06 10:32:53 +02:00
Samuele Pedroni
f31235ef79 boot,o/devicestate: extend HasFDESetupHook to consider unrelated kernels
we need to check for hook presence also in kernels that are not the currently
installed kernel if any
2022-10-06 10:20:37 +02:00
Samuele Pedroni
ca1d7a2504 boot,o/devicestate: introduce and use MakeRunnableStandaloneSystem
MakeRunnableSystem implicitly assumes that the run system is a clone
of the current system, usually a UC20 ephemeral mode system

introduce MakeRunnableStandaloneSystem that does not make this assumption
and use it for the finish step of the install API

in theory we could change MakeRunnableSystem itself not to make the assumption
but it changes a bit its properties so it is something to maybe consider for
later
2022-10-05 16:12:39 +02:00
Samuele Pedroni
b9da041a0b boot: tweak and test code to deal with unasserted uninstalled snaps 2022-10-04 14:42:41 +02:00