It would be really great if someone can confirm that the below steps are correct. I would like to know the exact correct steps.
Power ON the computer.
Basic I/O system (BIOS/UEFI). The first program that is executed which stored in ROM on the motherboard of the PC.
- Firmware (BIOS/UEFI): A program that informs a device’s processor how to begin the startup process is considered firmware.
- Firmware is installed directly onto a piece of hardware during manufacturing.
- Computers, mobile phones, and tablets rely on firmware like BIOS and EFI to load their operating systems.
perform POST (power-on self-test) to verify the H/W components are in working condition.
Look for a bootable device. If found then handover CONTROL to the first sector of the device i.e. MBR
Master Boot Record (MBR). 512 bytes, the first sector of any bootable device contains machine code instructions to boot a machine. it has the following info:
- Boot loader info (446 bytes) — a small low-level code that points to a boot loader [where is the boot loader located?] /boot/grub2/grub.cfg
- Partition table info (64 bytes) [where is the OS located in the filesystem?]
- Error checking (2 bytes)
- it will load the boot loader (GRUB2) into memory and handover CONTROL to it.
GRand Unified Bootloader (GRUB2)
- It's a program that loads the OS. It used to fit in MBR (446 bytes) but since the size is increasing the complexity of OS is increasing. It's not a single program, it allows the filesystem to be interpreted properly.
- Loaded from /boot/grub2/grub.cfg into memory by MBR at boot time
- user can see GUI asking to select different OS or kernels to boot from.
- once selected the kernel, it locates the corresponding kernel executable.
- main job is to load kernel and initramfs [initramfs-4.18.0–408.el8.x86_64.img] into memory.
- once the kernel is loaded into RAM, it passes CONTROL to it.
- Once the Linux kernel has control over the system (which it gets after being loaded by the boot loader), it prepares its memory structures and drivers (initializes hardware). The kernel is booting.
- we can see a lot of messages, that can be suppressed through RHGB & quiet. [To enable messaging modify the parameter GRUB_CMDLINE_LINUX in /etc/default/grub; then run #grub2-mkconfig > /boot/grub2/grub.cfg and reboot]
- Some Linux-based computer systems require an initramfs to boot properly. If present, then the kernel will execute /init script from the initramfs.
- Systems with exotic drivers or setups, or encrypted file systems need initramfs so the Linux kernel is capable of handing over control to the init binary on their system.
- An initramfs is an initial ram file system based on tmpfs. It provides early userspace which can do things that kernel can’t do during boot time.
- It contains the tools and scripts needed to mount the file systems before the init binary on the real root file system is called.
- These tools can be decryption abstraction layers (for encrypted file systems), logical volume managers, software raid, bluetooth driver based file system loaders, etc.
- At boot time, the kernel checks for the presence of the initramfs or the boot loader informs the Linux kernel that an initramfs is loaded.
- If found, the Linux kernel will create a tmpfs file system, extract the contents of the archive on it, and then launch the /init script located in the root of the tmpfs file system.
- [An initramfs contains at least one file called /init. This file is executed by the kernel as the main init process (PID 1). It has to do all the work.] ref-7
- This script then mounts the real root file system under /sysroot (after making sure it can mount it, for instance by loading additional modules, preparing an encryption abstraction layer, etc.) as well as vital other file systems (such as /usr and /var ).
- Once the root file system and the other vital file systems are mounted, the init script from the initramfs will switch the root towards the real root file system (remember it is switch_root operation NOT pivot_root).
- [switch_root operation is to switch /sysroot into a real root filesystem, start executing stuff from there and then remove the initramfs from memory.]
- finally call the /sbin/init (init -> /usr/lib/systemd/systemd) binary on that system’s real root filesystem as the main init process (PID 1 — inherited from initramfs /init, see exec details) to continue the boot process.
- First service loaded with PID 1
- mounting the filesystem from /etc/fstab.
- start all required services and processes in parallel.
- it starts looking for the file for the required dependencies to boot into the default target.
- once the default target is up and the user can see the login prompt then we can say the system boot-up is successful.
1. https://opensource.com/article/20/5/systemd-startup 2. https://opensource.com/article/20/5/systemd-units 3. https://opensource.com/article/20/4/systemd 4. https://www.quora.com/What-is-chroot-Sysroot 5. https://blog.csdn.net/flynetcn/article/details/131828832 6. https://www.linfo.org/vmlinuz.html 7. https://wiki.gentoo.org/wiki/Custom_Initramfs 8. https://www.linuxfromscratch.org/blfs/view/svn/postlfs/initramfs.html 9. https://www.quora.com/What-exactly-is-the-initramfs-program-in-Linux-Is-it-a-script-binary-or-what 10. https://wiki.gentoo.org/wiki/Initramfs/Guide 11. https://wiki.ubuntu.com/Initramfs 12. https://www.youtube.com/watch?v=saovaEhA85g 13. https://www.youtube.com/watch?v=sOIOY6Ks0xA&t=423s 14. https://sourcemage.org/HowTo/initramfs 15. https://web.archive.org/web/20160730094856/http://wiki.sourcemage.org/HowTo(2f)Initramfs.html 16. https://tiebing.blogspot.com/2014/02/linux-switchroot-vs-pivotroot-vs-chroot.html 17. https://unix.stackexchange.com/questions/126217/when-would-you-use-pivot-root-over-switch-root 18. https://linux.die.net/man/8/pivot_root 19. https://linux.die.net/man/8/switch_root 20. https://en.wikipedia.org/wiki/Exec_(system_call) 21. https://www.baeldung.com/linux/exec-command-in-shell-script 22. https://eng.libretexts.org/Bookshelves/Computer_Science/Operating_Systems/Linux_-_The_Penguin_Marches_On_(McClanahan)/13%3A_Working_with_Bash_Scripts/3.09%3A_Positional_Parameters_exec_Command_source_Command#:~:text=The%20exec%20command%20in%20Linux,return%20to%20the%20calling%20process. 23. https://en.wikipedia.org/wiki/Overlay_(programming) 24. https://superuser.com/questions/782008/linux-boot-time-scrolling-messages 25. https://itnixpro.com/how-to-view-linux-boot-messages-using-dmesg-command/?utm_content=cmp-true 26. https://linux-audit.com/finding-boot-logs-in-systemd-journals/ 27. https://www.loggly.com/ultimate-guide/using-journalctl/