grub

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package grub provides the interface to the GRUB bootloader: config management, installation, etc.

Package grub provides the interface to the GRUB bootloader: config management, installation, etc.

Package grub provides the interface to the GRUB bootloader: config management, installation, etc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Quote added in v1.4.0

func Quote(s string) string

Quote according to (incomplete) GRUB quoting rules.

See https://www.gnu.org/software/grub/manual/grub/html_node/Shell_002dlike-scripting.html

func Unquote added in v1.4.0

func Unquote(s string) string

Unquote according to (incomplete) GRUB quoting rules.

Types

type BootLabel

type BootLabel string

BootLabel represents a boot label, e.g. A or B.

const (
	// ConfigPath is the path to the grub config.
	ConfigPath = constants.BootMountPoint + "/grub/grub.cfg"
	// BootA is a bootloader label.
	BootA BootLabel = "A"
	// BootB is a bootloader label.
	BootB BootLabel = "B"
	// BootReset is a bootloader label.
	BootReset BootLabel = "Reset"
)

func ParseBootLabel

func ParseBootLabel(name string) (BootLabel, error)

ParseBootLabel parses the given human-readable boot label to a BootLabel.

type Config

type Config struct {
	Default        BootLabel
	Fallback       BootLabel
	Entries        map[BootLabel]MenuEntry
	AddResetOption bool
}

Config represents a grub configuration file (grub.cfg).

func Decode

func Decode(c []byte) (*Config, error)

Decode parses the grub configuration from the given bytes.

func NewConfig

func NewConfig() *Config

NewConfig creates a new grub configuration (nothing is written to disk).

func Probe added in v1.5.0

func Probe(ctx context.Context, disk string) (*Config, error)

Probe probes a block device for GRUB bootloader.

If the 'disk' is passed, search happens on that disk only, otherwise searches all partitions.

func Read

func Read(path string) (*Config, error)

Read reads the grub configuration from the disk.

func (*Config) Encode

func (c *Config) Encode(wr io.Writer) error

Encode writes the grub configuration to the given writer.

func (*Config) Install

func (c *Config) Install(options options.InstallOptions) error

Install validates the grub configuration and writes it to the disk.

func (*Config) PreviousLabel added in v1.5.0

func (c *Config) PreviousLabel() string

PreviousLabel returns the previous bootloader label.

func (*Config) Put

func (c *Config) Put(entry BootLabel, cmdline, version string) error

Put puts a new menu entry to the grub config (nothing is written to disk).

func (*Config) Revert added in v1.5.0

func (c *Config) Revert(ctx context.Context) error

Revert reverts the bootloader to the previous version.

func (*Config) UEFIBoot added in v1.5.0

func (c *Config) UEFIBoot() bool

UEFIBoot returns true if bootloader is UEFI-only.

func (*Config) Write

func (c *Config) Write(path string, printf func(string, ...any)) error

Write the grub configuration to the given file.

type MenuEntry struct {
	Name    string
	Linux   string
	Cmdline string
	Initrd  string
}

MenuEntry represents a grub menu entry in the grub config file.

Jump to

Keyboard shortcuts

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