Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Booting process of Linux

From Wikipedia, the free encyclopedia
Multi-stage initialisation process of operating system
This articlemay be too technical for most readers to understand. Pleasehelp improve it tomake it understandable to non-experts, without removing the technical details.(August 2025) (Learn how and when to remove this message)
Linux kernel 6.1 booting onDebian Bookworm

The Linuxbooting process involves multiple stages and is in many ways similar to theBSD and otherUnix-style boot processes, from which it is derived. Although the Linux booting process depends very much on the computer architecture, those architectures share similar stages and software components,[1] including system startup,bootloader execution, loading and startup of aLinux kernel image, and execution of variousstartup scripts anddaemons.[2] Those are grouped into 4 steps: system startup, bootloader stage, kernel stage, and init process.[3]

When a Linux system is powered up or reset, its processor will execute a specific firmware/program for system initialization, such as thepower-on self-test, invoking thereset 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.[2] InIBM PC–compatiblepersonal computers (PCs), this firmware/program is either aBIOS or aUEFI monitor, and is stored in the mainboard.[2] In embedded Linux systems, this firmware/program is calledboot ROM.[4][5] After being loaded into RAM, the bootloader (also called first-stage bootloader or primary bootloader) will execute to load the second-stage bootloader[2] (also called secondary bootloader).[6] The second-stage bootloader will load the kernel image into memory, decompress and initialize it, and then pass control to this kernel image.[2] The second-stage bootloader also performs several operations on the system such as system hardware check, mounting the root device, loading the necessary kernel modules, etc.[2] Finally, the first user-space process (init process) starts, and other high-level system initializations are performed (which involve with startup scripts).[2]

For each of these stages and components, there are different variations and approaches; for example,GRUB,systemd-boot,coreboot orDas U-Boot can be used as bootloaders (historical examples areLILO,SYSLINUX orLoadlin), while the startup scripts can be either traditionalinit-style, or the system configuration can be performed through modern alternatives such assystemd orrunit.

System startup

[edit]

System startup has different steps based on the hardware that Linux is being booted on.[7]

IBM PC compatible hardware is one architecture Linux is commonly used on; on these systems, theBIOS orUEFI firmware plays an important role.

In BIOS systems, the BIOS will respectively perform power-on self test (POST), which is to check the system hardware, then enumerate local device and finally initialize the system.[7] For system initialization, BIOS will start by searching for the bootable device on the system which stores the OS. A bootable device can be storage devices like floppy disk, CD-ROM, USB flash drive, a partition on a hard disk (where a hard disk stores multiple OS, e.g Windows and Fedora), a storage device on local network, etc.[7] A hard disk to boot Linux stores theMaster Boot Record (MBR), which contains the first-stage/primary bootloader in order to be loaded into RAM.[7]

In UEFI systems, the Linux kernel can be executed directly by UEFI firmware via the EFI boot stub,[8] but usually usesGRUB 2 orsystemd-boot as a bootloader.[9][10]

IfUEFI Secure Boot is supported, a "shim" or "Preloader" is often booted by the UEFI before the bootloader or EFI-stub-bearing kernel.[11] Even ifUEFI Secure Boot is disabled this may be present and booted in case it is later enabled. It merely acts to add an extra signing key database providing keys for signature verification of subsequent boot stages without modifying the UEFI key database, and chains to the subsequent boot step the same as the UEFI would have.

The system startup stage on embedded Linux system starts by executing the firmware / program on the on-chipboot ROM, which then load bootloader / operating system from the storage device like eMMC, eUFS, NAND flash, etc.[5] The sequences of system startup are varies by processors[5] but all include hardware initialization and system hardware testing steps.[7] For example in a system with an i.MX7D processor and a bootable device which stores the OS (including U-Boot), the on-chip boot ROM sets up theDDR memory controller at first which allows the boot ROM's program to obtain the SoC configuration data from the external bootloader on the bootable device.[5] The on-chip boot ROM then loads the U-Boot into DRAM for the bootloader stage.[12]

Bootloader stage

[edit]

