Skip to content

About

Reader and resolver for GRUB boot configuration (grub.cfg, /etc/default/grub, grubenv)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

lamboot-reader

CI License: MIT OR Apache-2.0

A reader and resolver for GRUB boot configuration on Linux hosts: grub.cfg, /etc/default/grub, and grubenv. It answers "which entry would GRUB boot, with what cmdline?" and detects drift between the generated menu and the operator config.

Status: Proxmox-focused today. It's validated against PVE's grub-mkconfig output and best-effort elsewhere. See ROADMAP.md for the path to a universal, cross-distro boot-entry reader (grub.cfg + BLS + systemd-boot).

What it parses

File Module Public entry
/boot/grub/grub.cfg parser parse_grub_cfg
/etc/default/grub default_grub parse_default_grub
/boot/grub/grubenv grubenv parse_grubenv

What it answers

  • "Which menuentry would GRUB boot right now?" resolve_default ties all three inputs together and applies GRUB's own selection rules: next_entry one-shot wins; then GRUB_DEFAULT=saved routes through grubenv; then numeric index or literal id; else fall back to entry 0.
  • "Is the kernel cmdline in grub.cfg consistent with what /etc/default/grub declares?" compare_cmdline reports drift in both directions, ignoring root= and ro/rw which update-grub injects from the live mount table rather than GRUB_CMDLINE_*.
  • "What kernels does GRUB know about?" GrubCfg::kernel_versions and GrubCfg::entry_by_kernel_version give the install tool a stable view of the boot menu independent of menu numbering.

CLI

lamboot-reader ships with the crate. Subcommands all accept --json for machine-readable output and default to the standard Proxmox/Debian paths (/boot/grub/grub.cfg, /etc/default/grub, /boot/grub/grubenv):

lamboot-reader list-kernels        # enumerate all menuentries
lamboot-reader default             # show the entry GRUB would boot
lamboot-reader cmdline             # cmdline of the default entry
lamboot-reader cmdline --kernel 6.17.13-11-pve
lamboot-reader compare-cmdline     # drift detection; exits 2 on drift
lamboot-reader parse-default-grub  # GRUB_CMDLINE_*, GRUB_DEFAULT, ...
lamboot-reader grubenv             # saved_entry, next_entry, recordfail

Exit codes: 0 success, 1 input error, 2 operation found drift (for compare-cmdline), 3 internal error.

Scope

Proxmox-focused. The parser handles the canonical Proxmox VE grub-mkconfig output (one top-level menuentry, one "Advanced options" submenu of per-kernel + recovery entries, plus the 20_memtest86+ and 30_uefi-firmware entries) but does not implement the full GRUB config language. Specifically:

  • linux / linuxefi and initrd / initrdefi are accepted as synonyms.
  • submenu blocks recurse; nested submenus would also work.
  • set <var>=<value> at top level populates GrubCfg::variables.
  • configfile, multiboot{,2}, module{,2}, devicetree directives surface as GrubCfgError::Unsupported. They signal a config shape the parser doesn't handle yet, and the operator should know.
  • Unknown directives (load_video, insmod, search, echo, …) are silently skipped.

The fixtures in tests/fixtures/ are written for the tests, in the shape of a Proxmox VE host's files, and they're the canonical statement of what's supported. To cover another distribution, write a fixture in the shape of its grub.cfg and add a test case to src/parser.rs. Don't copy a generated grub.cfg or a stock /etc/default/grub: Both carry GNU GRUB's text, which is GPL-3.0-or-later, and this crate is MIT OR Apache-2.0.

License

Licensed under either of MIT (LICENSE-MIT) or Apache-2.0 (LICENSE-APACHE) at your option.

About

Reader and resolver for GRUB boot configuration (grub.cfg, /etc/default/grub, grubenv)

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages