Skip to content

Commit 11ebb10

Browse files
committed
fix: kexec when using sd-boot
#10443 broke kexec and `callback` was never being called. Signed-off-by: Noel Georgi <git@frezbo.dev>
1 parent 61f1a32 commit 11ebb10

5 files changed

Lines changed: 56 additions & 19 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2025-03-13T14:46:47Z by kres ec5ec04.
3+
# Generated on 2025-03-14T10:24:50Z by kres ec5ec04.
44

55
name: default
66
concurrency:
@@ -102,6 +102,7 @@ jobs:
102102
- name: iso
103103
env:
104104
IMAGE_REGISTRY: registry.dev.siderolabs.io
105+
IMAGER_ARGS: --extra-kernel-arg=console=ttyS0
105106
run: |
106107
make iso secureboot-iso
107108
- name: images-essential
@@ -2214,6 +2215,7 @@ jobs:
22142215
if: github.event_name == 'schedule'
22152216
env:
22162217
IMAGE_REGISTRY: registry.dev.siderolabs.io
2218+
IMAGER_ARGS: --extra-kernel-arg=console=ttyS0
22172219
run: |
22182220
make iso
22192221
- name: images-essential
@@ -3808,8 +3810,8 @@ jobs:
38083810
- name: Generate Checksums
38093811
run: |
38103812
cd _out
3811-
sha256sum cloud-images.json initramfs-amd64.xz initramfs-arm64.xz metal-amd64.iso metal-arm64.iso metal-amd64.raw.zst metal-arm64.raw.zst talosctl-cni-bundle-amd64.tar.gz talosctl-cni-bundle-arm64.tar.gz talosctl-darwin-amd64 talosctl-darwin-arm64 talosctl-freebsd-amd64 talosctl-freebsd-arm64 talosctl-linux-amd64 talosctl-linux-arm64 talosctl-linux-armv7 talosctl-windows-amd64.exe talosctl-windows-arm64.exe vmlinuz-amd64 vmlinuz-arm64 > sha256sum.txt
3812-
sha512sum cloud-images.json initramfs-amd64.xz initramfs-arm64.xz metal-amd64.iso metal-arm64.iso metal-amd64.raw.zst metal-arm64.raw.zst talosctl-cni-bundle-amd64.tar.gz talosctl-cni-bundle-arm64.tar.gz talosctl-darwin-amd64 talosctl-darwin-arm64 talosctl-freebsd-amd64 talosctl-freebsd-arm64 talosctl-linux-amd64 talosctl-linux-arm64 talosctl-linux-armv7 talosctl-windows-amd64.exe talosctl-windows-arm64.exe vmlinuz-amd64 vmlinuz-arm64 > sha512sum.txt
3813+
sha256sum cloud-images.json initramfs-amd64.xz initramfs-arm64.xz metal-amd64.iso metal-arm64.iso metal-amd64-uki.efi metal-arm64-uki.efi metal-amd64.raw.zst metal-arm64.raw.zst talosctl-cni-bundle-amd64.tar.gz talosctl-cni-bundle-arm64.tar.gz talosctl-darwin-amd64 talosctl-darwin-arm64 talosctl-freebsd-amd64 talosctl-freebsd-arm64 talosctl-linux-amd64 talosctl-linux-arm64 talosctl-linux-armv7 talosctl-windows-amd64.exe talosctl-windows-arm64.exe vmlinuz-amd64 vmlinuz-arm64 > sha256sum.txt
3814+
sha512sum cloud-images.json initramfs-amd64.xz initramfs-arm64.xz metal-amd64.iso metal-arm64.iso metal-amd64-uki.efi metal-arm64-uki.efi metal-amd64.raw.zst metal-arm64.raw.zst talosctl-cni-bundle-amd64.tar.gz talosctl-cni-bundle-arm64.tar.gz talosctl-darwin-amd64 talosctl-darwin-arm64 talosctl-freebsd-amd64 talosctl-freebsd-arm64 talosctl-linux-amd64 talosctl-linux-arm64 talosctl-linux-armv7 talosctl-windows-amd64.exe talosctl-windows-arm64.exe vmlinuz-amd64 vmlinuz-arm64 > sha512sum.txt
38133815
- name: release
38143816
uses: crazy-max/ghaction-github-release@v2
38153817
with:
@@ -3821,6 +3823,8 @@ jobs:
38213823
_out/initramfs-arm64.xz
38223824
_out/metal-amd64.iso
38233825
_out/metal-arm64.iso
3826+
_out/metal-amd64-uki.efi
3827+
_out/metal-arm64-uki.efi
38243828
_out/metal-amd64.raw.zst
38253829
_out/metal-arm64.raw.zst
38263830
_out/talosctl-cni-bundle-amd64.tar.gz

.github/workflows/integration-misc-2-cron.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2025-03-10T14:45:43Z by kres ef4356e.
3+
# Generated on 2025-03-14T10:24:50Z by kres ec5ec04.
44

55
name: integration-misc-2-cron
66
concurrency:
@@ -88,6 +88,7 @@ jobs:
8888
if: github.event_name == 'schedule'
8989
env:
9090
IMAGE_REGISTRY: registry.dev.siderolabs.io
91+
IMAGER_ARGS: --extra-kernel-arg=console=ttyS0
9192
run: |
9293
make iso
9394
- name: images-essential

.kres.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ spec:
112112
- name: iso
113113
command: iso secureboot-iso
114114
environment:
115+
IMAGER_ARGS: "--extra-kernel-arg=console=ttyS0"
115116
IMAGE_REGISTRY: registry.dev.siderolabs.io
116117
- name: images-essential
117118
environment:
@@ -194,6 +195,8 @@ spec:
194195
- initramfs-arm64.xz
195196
- metal-amd64.iso
196197
- metal-arm64.iso
198+
- metal-amd64-uki.efi
199+
- metal-arm64-uki.efi
197200
- metal-amd64.raw.zst
198201
- metal-arm64.raw.zst
199202
- talosctl-cni-bundle-amd64.tar.gz
@@ -838,6 +841,7 @@ spec:
838841
- only-on-schedule
839842
command: iso
840843
environment:
844+
IMAGER_ARGS: "--extra-kernel-arg=console=ttyS0"
841845
IMAGE_REGISTRY: registry.dev.siderolabs.io
842846
- name: images-essential
843847
conditions:

internal/app/machined/pkg/runtime/v1alpha1/bootloader/sdboot/sdboot.go

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,29 @@ func New() *Config {
6565
}
6666

6767
// ProbeWithCallback probes the sd-boot bootloader, and calls the callback function with the Config.
68+
//
69+
//nolint:gocyclo
6870
func ProbeWithCallback(disk string, options options.ProbeOptions, callback func(*Config) error) (*Config, error) {
6971
// if not UEFI boot, nothing to do
7072
if !IsUEFIBoot() {
7173
return nil, nil
7274
}
7375

76+
// here we need to read the EFI vars to see if we have any defaults
77+
// and populate config accordingly
78+
// https://www.freedesktop.org/software/systemd/man/systemd-boot.html#LoaderEntryDefault
79+
// this should be set on install/upgrades
80+
efiCtx := efivario.NewDefaultContext()
81+
82+
bootedEntry, err := ReadVariable(efiCtx, LoaderEntrySelectedName)
83+
if err != nil {
84+
return nil, err
85+
}
86+
87+
log.Printf("booted entry: %q", bootedEntry)
88+
89+
config := &Config{}
90+
7491
// read /boot/EFI and find if sd-boot is already being used
7592
// this is to make sure sd-boot from Talos is being used and not sd-boot from another distro
7693
if err := mount.PartitionOp(
@@ -93,6 +110,28 @@ func ProbeWithCallback(disk string, options options.ProbeOptions, callback func(
93110
return fmt.Errorf("no boot*.efi files found in %q", filepath.Join(constants.EFIMountPoint, "EFI", "boot"))
94111
}
95112

113+
// list existing UKIs, and check if the current one is present
114+
ukiFiles, err := filepath.Glob(filepath.Join(constants.EFIMountPoint, "EFI", "Linux", "Talos-*.efi"))
115+
if err != nil {
116+
return err
117+
}
118+
119+
for _, ukiFile := range ukiFiles {
120+
if strings.EqualFold(filepath.Base(ukiFile), bootedEntry) {
121+
config.Default = bootedEntry
122+
}
123+
}
124+
125+
// here we handle a case when we boot of just kernel+initrd/uki and we don't have a booted entry
126+
if bootedEntry == "" && len(ukiFiles) == 1 {
127+
// we have only one UKI, so we can assume it's the default
128+
config.Default = filepath.Base(ukiFiles[0])
129+
}
130+
131+
if callback != nil {
132+
return callback(config)
133+
}
134+
96135
return nil
97136
},
98137
options.BlockProbeOptions,
@@ -111,7 +150,7 @@ func ProbeWithCallback(disk string, options options.ProbeOptions, callback func(
111150
return nil, err
112151
}
113152

114-
return &Config{}, nil
153+
return config, nil
115154
}
116155

117156
// Probe for existing sd-boot bootloader.
@@ -355,26 +394,13 @@ func (c *Config) Revert(disk string) error {
355394
}
356395

357396
func (c *Config) revert() error {
358-
// read current entry from EFI variables
359-
efiCtx := efivario.NewDefaultContext()
360-
361-
// if we can't read the current entry, we can't revert
362-
bootedEntry, err := ReadVariable(efiCtx, LoaderEntrySelectedName)
363-
if err != nil {
364-
return fmt.Errorf("failed to read current UKI, cannot revert: %w", err)
365-
}
366-
367-
if bootedEntry == "" {
368-
return errors.New("no UKI selected, nothing to revert")
369-
}
370-
371397
files, err := filepath.Glob(filepath.Join(constants.EFIMountPoint, "EFI", "Linux", "Talos-*.efi"))
372398
if err != nil {
373399
return err
374400
}
375401

376402
for _, file := range files {
377-
if strings.EqualFold(filepath.Base(file), bootedEntry) {
403+
if strings.EqualFold(filepath.Base(file), c.Default) {
378404
continue
379405
}
380406

internal/app/machined/pkg/runtime/v1alpha1/v1alpha1_sequencer_tasks.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,6 +1925,8 @@ func KexecPrepare(_ runtime.Sequence, data any) (runtime.TaskExecutionFunc, stri
19251925
}
19261926

19271927
if systemDisk == nil {
1928+
log.Print("kexec skipped as system disk is not found")
1929+
19281930
return nil // no system disk, no kexec
19291931
}
19301932

0 commit comments

Comments
 (0)