InIBM PC compatibles using aBIOS, the first stage bootloader, which is a part of themaster boot record (MBR), is a 512-byte image containing the vendor-specific program code and a partition table.[6] As mentioned earlier in the introduction part, the first stage bootloader will find and load the second stage bootloader.[6] It does this by searching in the partition table for an active partition.[6] After finding an active partition, first stage bootloader will keep scanning the remaining partitions in the table to ensure that they're all inactive.[6] After this step, the active partition's boot record is read into RAM and executed as the second stage bootloader.[6] The job of the second stage bootloader is to load the Linux kernel image into memory, and optional initial RAM disk.[13] Kernel image isn't an executable kernel, but a"compressed file" of the kernel instead, compressed into eitherzImage or bzImage formats withzlib.[14]

In those systems, the first- and second-stage bootloaders are usually provided by theGRand Unified Bootloader (GRUB), and formerly provided by the Linux Loader (LILO).[13]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 by the BIOS from the 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.

InUEFI systems, the stage1 and stage1.5 usually are the same UEFI application file (such as grubx64.efi forx64 UEFI systems).

Beside GRUB, there are some more popular bootloaders:

  • systemd-boot (formerly Gummiboot), a bootloader included withsystemd that requires minimal configuration (forUEFI systems only).
  • SYSLINUX/ISOLINUX is a bootloader that specializes in booting full Linux installations from FAT filesystems. It is often used for boot or rescue floppy discs,live USBs, and other lightweight boot systems. ISOLINUX is generally used by Linuxlive CDs and bootable install CDs.
  • rEFInd, aboot manager forUEFI systems.
  • coreboot is a free implementation of theUEFI orBIOS and usually deployed with thesystem board, and field upgrades provided by the vendor if need be. Parts of coreboot becomes the systems BIOS and stays resident in memory after boot.
  • Das U-Boot is a bootloader for embedded systems. It is used on systems that do not have a BIOS/UEFI but rather employ custom methods to read the bootloader into memory and execute it.

Historical bootloaders, no longer in common use, include:

  • LILO does not understand or parse filesystem layout. Instead, a configuration file (/etc/lilo.conf) is created in a live system which maps raw offset information (mapper tool) about location of kernel and ram disks (initrd or initramfs). The configuration file, which includes data such as bootpartition andkernel pathname for each, as well as customized options if needed, is then written together with bootloader code into MBR bootsector. When this bootsector is read and given control by BIOS, LILO loads the menu code and draws it then uses stored values together with user input to calculate and load the Linux kernel orchain-load any otherboot-loader.
  • GRUB 1 includes logic to read common file systems at run-time in order to access its configuration file.[15] This gives GRUB 1 ability to read its configuration file from the filesystem rather than have it embedded into the MBR, which allows it to change the configuration at run-time and specify disks and partitions in a human-readable format rather than relying on offsets. It also contains acommand-line interface, which makes it easier to fix or modify GRUB if it is misconfigured or corrupt.[16]
  • Loadlin is a bootloader that can replace a runningDOS orWindows 9x kernel with the Linux kernel at run time. This can be useful in the case of hardware that needs to be switched on via software and for which such configuration programs are proprietary and only available for DOS. This booting method is less necessary nowadays, as Linux has drivers for a multitude of hardware devices, but it has seen some use inmobile devices. Another use case is when the Linux is located on a storage device which is not available to the BIOS for booting: DOS or Windows can load the appropriate drivers to make up for the BIOS limitation and boot Linux from there.

Kernel

[edit]

The kernel stage occurs after the bootloader stage. TheLinux kernel handles all operating system processes, such asmemory management, taskscheduling,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.[14] The kernel image is self-decompressed, which is a part of the kernel image's routine.[14] For some platforms (like ARM 64-bit), kernel decompression has to be performed by the bootloader instead, like U-Boot.[17]

For details of those steps, take an example withi386 microprocessor. When its bzImage is invoked, functionstart() (of./arch/i386/boot/head.S) is called to do some basic hardware setup then callsstartup_32() (located in./arch/i386/boot/compressed/head.S).[14]startup_32()will do basic setup to environment (stack, etc.), clears theBlock Started by Symbol (BSS) then invokesdecompress_kernel() (located in./arch/i386/boot/compressed/misc.c) to decompress the kernel.[14] Kernel startup is then executed via a differentstartup_32() function located in./arch/i386/kernel/head.S.[14] The startup functionstartup_32() for the kernel (also called the swapper or process 0) establishesmemory management (paging tables and memory paging), detects the type ofCPU and any additional functionality such asfloating point capabilities, and then switches to non-architecture specific Linux kernel functionality via a call tostart_kernel() located in./init/main.c.[14]

