GRUB, ancient and modern
GRUB Legacy • Of course originally just GRUB • Started in 1995 by Erich Boleyn • Multiboot • Editable menus, reasonable FS interface • BALGE
Multiboot https://xkcd.com/927/
GRUB Legacy: stages • Stage 1: MBR, just reads first sector of Stage 1.5 and jumps to it • Stage 1.5: enough file system code to read Stage 2 from an ordinary file system • Stage 2: rest of loader, e.g. Linux boot code
GRUB Legacy: problems • Ad-hoc FS abstraction, multiple stage1.5s • Not much other abstraction worth mentioning • Difficult to extend safely • Lots of PC/BIOS assumptions • Divergence
GRUB 2 rewrite
New design • Small kernel, almost everything in modules • grub-install detects modules needed to read /boot/grub/ and builds a core image • Heavy use of abstraction layers; highly composable • Userspace tools built from same code • 10 kLoC asm, 250 kLoC C (excluding libgcrypt) – Includes all arches; i386-pc 4.5 kLoC asm
Architecture support • x86: BIOS, UEFI, Coreboot, IEEE1275 (!), Xen • PowerPC, SPARC: IEEE1275 • IA/64: UEFI • MIPS: ARC, Yeeloong, Fuloong, Loongson • ARM: U-Boot, UEFI • ARM64: UEFI
Normal hacking routine • Hardest Legacy problems were with reading files from disk • Usually stuck with emulator + printf or (in extremis) gdb • grub-probe and grub-fstest • Spin-off benefits: grub-mount
When userspace doesn't help • bash-style interactive shell; set debug=foo • grub-mkrescue • Easy to run configuration files or even plug in new commands
Configuration • Debian update-grub → upstream, with clearer input/output separation • Now /etc/default/grub and /etc/grub.d/ • (Almost) all customisable • … but some customisation is hard
PCs suck • MBR: no formal space for boot code – Trivial loader in 446 bytes – Embed rest of brain in file system – Skate edge of (non-)spec: use boot track • Unpredictable with multiple disks
PCs suck (2) • GPT much better, but different problems • Variant MBR interpretations – Apple – boot flag on PMBR
UEFI • New big thing on PCs; bye-bye legacy BIOS • Core support basically fine • “Secure Boot” works in Ubuntu, but needs archive signing set up in Debian • Can require signed kernels without impinging on freedom once MokManager is in place • ESP layout pain
Non-x86 • powerpc/sparc basically work fine, though defaults not switched • Some mipsen work well, e.g. Yeeloong • Trend towards new architectures including GRUB port early on • Most recent port (arm64) was about 2000 lines
Debian pros/cons • Other loaders: LILO, syslinux and friends, yaboot, etc. • Some pretty good, all smaller/simpler • … but result is complexity elsewhere • Any architecture, any disk layout • Portable loader allows common boot UI across architectures and common tools
Help wanted • Mostly just me right now in Debian; BUGS • Everyone's boot problem is critical for them • Overhaul configuration • MBR robustness • Rest of UEFI • Xen • Take better advantage of ports
Discussion Colin Watson <cjwatson@debian.org>
Recommend
More recommend