Skip to content

Boot

November 26, 2023
May 10, 2015

Booting - Wikiwand

POST -> BIOS/ROM code -> MBR of boot partition -> Bootloader ->
Kernel -> init/systemd ->
shell/display manager (login) -> startx/xinit -> DE

  1. CPU starts in real mode, executes instruction at 0xFFFF0
    → top of BIOS ROM
  2. self test (POST), configuration of devices (e.g. PCI
    resource allocation), initialization of BIOS extensions
    (option ROMs)
  3. load first sector of boot device ("boot sector", MBR) to
    0x7C00
    MBR relocates itself, loads first sector of active partition to
    0x7C00
  4. boot sector loads "second stage" boot loader
    a. boot loader knows how to read kernel from file system
    b. usually loads kernel to an address > 1MB and switches to
    protected mode before jumping to kernel entry point
    protected mode before jumping to kernel entry point
+--------+----------------+----------------+----------+
| Boot   | Terminology #1 | Terminology #2 | Actual   |
| stage  |                |                | program  |
| number |                |                | name     |
+--------+----------------+----------------+----------+
| 1      |  Primary       |  -             | ROM code |
|        |  Program       |                |          |
|        |  Loader        |                |          |
|        |                |                |          |
| 2      |  Secondary     |  1st stage     | u-boot   |
|        |  Program       |  bootloader    | SPL      |
|        |  Loader (SPL)  |                |          |
|        |                |                |          |
| 3      |  -             |  2nd stage     | u-boot   |
|        |                |  bootloader    |          |
|        |                |                |          |
| 4      |  -             |  -             | kernel   |
|        |                |                |          |
+--------+----------------+----------------+----------+

System Initialization (x86) - OSDev Wiki
Linux startup process - Wikipedia, the free encyclopedia
Arch boot process - ArchWiki
Inside the Linux boot process
The BIOS/MBR Boot Process
鳥哥的 Linux 私房菜 -- 第十九章、開機流程、模組管理與 Loader
如何訂製 Linux X 視窗環境 - 石頭閒語 - 樂多日誌

The Linux Boot Process (Linux+ Objective 1.1.2) - YouTube
How Computers BOOT: From Startup to Viruses - YouTube

LinuxBoot

Xv6, a simple Unix-like teaching operating system
mit-pdos/xv6-public: xv6 OS
6.1810 Operating System Engineering / Fall 2023
mit-pdos/xv6-riscv: Xv6 for RISC-V
mit-pdos/xv6-riscv-book: Text describing xv6 on RISC-V
How does an OS boot? //Source Dive// 001 - YouTube

Some basics of MBR v/s GPT and BIOS v/s UEFI - Manjaro Linux
What’s the Difference Between GPT and MBR When Partitioning a Drive?
MBR vs GPT: What's the Difference Between an MBR Partition and a GPT Partition? [Solved]
MBR: up to 2TB, 4 primary partitions
GPT (Windows): 128 partitions, bootable only with UEFI

Bootloader

Bootloader - OSDev Wiki
What is the difference between a Bootrom vs bootloader on ARM systems - Stack Overflow
linux - Why do we need a bootloader in an embedded device? - Stack Overflow

Embedded/IoT Linux for Red-Blue Teams - YouTube bootloader + kernel

SPL (secondary program loader) is needed when the static RAM cannot hold the whole bootloader and this abstract the specific hardware used form the bootloader.
what is the use of SPL (secondary program loader) - Stack Overflow

TPL: SPL loading SPL

Home · kexecboot/kexecboot Wiki Kexecboot is a nice Linux-As-a-Bootloader implementation based on kexec.

WebHome < U-Boot < DENX
Das U-Boot - Wikiwand
Introduction to the U-Boot bootloader - YouTube
Embedded Linux Booting Process (Multi-Stage Bootloaders, Kernel, Filesystem) - YouTube
Introduction — Depthcharge documentation

Lennart Talks Up systemd's SD-Boot + Boot Loader Specification - Phoronix

Source Dive - YouTube RISC-V QEmu, Kernel

initramfs

Initial ramdisk - Wikiwand
About initramfs
Arch boot process - ArchWiki

dracut (software) - Wikiwand
dracut - ArchWiki
dracut 基本介绍 - doscho - 博客园

Dracut – Discovery EndeavourOS upgrade

systemd-boot

systemd-boot - ArchWiki
systemd-boot

systemd-boot – Discovery EndeavourOS upgrade

Boot Partition

Master boot record - Wikipedia, the free encyclopedia
MBR (x86) - OSDev Wiki
GUID Partition Table - Wikipedia, the free encyclopedia
Make the most of large drives with GPT and Linux
Converting to or from GPT

FGA: What "boot" and "system" volumes are
FGA: How operating systems determine the location of the system volume when bootstrapped

BIOS

BIOS - Wikiwand
Arch boot process - ArchWiki
Boot with GRUB | Linux Journal

Flash BIOS with bare motherboard:

OpenBIOS

OpenBIOS - Wikiwand
OpenBIOS
Category:Free BIOS implementations - Wikipedia, the free encyclopedia

coreboot coreboot - Wikiwand
Libreboot project

Fixing MBR

