Upstream grub does not pass to LoadImage the correct path to the
loaded binary. This results in second grub not knowing where it was
loaded from and loading the wrong grub.cfg. If we set "root", then the
path becomes correct.
Currently in mantic, the Ubuntu patch that used to be applied to 2.06
is not applied to 2.12. So we are we are back to upstream behavior.
The common use case for chainloading in EFI with grub (see
30_os-prober) always sets root. So we should do it and not get broken
again.
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
The copyright of the auto-generated grub_{recovery,}_cfg_assets.go
file is generated from the current date. This leads to a dirty build
when the year changes. This commit hardcodes the copyright year
to 2022.
Once there is a better go build system (or we use something like
meson) we can re-introduce this because then the generated files
will be no longer in git.
grub's regexp does not change the store variable if there is no match,
so checking for empty variable after the regexp call was not really
working. Instead, check for successful regexp call.
This commit will help the boot speed on most PC devices and
requested by the Taipei team.
The changes to the auto-generated parts are done via:
```
$ cd boot/assets
$ go build -o ./genasset/genasset ./genasset/
$ ./genasset/genasset -in ./data/grub.cfg -out grub_cfg_asset.go -name grub.cfg
```
and the `Snapd-Boot-Config-Edition` for `grub.cfg` was bumped.
Note that no changes for the recovery grub configuration are done
in this commit. I'm happy to do a follwup for this.
This is the same fix as commit 17fbdc7c, but in other tests.
The current code will mock the `amd64` architecture when running some
tests but it does not mock the `grub.cfg:static-cmdline` or the
`grub-recovery.cfg:static-cmdline`. This is needed because the
`bootloader/asserts` package registers the cmdline via `init()` so
this happens before the architecture is mocked in the testing
code. Hence the tests will fail when inspecting the command line on
non amd64/i386 machines.
This commit makes the mocking explicit. An alternative approach would
be to move the snippet registration out of `init()` and run it on
first boot but that has it's own problems so this other approach was
followed.
Use different grub binaries in different architectures, by checking
the grub_cfg variable in the grub recovery script. Also, increase the
config edition for grub-recovery.cfg.
Provide the different names for the assets in snapd by using constants
in files tagged for different architectures.
If we chainload in the case of a failed kernel update, we will not be
able to unseal keys from the TMP, as the measurements in the PCR
registers store all the history since we booted so we will get there
unexpected values in the fail case. Instead, reboot so we clean the
PCR registers and we can start the old kernel.