Content deleted Content added
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation) |
→Bootloader stage: The MBR boot sector (MBR boot code) is only used on x86 BIOS systems. However, the MBR partition table can be used on modern UEFI PCs, as well as non-x86 embedded devices (while the boot loader is not MBR boot sector). Tags: Mobile edit Mobile web edit |
||
(12 intermediate revisions by 9 users not shown) | |||
Line 1:
{{Short description|Multi-stage initialisation process of operating system}}
{{Technical|date=August 2025}}
The Linux [[booting]] process involves multiple stages and is in many ways similar to the [[BSD]] and other [[Unix]]-style boot processes, from which it
When a Linux system is powered up or reset, its processor will execute a specific firmware/program for system initialization, such as the [[power-on self-test]], invoking the [[reset vector]] to start a program at a known address in flash/ROM (in embedded Linux devices), then load the bootloader into RAM for later execution.{{Sfn|M. Tim Jones|2006|ps=, "Figure 1. The 20,000-foot view of the Linux boot process"|loc="Overview"}} In [[IBM PC–compatible]] [[personal computers]] (PCs), this firmware/program is either a [[BIOS]] or a [[UEFI]] monitor, and is stored in the mainboard.{{Sfn|M. Tim Jones|2006|ps=, "Figure 1. The 20,000-foot view of the Linux boot process"|loc="Overview"}} In embedded Linux systems, this firmware/program is called [[boot ROM]].<ref>{{Cite book |last1=Bin |first1=Niu |title=2020 International Symposium on Computer Engineering and Intelligent Communications (ISCEIC) |last2=Dejian |first2=Li |last3=Zhangjian |first3=LU |last4=Lixin |first4=Yang |last5=Zhihua |first5=Bai |last6=Longlong |first6=He |last7=Sheng |first7=Liu |date=August 2020 |isbn=978-1-7281-8171-4 |pages=5–8 |chapter=Research and design of Bootrom supporting secure boot mode |doi=10.1109/ISCEIC51027.2020.00009
For each of these stages and components, there are different variations and approaches; for example, [[GNU GRUB|GRUB]], [[systemd-boot]], [[coreboot]] or [[Das U-Boot]] can be used as bootloaders (historical examples are [[LILO (boot loader)|LILO]], [[SYSLINUX]] or [[Loadlin]]), while the startup scripts can be either traditional [[init]]-style, or the system configuration can be performed through modern alternatives such as [[systemd]] or [[Upstart (software)|Upstart]].
Line 20 ⟶ 21:
== Bootloader stage ==
In x86 PC, first- and second-stage bootloaders are combined into the [[GNU GRUB|GRand Unified Bootloader]] (GRUB), and formerly Linux Loader ([[LILO (bootloader)|LILO]]).{{Sfn|M. Tim Jones|2006|loc=, "Stage 2 boot loader"}} [[GRUB 2]], which is now used, differs from GRUB 1 by being capable of automatic detection of various operating systems and automatic configuration. The stage1 is loaded and executed either by the [[BIOS]] from the [[Master boot record]] (MBR). The intermediate stage loader (stage1.5, usually core.img) is loaded and executed by the stage1 loader. The second-stage loader (stage2, the /boot/grub/ files) is loaded by the stage1.5 and displays the GRUB startup menu that allows the user to choose an operating system or examine and edit startup parameters. After a menu entry is chosen and optional parameters are given, GRUB loads the linux kernel into memory and passes control to it. GRUB 2 is also capable of chain-loading of another bootloader. In [[UEFI]] systems, the stage1 and stage1.5 usually are the same UEFI application file (such as grubx64.efi for [[x64]] UEFI systems).
Line 38 ⟶ 39:
== Kernel ==
The kernel stage occurs after the bootloader stage. The [[Linux kernel]] handles all operating system processes, such as [[memory management]], task [[scheduling (computing)|scheduling]], [[I/O]], [[interprocess communication]], and overall system control. This is loaded in two stages – in the first stage, the kernel (as a compressed image file) is loaded into memory and decompressed, and a few fundamental functions are set up such as basic memory management, minimal amount of hardware setup.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}}
For details of those steps, take an example with [[i386]] microprocessor. When its bzImage is invoked, function <code>start()</code> (of <code>./arch/i386/boot/head.S</code>) is called to do some basic hardware setup then calls <code>startup_32()</code> (located in <code>./arch/i386/boot/compressed/head.S</code>).{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} <code>startup_32()</code>will do basic setup to environment (stack, etc.), clears the [[.bss|Block Started by Symbol]] (BSS) then invokes <code>decompress_kernel()</code> (located in <code>./arch/i386/boot/compressed/misc.c</code>) to decompress the kernel.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} Kernel startup is then executed via a different <code>startup_32()</code> function located in <code>./arch/i386/kernel/head.S</code>.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} The startup function <code>startup_32()</code> for the kernel (also called the swapper or process 0) establishes [[memory management]] (paging tables and memory paging), detects the type of [[Central processing unit|CPU]] and any additional functionality such as [[floating point]] capabilities, and then switches to non-architecture specific Linux kernel functionality via a call to <code>start_kernel()</code> located in <code>./init/main.c</code>.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}}
{{Anchor|Early user space}}<code>start_kernel()</code>executes a wide range of initialization functions. It sets up [[interrupt handling]] ([[Interrupt request|IRQ]]s), further configures memory, mounts the [[initrd|initial RAM disk]] ("initrd") that was loaded previously as the temporary root file system during the bootloader stage.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} The initrd, which acts as a temporary root filesystem in RAM, allows the kernel to be fully booted and driver modules to be loaded directly from memory, without reliance upon other devices (e.g. a hard disk).{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} initrd contains the necessary modules needed to interface with peripherals,{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} e.g SATA driver, and support a large number of possible hardware configurations.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} This split of some drivers statically compiled into the kernel and other drivers loaded from initrd allows for a smaller kernel.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} [[initramfs]], also known as early user space, has been available since version 2.5.46 of the Linux kernel,<ref>{{cite web |last1=Corbet |first1=Jonathan |title=Initramfs arrives |date=6 November 2002 |url=https://lwn.net/Articles/14776/ |access-date=14 November 2011}}</ref> with the intent to replace as many functions as possible that previously the kernel would have performed during the startup process. Typical uses of early user space are to detect what [[device driver]]s are needed to load the main user space file system and load them from a [[temporary filesystem]]. Many distributions use [[dracut (software)|dracut]] to generate and maintain the initramfs image.
The root file system is later switched via a call to <code>pivot_root()</code> which unmounts the temporary root file system and replaces it with the use of the real one, once the latter is accessible.{{Sfn|M. Tim Jones|2006|loc=, "Kernel"}} The memory used by the temporary root file system is then reclaimed.{{Clarify|date=March 2010}}
Line 56 ⟶ 57:
== Init process ==
Once the kernel has started, it starts the [[init]] process,{{Sfn|M. Tim Jones|2006|loc=, "Init"}} a [[Daemon (computing)|daemon]] which then [[Bootstrapping#Software loading and execution|bootstraps]] the [[user space]], for example by checking and mounting [[file system]]s, and starting up other [[Process (computing)|processes]]. The init system is the first daemon to start (during booting) and the last daemon to terminate (during [[Shutdown (computing)|shutdown]]).
Historically this was the "SysV init", which was just called "init". More recent Linux distributions are likely to use one of the more modern alternatives such as [[systemd]]. Below is a summary of the main init processes:
Line 67 ⟶ 68:
{{Portal|Linux}}
* [[SYSLINUX]]
* [[Booting process of Android devices]]
* [[Booting process of macOS]]
* [[Booting process of Windows]]
|