efivars

package
v0.0.0-...-6908b6b Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEFIBooted

func IsEFIBooted() bool

IsEFIBooted checks that the machine is booted in EFI mode and that the efivars filesystem is readable.

func ReadBootEntries

func ReadBootEntries() (map[uint16]BootEntry, error)

ReadBootEntries reads all existing EFI boot entries, even if they are not in the boot order.

func WriteBootEntries

func WriteBootEntries(entries map[uint16]BootEntry) error

WriteBootEntries overwrites or creates the specified EFI boot entries. It does not modify or delete any other boot entries.

func WriteBootOrder

func WriteBootOrder(ord BootOrder) error

WriteBootOrder overwrites the EFI boot order variable.

Types

type BootEntry

type BootEntry struct {
	Description     string // eg. "Linux Boot Manager"
	Path            string // eg. `\EFI\systemd\systemd-bootx64.efi`
	PartitionGUID   gpt.Guid
	PartitionNumber uint32 // Starts with 1
	PartitionStart  uint64 // LBA
	PartitionSize   uint64 // LBA
}

BootEntry represents a subset of the contents of a Boot#### EFI variable.

func NewBootEntry

func NewBootEntry(path string, partitions []gpt.Partition) (*BootEntry, error)

NewBootEntry creates a boot entry for softmetal by finding required information about the ESP partition on disk. The partitions argument should contain the final partitions stored on the disk, not the ones in the image. NewBootEntry fills all fields of BootEntry except Description. If there are n != 1 ESP partitions, NewBootEntry fails. ESP partitions are detected by their type: EFI System (see espGUIDStr).

func UnmarshalBootEntry

func UnmarshalBootEntry(d []byte) (*BootEntry, error)

UnmarshalBootEntry loads a BootEntry from its binary representation. WARNING: UnmarshalBootEntry only loads the Description field. Everything else is ignored (and not validated if possible)

func (*BootEntry) Marshal

func (t *BootEntry) Marshal() ([]byte, error)

Marshal generates the binary representation of a BootEntry (EFI_LOAD_OPTION). Description, DiskGUID and Path must be set. Attributes of the boot entry (EFI_LOAD_OPTION.Attributes, not the same as attributes of an EFI variable) are always set to LOAD_OPTION_ACTIVE.

type BootOrder

type BootOrder []uint16

BootOrder represents the contents of the BootOrder EFI variable.

func ReadBootOrder

func ReadBootOrder() (*BootOrder, error)

ReadBootOrder reads the EFI boot order variable.

func UnmarshalBootOrder

func UnmarshalBootOrder(d []byte) (*BootOrder, error)

UnmarshalBootOrder loads a BootOrder from its binary representation.

func (*BootOrder) Marhsal

func (t *BootOrder) Marhsal() []byte

Marhsal generates the binary representation of a BootOrder.

type Update

type Update struct {
	Write map[uint16]BootEntry // Create or update these variables
	Order BootOrder            // Set BootOrder to this
}

Update specifies a set of modifications to EFI boot variables.

func PlanUpdate

func PlanUpdate(oldOrd BootOrder, oldEntries map[uint16]BootEntry, newEntry BootEntry) (*Update, error)

PlanUpdate creates or updates the softmetal boot entry to match newEntry and adjusts the boot order to have that entry load first. PlanUpdate does not write any EFI variables itself. The newEntry argument should be a fully configured boot entry with an empty description. If PlanUpdate plans to create a new boot entry, it uses the lowest free ID (Update.Write key). Only the Description field is required in the supplied boot entries (oldEntries). PlanUpdate recognizes the softmetal boot entry by description only. If there are multiple softmetal boot entries, PlanUpdate will fail.

Jump to

Keyboard shortcuts

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