Skip to content

Commit 51b732b

Browse files
committed
fix: selection of boot entry
Only pick boot entry if the UKI file exist. Signed-off-by: Noel Georgi <git@frezbo.dev>
1 parent 18f8ac3 commit 51b732b

File tree

1 file changed

+36
-24
lines changed
  • internal/app/machined/pkg/runtime/v1alpha1/bootloader/sdboot

1 file changed

+36
-24
lines changed

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

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,48 +118,60 @@ func ProbeWithCallback(disk string, options options.ProbeOptions, callback func(
118118

119119
options.Logf("sd-boot: found UKI files: %v", xslices.Map(ukiFiles, filepath.Base))
120120

121+
var bootEntry string
122+
121123
// If we booted of UKI/Kernel+Initramfs/ISO Talos installer will always be run which
122124
// sets the `LoaderEntryDefault` to the UKI file name, so either for reboot with Kexec or upgrade
123125
// we will always have the UKI file name in the `LoaderEntryDefault`
124126
// and we can use it to determine the default entry.
125-
bootEntry, err := ReadVariable(LoaderEntryDefaultName)
127+
loaderEntryDefault, err := ReadVariable(LoaderEntryDefaultName)
126128
if err != nil {
127129
return err
128130
}
129131

130-
options.Logf("sd-boot: LoaderEntryDefault: %s", bootEntry)
132+
options.Logf("sd-boot: LoaderEntryDefault: %s", loaderEntryDefault)
131133

132-
if bootEntry == "" {
133-
// If we booted of a Disk image, only `LoaderEntrySelected` will be set until we do an upgrade
134-
// which will set the `LoaderEntryDefault` to the UKI file name.
135-
// So for reboot with Kexec we will have to read the `LoaderEntrySelected`
136-
// upgrades will always have `LoaderEntryDefault` set to the UKI file name.
137-
loaderEntrySelected, err := ReadVariable(LoaderEntrySelectedName)
138-
if err != nil {
139-
return err
140-
}
134+
// If we booted of a Disk image, only `LoaderEntrySelected` will be set until we do an upgrade
135+
// which will set the `LoaderEntryDefault` to the UKI file name.
136+
// So for reboot with Kexec we will have to read the `LoaderEntrySelected`
137+
// upgrades will always have `LoaderEntryDefault` set to the UKI file name.
138+
loaderEntrySelected, err := ReadVariable(LoaderEntrySelectedName)
139+
if err != nil {
140+
return err
141+
}
141142

142-
if loaderEntrySelected == "" {
143-
return errors.New("sd-boot: no LoaderEntryDefault or LoaderEntrySelected found, cannot continue")
144-
}
143+
options.Logf("sd-boot: LoaderEntrySelected: %s", loaderEntrySelected)
145144

146-
bootEntry = loaderEntrySelected
145+
if loaderEntrySelected == "" && loaderEntryDefault == "" {
146+
return errors.New("sd-boot: no LoaderEntryDefault or LoaderEntrySelected found, cannot continue")
147147
}
148148

149-
options.Logf("sd-boot: found boot entry: %s", bootEntry)
150-
151149
for _, ukiFile := range ukiFiles {
152-
if strings.EqualFold(filepath.Base(ukiFile), bootEntry) {
153-
options.Logf("sd-boot: default entry matched as %q", bootEntry)
150+
if loaderEntryDefault != "" && strings.EqualFold(filepath.Base(ukiFile), loaderEntryDefault) {
151+
options.Logf("sd-boot: default entry matched as %q", loaderEntryDefault)
152+
153+
bootEntry = loaderEntryDefault
154154

155-
sdbootConf = &Config{
156-
Default: bootEntry,
157-
}
155+
break
156+
}
157+
158+
if loaderEntrySelected != "" && strings.EqualFold(filepath.Base(ukiFile), loaderEntrySelected) {
159+
options.Logf("sd-boot: selected entry matched as %q", loaderEntrySelected)
160+
161+
bootEntry = loaderEntrySelected
162+
163+
break
158164
}
159165
}
160166

161-
if sdbootConf == nil {
162-
return errors.New("sd-boot: no valid sd-boot config found, cannot continue")
167+
if bootEntry == "" {
168+
return errors.New("sd-boot: no valid boot entry found matching LoaderEntryDefault or LoaderEntrySelected")
169+
}
170+
171+
options.Logf("sd-boot: found boot entry: %s", bootEntry)
172+
173+
sdbootConf = &Config{
174+
Default: bootEntry,
163175
}
164176

165177
options.Logf("sd-boot: using %s as default entry", sdbootConf.Default)

0 commit comments

Comments
 (0)