72 Commits

Author SHA1 Message Date
Miguel Pires
79c5ac14b2 many: remove usages of deprecated io/ioutil package (#13768)
* many: remove usages of deprecated io/ioutil package

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* .golangci.yml: remove errcheck ignore rule for io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* run-checks: prevent new usages of io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-04-03 23:23:24 +02:00
Valentin David
0267590c2a bootloader/assets/data/grub-recovery.cfg: set root when chainloading
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.
2023-10-11 10:16:09 +01:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
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>
2023-09-26 11:38:46 +01:00
Dimitri John Ledkov
d55f3123d4 go: go fix with 1.18
Apply `go fix ./...` to the whole code base using go-1.18 to remove
old build tags.
2023-09-25 13:22:14 +02:00
Miguel Pires
c0c0c19157 bootloader: fix test w/ auto-generated copyright year
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-01-06 14:31:40 +01:00
Michael Vogt
d4b4efccef bootloader: hardcode copyright year
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.
2023-01-06 10:22:05 +01:00
Michael Vogt
946fb0db42 Merge pull request #12285 from alfonsosanchezbeato/fix-grub-no-system
bootloader/assets: fix grub.cfg when there are no labels
2022-11-01 14:24:24 +01:00
Valentin David
2670743b56 bootloader: do not specify Core version in grub entry
Ubuntu Core 22 now shows "Run Ubuntu Core 20" as boot entry.
2022-10-24 17:15:15 +02:00
Alfonso Sánchez-Beato
d4036a5b7a bootloader/assets: fix grub.cfg when there are no labels
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.
2022-10-20 16:23:56 +01:00
Michael Vogt
5595253031 bootloader/assets: add ttyS0,115200n8 to grub.cfg
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.
2022-07-20 11:54:17 +02:00
Alfonso Sánchez-Beato
87dcd7b7f7 b/a/grub_cfg_asset.go: update as we have changed grub.cfg 2022-04-21 13:26:14 +02:00
Alfonso Sánchez-Beato
8cf83e1524 b/a/d/grub.cfg: remove kernel_fallback varible
Not needed anymore as we reboot instead of chainloading after a
failure.
2022-04-21 12:53:35 +02:00
Alfonso Sánchez-Beato
b7eca4e8d0 Merge branch 'master' into add-grub-fallback 2022-04-21 12:44:19 +02:00
Michael Vogt
d9cf7c9647 Merge remote-tracking branch 'upstream/master' into bboozzoo/factory-reset-spread-no-encrypt 2022-04-11 15:30:58 +02:00
Alfonso Sánchez-Beato
7dd912b49d boot,bootloader: add missing grub.cfg assets mocks in some tests
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.
2022-04-06 16:24:25 +02:00
Maciej Borzecki
cb691abb05 bootloader/assets: regenerate the assets after merge
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-04-06 14:36:12 +02:00
Maciej Borzecki
c60b4d40d6 Merge remote-tracking branch 'upstream/master' into bboozzoo/factory-reset-spread-no-encrypt 2022-04-06 14:34:46 +02:00
alfonsosanchezbeato
d5b3bcc309 b/a: do not set console in kernel command line for arm64
* b/assets: use different kernel command line for arm64

Do not set console in the kernel command line for arm64. The defaults
are better than setting ttyS0 as in x86, also this is our choice in
server images. The kernel will choose the preferred console depending
on whether dtb or ACPI is available:

1. When having a device tree, it will take the content of the
   /chosen/stdout-path node [1]. This node is properly filled in most
   of the cases.

2. If using ACPI tables, it will look for the console in the ACPI SPCR
   table [2,3]. This is different to what is done in x86 [4], as in that
   case the SPCR table is used only if earlycon is set.

[1] https://www.kernel.org/doc/Documentation/devicetree/bindings/chosen.txt
[2] https://docs.microsoft.com/en-us/windows-hardware/drivers/serports/serial-port-console-redirection-table
[3] https://elixir.bootlin.com/linux/v5.17/source/arch/arm64/kernel/acpi.c#L229
[4] https://elixir.bootlin.com/linux/v5.17/source/arch/x86/kernel/acpi/boot.c#L1615

* b/assets: register different grub snippets per arch

This is needed now as the kernel command line parameters will differ
across architectures.

* b/a/grub.go: fix tests for ubuntu-18.04-32

Co-authored-by: Michael Vogt <mvo@ubuntu.com>
2022-04-05 11:27:25 +02:00
Maciej Borzecki
df919bcca2 bootloader/assets: add menu entry for factory reset mode
Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2022-03-30 13:53:00 +02:00
Alfonso Sánchez-Beato
8650c00045 Merge branch 'master' into add-grub-fallback 2022-03-23 14:20:41 +01:00
Alfonso Sánchez-Beato
41cb1b79f7 b/assets: revert grub-recovery.cfg edition to 1 again
There is no need for the bump as no new features are added by using
gnu_arch in the grub script.
2022-02-11 15:44:19 +01:00
Alfonso Sánchez-Beato
261ac5e688 bootloader/assets: update grub.cfg edition number 2022-02-11 13:26:49 +01:00
Alfonso Sánchez-Beato
660db7bf77 bootloader: use different grub binaries in different arch
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.
2022-02-11 12:31:02 +01:00
Ian Johnson
21654fb2f7 bootloader/assets/grub_*cfg_asset.go: update Copyright
Signed-off-by: Ian Johnson <ian.johnson@canonical.com>
2022-01-06 08:51:34 -06:00
Alfonso Sánchez-Beato
e26c07a456 bootloader/assets: on failure, reboot instead of chainloading
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.
2021-12-13 15:49:44 +01:00