efibootmgr

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2021 License: GPL-3.0 Imports: 16 Imported by: 1

Documentation

Overview

Package efibootmgr contains a boot management library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEfiArchitecture

func GetEfiArchitecture() string

GetEfiArchitecture returns the EFI architecture for the target system

func InstallShim

func InstallShim(esp string, source string, vendor string) (bool, error)

InstallShim installs the shim into the given ESP for the given vendor It returns true if it installed the shim.

func MaybeUpdateFile

func MaybeUpdateFile(dst string, src string) (bool, error)

MaybeUpdateFile copies src to dest if they are different It returns true if the destination file was successfully updated. If the return value is false, the state of the destination is unspecified. It might not exist, exist with partial data or exist with old data, amongst others.

func WriteShimFallback

func WriteShimFallback(w io.Writer, entries []BootEntry) error

WriteShimFallback writes out a BOOT*.CSV for the shim fallback loader to the specified writer. The output of this function is unencoded, use a transformed UTF-16 writer.

func WriteShimFallbackToFile

func WriteShimFallbackToFile(path string, entries []BootEntry) error

WriteShimFallbackToFile opens the specified path in UTF-16LE and then calls WriteShimFallback

Types

type BootEntry

type BootEntry struct {
	Filename    string
	Label       string
	Options     string
	Description string
}

BootEntry is a boot entry.

type BootEntryVariable

type BootEntryVariable struct {
	BootNumber int                // number of the Boot variable, for example, for Boot0004 this is 4
	Data       []byte             // the data of the variable
	Attributes uint32             // any attributes set on the variable
	LoadOption efivars.LoadOption // the data of the variable parsed as a load option, if it is a valid load option
}

BootEntryVariable defines a boot entry variable

type BootManager

type BootManager struct {
	// contains filtered or unexported fields
}

BootManager manages the boot device selection menu entries (Boot0000...BootFFFF).

func NewBootManagerFromSystem

func NewBootManagerFromSystem() (BootManager, error)

NewBootManagerFromSystem returns a new BootManager object, initialized with the system state.

func (*BootManager) DeleteEntry

func (bm *BootManager) DeleteEntry(bootNum int) error

DeleteEntry deletes an entry and updates the cached boot order.

The boot order still needs to be committed afterwards. It is not written back immediately, as there will usually be multiple places to update boot order, and we can coalesce those writes. We still have to update the boot order though, such that when we delete an entry and then create a new one with the same number we don't accidentally have the new one in the order.

func (*BootManager) FindOrCreateEntry

func (bm *BootManager) FindOrCreateEntry(entry BootEntry, relativeTo string) (int, error)

FindOrCreateEntry finds a matching entry in the boot device selection menu, or creates one if it is missing.

It returns the number of the entry created, or -1 on failure, with error set.

The argument relativeTo specifies the directory entry.Filename is in.

func (*BootManager) NextFreeEntry

func (bm *BootManager) NextFreeEntry() (int, error)

NextFreeEntry returns the number of the next free Boot variable.

func (*BootManager) PrependAndSetBootOrder

func (bm *BootManager) PrependAndSetBootOrder(head []int) error

PrependAndSetBootOrder commits a new boot order or returns an error.

The boot order specified is prepended to the existing one, and the order is deduplicated before committing.

type EFIVariables

type EFIVariables interface {
	GetVariableNames(filterGUID efivars.GUID) []string
	GetVariable(guid efivars.GUID, name string) (data []byte, attrs uint32)
	VariablesSupported() bool
	SetVariable(guid efivars.GUID, name string, data []byte, attrs uint32, mode os.FileMode) error
	DelVariable(guid efivars.GUID, name string) error
	NewDevicePath(filepath string, options uint32) (efivars.DevicePath, error)
}

EFIVariables abstracts away the host-specific bits of the efivars module

type FS

type FS interface {
	// Create behaves like os.Create()
	Create(path string) (io.WriteCloser, error)
	// MkdirAll behaves like os.MkdirAll()
	MkdirAll(path string, perm os.FileMode) error
	// Open behaves like os.Open()
	Open(path string) (io.ReadSeekCloser, error)
	// ReadDir behaves like os.ReadDir()
	ReadDir(path string) ([]os.DirEntry, error)
	// Remove behaves like os.Remove()
	Remove(path string) error
}

FS abstracts away the filesystem.

So we really wanted to use afero because it does all the magic for us, but it doubles our binary size, so that seems a tad much.

type KernelManager

type KernelManager struct {
	// contains filtered or unexported fields
}

KernelManager manages kernels in an SP vendor directory.

It will update or install shim, copy in any new kernels, remove old kernels, and configure boot in shim and BDS.

func NewKernelManager

func NewKernelManager() (*KernelManager, error)

NewKernelManager returns a new kernel manager managing kernels in the host system

func (*KernelManager) CommitToBootLoader

func (km *KernelManager) CommitToBootLoader() error

CommitToBootLoader updates the firmware BDS entries and shim's boot.csv

func (*KernelManager) InstallKernels

func (km *KernelManager) InstallKernels() error

InstallKernels installs the kernels to the ESP and builds up the boot entries to commit using CommitToBootLoader()

func (*KernelManager) RemoveObsoleteKernels

func (km *KernelManager) RemoveObsoleteKernels() error

RemoveObsoleteKernels removes old kernels in the ESP vendor directory

type RealEFIVariables

type RealEFIVariables struct{}

RealEFIVariables provides the real implementation of efivars

func (RealEFIVariables) DelVariable

func (RealEFIVariables) DelVariable(guid efivars.GUID, name string) error

DelVariable proxy

func (RealEFIVariables) GetVariable

func (RealEFIVariables) GetVariable(guid efivars.GUID, name string) (data []byte, attrs uint32)

GetVariable proxy

func (RealEFIVariables) GetVariableNames

func (RealEFIVariables) GetVariableNames(filterGUID efivars.GUID) []string

GetVariableNames proxy

func (RealEFIVariables) NewDevicePath

func (RealEFIVariables) NewDevicePath(filepath string, options uint32) (efivars.DevicePath, error)

NewDevicePath proxy

func (RealEFIVariables) SetVariable

func (RealEFIVariables) SetVariable(guid efivars.GUID, name string, data []byte, attrs uint32, mode os.FileMode) error

SetVariable proxy

func (RealEFIVariables) VariablesSupported

func (RealEFIVariables) VariablesSupported() bool

VariablesSupported proxy

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL