Difference between revisions of "How Linux Boots"

From docwiki
Jump to: navigation, search
(Stages of Booting Linux)
Line 11: Line 11:
 
# loads the first ca 300 bytes from block 0 of your hard drive
 
# loads the first ca 300 bytes from block 0 of your hard drive
 
# loads the rest of GRUB boot loader
 
# loads the rest of GRUB boot loader
# GRUB can readonly read most filesystems and load kernel (vmlinuz) and initial-ramdisk (initrd)
+
# GRUB can readonly mount most filesystems and load kernel (vmlinuz) and initial-ramdisk (initrd)
 
# kernel unpacks itself and intializes hardware
 
# kernel unpacks itself and intializes hardware
 
# kernel unpacks initial ramdisk and starts script there (e.g. /init )
 
# kernel unpacks initial ramdisk and starts script there (e.g. /init )
Line 17: Line 17:
 
# starts init process. (today usually systemd)
 
# starts init process. (today usually systemd)
 
# systemd runs boot scripts for all configured items. (e.g. ssh, X11, ..) and mounts additional filesystems, ..
 
# systemd runs boot scripts for all configured items. (e.g. ssh, X11, ..) and mounts additional filesystems, ..
  +
  +
A few notes to the above:
  +
  +
* The BIOS is specific to PCs and this looks different on other hardware. E.g. Raspberry Pi and other ARM systems, etc..
  +
* The initial boot blocks can also be loaded via network (PXE network boot).
  +
* you can also directly boot a kernel without an initial ram-disk but that means that the kernel needs to have all necessary drives compiled in that are needed for at least reading the harddisk.
  +
* systemd is still a bit controversial and there are distributions out there that try to avoid it. e.g. devuan.

Revision as of 14:46, 29 October 2020

Motivation

Nothing is more frustrating then not being able to boot into your system. If it hangs a boot with a cryptic message, then what do you do? People running other Operating Systems then tend to try to re-install their OS at this point. Once you know how Linux boots then it is almost always possible to boot into your system again as long as your hard-drive is not damaged.

Stages of Booting Linux

Simplified:

  1. your PC boots (BIOS from EEPROM chips on your motherboard. e.g when you press F12 during boot this is handled by the BIOS)
  2. loads the first ca 300 bytes from block 0 of your hard drive
  3. loads the rest of GRUB boot loader
  4. GRUB can readonly mount most filesystems and load kernel (vmlinuz) and initial-ramdisk (initrd)
  5. kernel unpacks itself and intializes hardware
  6. kernel unpacks initial ramdisk and starts script there (e.g. /init )
  7. initial ramdisk scripts loads additional modules and mount real /
  8. starts init process. (today usually systemd)
  9. systemd runs boot scripts for all configured items. (e.g. ssh, X11, ..) and mounts additional filesystems, ..

A few notes to the above:

  • The BIOS is specific to PCs and this looks different on other hardware. E.g. Raspberry Pi and other ARM systems, etc..
  • The initial boot blocks can also be loaded via network (PXE network boot).
  • you can also directly boot a kernel without an initial ram-disk but that means that the kernel needs to have all necessary drives compiled in that are needed for at least reading the harddisk.
  • systemd is still a bit controversial and there are distributions out there that try to avoid it. e.g. devuan.