http://support.microsoft.com/kb/927392
http://windows7themes.net/how-to-fix-mbr-in-windows-7.html
http://www.tomshardware.com/news/win7-windows-7-mbr,10036.html
http://www.sevenforums.com/general-discussion/17521-how-fix-mbr-through-command-prompt.html
http://ubuntuforums.org/showthread.php?t=1014708

Bootable USB key

Creating a bootable USB key in Linux is straight forward.

sudo dd if=${iso} of=${usb device} bs=4M
# note: the package is gddrescue
sudo ddrescue ${iso} ${usb device} --force -D

Useless Use Of dd – Vidar’s Blog
Ddrescue - GNU Project - Free Software Foundation (FSF) GNU ddrescue/gddrescue

Multiboot USB drive - ArchWiki
jsamr/bootiso: A bash script to securely create a bootable USB device from one ISO file. Just curl it, chmod it and go!
See also my iso2usb.

Note some utils modify the partition label of the ISO, that can cause problem during bootup.

Ventoy also supports Persistence Plugin, where you can define a image file for persistent storage (per ISO).

./VentoyGUI.x86_64
./Ventoy2Disk.sh -u /dev/sda

The Windows ISO cannot be dd-ed to USB flash. We must create a bootable NTFS partition then copy the contents over.

The best places to find Windows 10 ISOs | Computerworld
Download Windows USB/DVD Download Tool from Official Microsoft Download Center
ValdikSS/windows2usb: Windows 7/8/8.1/10 ISO to Flash Drive burning utility for Linux (MBR/GPT, BIOS/UEFI, FAT32/NTFS)

PXEBoot (network boot)

What Is Network Booting (PXE) and How Can You Use It?
Preboot Execution Environment - Wikiwand

Netboot.xyz

Your favorite operating systems in one place! | netboot.xyz
Meet netboot.xyz - Network Boot Any Operating System - YouTube
Meet netboot xyz - Network Boot Any Operating System | Techno Tim

UEFI

POST -> UEFI -> Boot Manager (in UEFI) ->
UEFI application (in EFI System partition) -> Bootloader -> Kernel -> ...

Unified Extensible Firmware Interface - Wikipedia, the free encyclopedia
Unified Extensible Firmware Interface - ArchWiki
Arch boot process - ArchWiki
rEFInd - ArchWiki

UEFI - OSDev Wiki
FGA: The EFI boot process.
UEFI boot: how does that actually work, then?
UEFI - Install Guide - Manjaro Linux

The Boot Loader Specification | systemd
systemd-boot
pop-os/kernelstub: A simple EFI boot manager manager for Linux
pbatard/uefi-ntfs: UEFI:NTFS - Boot NTFS partitions from UEFI

Linux on your laptop: A closer look at EFI boot options | ZDNet
Linux on your laptop: Here's what you need to know about UEFI firmware | ZDNet

http://www.rodsbooks.com/refind/installing.html
refind-efi

howtogeek.com

HTG Explains: Learn How UEFI Will Replace Your PC’s BIOS
Beginner Geek: Hard Disk Partitions Explained
What’s the Difference Between GPT and MBR When Partitioning a Drive?

rodsbooks.com

A BIOS to UEFI Transformation
Managing EFI Boot Loaders for Linux
Linux on UEFI: A Quick Installation Guide
The rEFInd Boot Manager
Managing EFI Boot Loaders for Linux: Dealing with Secure Boot

Programming for EFI

x86asm.net

Introduction to UEFI
UEFI Programming - First Steps
UEFI Hypervisors - Winning the Race to Bare Metal

Init System (pid 1)

Linux PID 1 和 Systemd | | 酷 壳 - CoolShell

init/sysvinit

init - Wikiwand

Originates from System V, the oldest and most widely used init system.
init is LSB-compliant.
Debian switched to systemd in 2015 with Debian 8 Jessie and caused the Devuan fork.

sysv-rc-conf - Run-level configuration for SysV like init script links UI tool

https://github.com/Fleshgrinder/nginx-sysvinit-script
https://github.com/JasonGiedymin/nginx-init-ubuntu

$ sudo update-rc.d
usage: update-rc.d [-n] [-f] <basename> remove
       update-rc.d [-n] <basename> defaults [NN | SS KK]
       update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .
       update-rc.d [-n] <basename> disable|enable [S|2|3|4|5]
                -n: not really
                -f: force

The disable|enable API is not stable and might change in the future.

Examples:

sudo update-rc.d -f nginx remove
sudo update-rc.d nginx defaults

upstart

upstart is deprecated

Upstart - Wikiwand
upstart - event-based init daemon

Use upstart instead of init.d for Ubuntu:
http://casear.chuto.tw/2013/05/31/upstart-setting-for-nginx-on-ubuntu/
http://casear.chuto.tw/2013/05/31/upstart-setting-for-redis-on-ubuntu/

Ubuntu followed Debian's footstep and moved to systemd since 15.04.

sudo service nginx status
sudo service nginx start
sudo service nginx stop

WordPress Upstart script example:

# /etc/init/docker-wordpress.conf
# assuming an image with `--name=docker-wordpress` has been created
description "Wordpress - example.com"
author "Doker Guru"
start on filesystem and started docker
stop on runlevel [!2345]
respawn
exec /usr/bin/docker start -a docker-wordpress
pre-stop exec /usr/bin/docker stop -a docker-wordpress

systemd

systemd

Launchd

used by MacOS

Launchd: One Program to Rule them All - YouTube
About Daemons and Services