start_kernel()executes a wide range of initialization functions. It sets upinterrupt handling (IRQs), further configures memory, mounts theinitial RAM disk ("initrd") that was loaded previously as the temporary root file system during the bootloader stage.[14] 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).[14] initrd usually contains the necessary modules needed to interface with storage peripherals,[14] e.g SATA driver, and support a large number of possible hardware configurations.[14] This split of some drivers statically compiled into the kernel and other drivers loaded from initrd allows for a smaller kernel.[14]initramfs, also known as early user space, has been available since version 2.5.46 of the Linux kernel,[18] 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 whatdevice drivers are needed to load the main user space file system and load them from atemporary filesystem. Many distributions usedracut to generate and maintain the initramfs image.

The root file system is later switched via a call topivot_root() which unmounts the temporary root file system and replaces it with the use of the real one, once the latter is accessible.[14] The memory used by the temporary root file system is then reclaimed.[clarification needed]

Finally,kernel_thread (inarch/i386/kernel/process.c) is called to start the Init process (the first user-space process), and then starts the idle task viacpu_idle().[14]

Thus, the kernel stage initializes devices, mounts the root filesystem specified by the bootloader asread only, and runsInit (/sbin/init) which is designated as the first process run by the system (PID = 1).[19] A message is printed by the kernel upon mounting the file system, and by Init upon starting the Init process.[19]

According toRed Hat, the detailed kernel process at this stage is therefore summarized as follows:[15]

"When the kernel is loaded, it immediately initializes and configures the computer's memory and configures the various hardware attached to the system, including all processors, I/O subsystems, and storage devices. It then looks for the compressed initrd image in a predetermined location in memory, decompresses it, mounts it, and loads all necessary drivers. Next, it initializes virtual devices related to the file system, such asLVM or softwareRAID before unmounting the initrddisk image and freeing up all the memory the disk image once occupied. The kernel then creates a root device,[clarification needed] mounts the root partition read-only, and frees any unused memory. At this point, the kernel is loaded into memory and operational. However, since there are no user applications that allow meaningful input to the system, not much can be done with it." An initramfs-style boot is similar, but not identical to the described initrd boot.

At this point, with interrupts enabled, the scheduler can take control of the overall management of the system, to provide pre-emptive multi-tasking, and the init process is left to continue booting the user environment in user space.

Init process

[edit]

Once the kernel has started, it starts theinit process,[20] adaemon which thenbootstraps theuser space, for example by checking and mountingfile systems, and starting up otherprocesses. The init system is the first daemon to start (during booting) and the last daemon to terminate (duringshutdown).

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 assystemd. Below is a summary of the main init processes:

  • SysV init (a.k.a. simply "init") is similar to the init process ofUNIX System V. In a standard Linux system, init is executed with a parameter, known as arunlevel, which takes a value from 0 to 6 and determines which subsystems are made operational. Each runlevel has its ownscripts which codify the various processes involved in setting up or leaving the given runlevel, and it is these scripts which are referenced as necessary in the boot process. Init scripts are typically held in directories with names such as"/etc/rc...". The top level configuration file for init is at/etc/inittab.[21] During system boot, it checks whether a default runlevel is specified in /etc/inittab, and requests the runlevel to enter via thesystem console if not. It then proceeds to run all the relevant boot scripts for the given runlevel, including loadingmodules, checking the integrity of the root file system (which was mounted read-only) and then remounting it for full read-write access, and sets up thenetwork.[19] After it has spawned all of the processes specified, init goes dormant, and waits for one of three events to happen: processes that started to end or die, a power failure signal,[clarification needed] or a request via/sbin/telinit to further change the runlevel.[22]
  • systemd is a modern alternative to SysV init. Like init, systemd is a daemon that manages other daemons. All daemons, including systemd, arebackground processes.Lennart Poettering andKay Sievers, software engineers that initially developed systemd,[23] sought to surpass the efficiency of the init daemon in several ways. They wanted to improve the software framework for expressing dependencies, to allow more processing to be done inparallel during system booting, and to reduce thecomputational overhead of theshell. Systemd's initialization instructions for each daemon are recorded in a declarative configuration file rather than a shell script. Forinter-process communication, systemd makesUnix domain sockets andD-Bus available to the running daemons. Systemd is also capable of aggressive parallelization.

