DebConf9/Boot loaders
Two part presentation for DebConf9.
First part is about the booting sequence (from hardware to initial user space) and the second part is more detailed about boot loaders (LILO, GRUB, GRUB2 and syslinux/extlinux). We restrict only to PC (x86) machines, thus with limited BIOS boot support.
Contents |
[edit] Booting sequence
[edit] Hardware and BIOS
- power on, wait circuits has enough electricity
- CPU reset signal:
- self CPU test
- CPU in 8086 compatility mode (segments, memory layout, memory limits, no memory protection)
- CPU jump in F000:FFF0 (mepped to BIOS)
- run motherboard BIOS
- initialize hardware
- test of hardware (POST)
- Initialized some tables (ACPI, PNP, ...) according BIOS configuration
- (ev. jump to BIOS configuration)
- run devices BIOS (if required)
- video
- net
[edit] OS boot
main BIOS / net BIOS:
- try network boot
- check a valid media with a valid boot sector (ends with 55 AA) (following priorities in BIOS configuration)
- load first sector (512 bytes) in 0000:7C00 of such device
- run the code in 0000:7C00
Note: BIOS will simulates CDROM, USB, etc. as first harddisk (disk 0x80), to simplify boot sector coding (nearly 500 bytes)
[edit] Old methods (PC-DOS)
Two types of "boot sectors", all end with 0xAA55 flag.
- MBR: find first active partition (4 partition in MBR), load the first sector of that partition, run it (DOS or a MBR like record for extended partitions)
- boot sector:
- setup BIOS floppy parameters (more timeouts)
- scan root directory of FATx
- load the OS (IO.SYS) and run it
- Note: read-only, file must be contiguous (thus with system flag), no need to worry about FAT tables, sizes, etc. Anyway few kBs of OS code
[edit] Linux boot without boot loaders
Similar to above:
- first 512 bytes are the boot loader
- boot signature still exists: od -x -A x -j 0x1fe -N 2 /boot/vmlinuz
- but not working since a lot of time!
- rdev command (in util-linux) to change kernel "parameters" (but only for next boot)
[edit] Linux boot loaders
Boot loaders are small "OS" (but they don't use own partition):
- provide interface to choose linux kernels
- provide interface to setup linux parameters (and initial environment variables)
- allow to load an other initramfs initial root system (optional)
- allow to load and run other OS boot sectors in the usual old way
Additionally:
- load the entire kernel (not only the boot sector), leaving the old real mode (limited to <640kb)
- put parameters in the right place (according linux boot protocol)
- run it (kernel will auto-decompress, so more memory it is needs)
Usually they are done as multistage loaders:
- first stage: load the second stage (with 510 bytes code and data limit)
- second stage: full featured boot loader
[edit] run linux kernel
- now they are big > 1MB
- usual kernel entry point: protected mode, A20-line enabled, interrupts disabled, ...
- kernel auto-decompress (gzip, bzip2, lzma)
- initialize kernel, drivers and devices
- kernel mount root partition (root, ro/rw parameters)
- the root partition could be an attached initramfs partition
- run /sbin/init -> start boot process
- See: THE LINUX/x86 BOOT PROTOCOL in Documentation/x86/boot.txt
- Note: Linux boot protocol has assigned the following boot loaders:
- 0 LILO
- 1 Loadlin (load linux from old DOS/Windows)
- 2 bootsect-loader
- 3 SYSLINUX (ISOLINUX, EXTLINUX, etc.)
- 4 EtherBoot (PXE)
- 5 ELILO (LILO for EFI)
- 7 GRUB
- 8 U-BOOT (the Universal Boot Loader, support: PPC, ARM, MIPS, x86, m68k, NIOS, Microblaze)
- 9 Xen
- A Gujin
- B Qemu
[edit] Run initramfs (optional)
Run iniramfs boot sequence:
- find and load root partition LVM, RAID, NFS, etc (and combined)
- allow to do this loading modules (thus keeping kernel size small)
then pivot root to new root partition and execute init (on the new root partition)
[edit] Run init
- scan inittab
- run /etc/init.d/rc.S (defined in inittab), do the system initialisation
[edit] boot loaders
[edit] Package informations
lilo
- first linux boot loader
- debian version: 1:22.8-7 (William Pitcock, Matt Arnold)
- upstream: original upstream Werner Almesberger (1992-1998), now 404 upstream page
- 2.8: Feb 2007
- License: BSD 3 clauses
GNU grub 1 (grub1 / grub-legacy)
- not only for linux, not only for PC
- Debian version: 0.97-55 (Grub Maintainers, Robert Millan, Felix Zielcke)
- upstream: ftp://alpha.gnu.org/gnu/grub/ unsupported, must use grub2
- 0.97: Mai 2005 (activity on svn)
- License: GPL (v2 only)
GNU grub 2 (grub2 / grub-pc)
- GRUB done again (but like LILO)
- Debian version: 1.96+20090721-4 (GRUB Maintainers, Robert Millan, Felix Zielcke, Jordi Mallach)
- upstream: http://www.gnu.org/software/grub/grub-2.en.html (quiet developement?)
- 1.96: Feb 2008 (recent activity on svn)
- License: GPL 3+
syslinux: isolinux/pxelinux/extlinux
- boot cdroom and boot loader done correctly
- Debian version: 2:3.82+dfsg-1 (Daniel Baumann, Otavio Salvador)
- upstream: H. Peter Anvin http://ftp.kernel.org/pub/linux/utils/boot/syslinux/
- 3.82: Jul 2009
- License: GPL2+. Note upstream support only (and provide in sources) precompiled "boot sectors" code
[edit] Design
lilo:
- the first stage has the sector map of the second stage (LI prompt)
- the second stage has the sector maps of the kernels (LILO prompt)
- allows to have password, kernel parameters (and not a lot more)
- MTR and boot partition, can understand a lot of filesystems to construct the sector map, at linux run-time
- use:
- /etc/lilo.conf contain the list of usable kernels
- after every change of kernel written in disk admin should run /sbin/lilo
- /sbin/lilo -R alternate-kernel to load once a kernel (then it will download the default)
grub 1:
- the first stage (stage1, in MBR) loads the second stage (stage1_5, in a fixed disk location before first partition)
- the second stage (stage1_5) loads the third stage (stage2), which includes the whole GRUB code
- the third stage can read partition to look for GRUB configuration (menu.lst)
- allows to run new kernels, new devices, and some manipulation
- a lot of options at boot time
- use:
- some configuration in /etc/grub.d/ (linux run-time. Default works fine)
- real configuration in /boot/grub/menu.lst (read boot-time)
- first time grub-install (to install boot loader)
- no need to run grub after installation of new kernels
- device name are not the linux one (grub is not linux-specific, e.g. (hd0,1) -> hda2)
grub 2:
- the first stage (boot.img, in MBR) loads the second stage (core.img, in a fixed disk location before first partition)
- the second stage (core.img) can read partition to look for GRUB modules (*.mod) and GRUB configuration (grub.cfg)
- a lot of options at boot-time
- use:
- some configuration in /etc/grub.d/ (linux run-time. Default works fine)
- real configuration in /boot/grub/grub.cfg (read boot-time, created by grub-mkinstall
- update-grub (grub-mkinstall) at every new kernel installation, to add a kenrel to menu
- device name are not the linux one (grub is not linux-specific)
extlinux (syslinux for ext2/ext3 filesystems):
- the first stage has the sector map of the second stage
- the second stage will check the extlinux configuration file (e.g. /boot/extlinux/exlinug.conf) and it can load the linux kernels using the path
- scriptable interface
- use:
- create a directory in the boot partition, configure, run extlinux -i /dir will install the boot sector and the path to the configuration file
- extlinux -U dir to update kernels (optional, but on some raid configuration) on ext2/3 filesystems
[edit] requirements and problems
- basic: choose kernels, provide parameters (possibly password protected), allow initramfs (and run kernels)
- big kernel and initramfs
- run kernel once (e.g. remote testing of kernel, with panic=X)
- usable system on sysadmin error
- allow to run memtest86+
- easy to configure
- raid, LVM and complex installations
lilo:
- problems:
- unmaintained (upstream)
- doesn't handle big kernel+initramfs
- doesn't support multoboot standard (required by xen)
- remember to run lilo (or to have minimun a immutable bootable kernel)
- few archs
- advantages:
- well known
grub1:
- superseded by grub 2
grub2:
- problems:
- training for old sysadmin
- use non linux partition
- not enough safe (sometime you still need rescue CD)
- will be ever officially released?
- advantages:
- common (installed on all new system by default)
extlinux2:
- problems:
- filesystem specific (but syslinux support different filesystems)
- too much new ?
- few archs. Only for Linux? (but multiboot)
- advantages:
- powerfull scriptable environment, well know for CD installations
- maintainer (same person for boot loader and kernel booting)
[edit] Questions?
- How many boot loader we need to support? (note: there are no single boot loaders for all architectures!)
- Multiboot:
- is a rc bug of lilo
- or a bug in xen, which doesn't distribute 'linux booting immages' ?
- ???
[edit] References and links
- Linux boot protocol: linux/Documentation/x86/boot.txt
- early boot sequence and initramfs: linux/Documentation/early-userspace/
- multiboot standard: http://www.gnu.org/software/grub/manual/multiboot/multiboot.html