Skip to content

Commit

Permalink
Do not return error for efi.ReadLoadOption
Browse files Browse the repository at this point in the history
When encountering a boot-entry for a device-path that go-efilib is
unable to parse we should just skip that entry instead of erroring out.

This same behavior is used earlier in the same loop so this should fix
an edge-case where the boot entry is parseable but the device-path is
not.

Signed-off-by: Fredrik Lönnegren <[email protected]>
  • Loading branch information
frelon committed May 23, 2024
1 parent fa82c1b commit 2e56a09
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/bootloader/grub.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (g *Grub) clearEntry() error {
// createBootEntry will create an entry in the efi vars for our shim and set it to boot first in the bootorder
func (g *Grub) CreateEntry(shimName string, relativeTo string, efiVariables eleefi.Variables) error {
g.logger.Debugf("Creating boot entry for elemental pointing to shim %s/%s", constants.EntryEFIPath, shimName)
bm, err := eleefi.NewBootManagerForVariables(efiVariables)
bm, err := eleefi.NewBootManagerForVariables(g.logger, efiVariables)
if err != nil {
return err
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/efi/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ import (

efi "github.com/canonical/go-efilib"
efilinux "github.com/canonical/go-efilib/linux"

"github.com/rancher/elemental-toolkit/v2/pkg/types"
)

const (
maxBootEntries = 65535 // Maximum number of boot entries we can hold
)

// NewBootManagerForVariables returns a boot manager for the given EFIVariables manager
func NewBootManagerForVariables(efivars Variables) (BootManager, error) {
func NewBootManagerForVariables(logger types.Logger, efivars Variables) (BootManager, error) {
var err error
bm := BootManager{}
bm.efivars = efivars
Expand Down Expand Up @@ -51,6 +53,7 @@ func NewBootManagerForVariables(efivars Variables) (BootManager, error) {
for _, name := range names {
var entry BootEntryVariable
if parsed, err := fmt.Sscanf(name, "Boot%04X", &entry.BootNumber); len(name) != 8 || parsed != 1 || err != nil {
logger.Warnf("Failed reading efi load option for '%s': %s", name, err.Error())
continue
}
entry.Data, entry.Attributes, err = bm.efivars.GetVariable(efi.GlobalVariable, name)
Expand All @@ -59,7 +62,8 @@ func NewBootManagerForVariables(efivars Variables) (BootManager, error) {
}
entry.LoadOption, err = efi.ReadLoadOption(bytes.NewReader(entry.Data))
if err != nil {
return bm, err
logger.Warnf("Error reading efi load option for '%s': %s", name, err.Error())
continue
}

bm.entries[entry.BootNumber] = entry
Expand Down

0 comments on commit 2e56a09

Please sign in to comment.