See also

[edit]

References

[edit]
  1. ^M. Tim Jones 2006, "Introduction", "The process of booting a Linux® system consists of a number of stages. But whether you're booting a standard x86 desktop or a deeply embedded PowerPC® target, much of the flow is surprisingly similar."
  2. ^abcdefgM. Tim Jones 2006, "Overview", "Figure 1. The 20,000-foot view of the Linux boot process"
  3. ^M. Tim Jones 2006, "Linux booting process are grouped into 4 stages, based on IBM source"
  4. ^Bin, Niu; Dejian, Li; Zhangjian, LU; Lixin, Yang; Zhihua, Bai; Longlong, He; Sheng, Liu (August 2020).Research and design of Bootrom supporting secure boot mode. 2020 International Symposium on Computer Engineering and Intelligent Communications (ISCEIC). pp. 5–8.doi:10.1109/ISCEIC51027.2020.00009.ISBN 978-1-7281-8171-4.S2CID 231714880.
  5. ^abcdAlberto Liberal De Los Ríos 2017, p. 28, "Linux Boot Process".
  6. ^abcdefM. Tim Jones 2006, "Stage 1 boot loader".
  7. ^abcdeM. Tim Jones 2006, "System startup".
  8. ^"EFI stub kernel - Gentoo Wiki".wiki.gentoo.org. Retrieved2020-11-02.
  9. ^Kinney, Michael (1 September 2000)."Solving BIOS Boot Issues with EFI"(PDF). pp. 47–50. Archived fromthe original(PDF) on 23 January 2007. Retrieved14 September 2010.
  10. ^"MS denies secure boot will exclude Linux". The Register. 23 September 2011. Retrieved24 September 2011.
  11. ^"Using a Signed Bootloader - Arch Wiki".wiki.archlinux.org. Retrieved2024-12-05.
  12. ^Alberto Liberal De Los Ríos 2017, p. 29, "Linux Boot Process".
  13. ^abM. Tim Jones 2006, "Stage 2 boot loader".
  14. ^abcdefghijklmnM. Tim Jones 2006, "Kernel".
  15. ^ab"Product Documentation". Redhat.com. 2013-09-30. Archived fromthe original on 2008-08-30. Retrieved2014-01-22.
  16. ^"Product Documentation". Redhat.com. 2013-09-30. Retrieved2014-01-22.
  17. ^Alberto Liberal De Los Ríos 2017, p. 20, "Bootloader".
  18. ^Corbet, Jonathan (6 November 2002)."Initramfs arrives". Retrieved14 November 2011.
  19. ^abchttp://oldfield.wattle.id.au/luv/boot.html Linux Boot Process - by Kim Oldfield (2001)
  20. ^M. Tim Jones 2006, "Init".
  21. ^"From Power Up To Bash Prompt: Init".users.cecs.anu.edu.au.
  22. ^"init".man.he.net.
  23. ^"systemd README".freedesktop.org. Retrieved2012-09-09.

Works cited

[edit]

External links

[edit]
Organization
Kernel
Support
People
Technical
Debugging
Startup
ABIs
APIs
Kernel
System Call
Interface
In-kernel
Userspace
Daemons,
File systems
Wrapper
libraries
Components
Variants
Virtualization
Adoption
Range
of use
Adopters
Linux kernel
Controversies
Distributions
Organizations
Adoption
Media
Security
certifications
Processes
Bootingfirmware
Types
Interfaces
Implementations
Hybrid firmware bootloader
Bootloaders
Implementations
Partition layouts
Partitions
Utilities
Software
Hardware
Network boot
ROM variants
Related
Retrieved from "https://en.wikipedia.org/w/index.php?title=Booting_process_of_Linux&oldid=1338774775"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp