Kernel and Boot Process

Level: Intermediate Module: Linux Fundamentals 7 min read Lesson 10 of 10

Overview

  • What you’ll learn: The complete Linux boot sequence from BIOS/UEFI to systemd, GRUB configuration, kernel module management, and kernel parameter tuning.
  • Prerequisites: Lesson 9 – Scheduling and Automation
  • Estimated reading time: 18 minutes

Introduction

Understanding how a Linux system boots is essential knowledge for any system administrator. When a server fails to start, or when you need to modify boot parameters, troubleshoot hardware issues, or tune kernel settings, you must understand each stage of the boot process.

In this lesson, you will follow the complete boot sequence from firmware initialization to user login, learn how to configure the GRUB bootloader, manage kernel modules, and tune the kernel through sysctl and /proc/sys.

The Boot Sequence

The Linux boot process follows these stages:

  1. BIOS/UEFI — Firmware initializes hardware and locates the bootloader.
  2. GRUB — The bootloader loads the kernel and initial RAM filesystem.
  3. Kernel — The kernel initializes hardware drivers and mounts the root filesystem.
  4. initramfs — The initial RAM filesystem provides essential drivers before the real root is available.
  5. systemd (PID 1) — The init system starts services and brings the system to the desired target.

BIOS vs. UEFI

  • BIOS (Basic Input/Output System): Legacy firmware that reads the Master Boot Record (MBR) from the first sector of the boot disk. Limited to 2 TB disks and 4 primary partitions.
  • UEFI (Unified Extensible Firmware Interface): Modern firmware that reads from an EFI System Partition (ESP) formatted as FAT32. Supports GPT partition tables, larger disks, and Secure Boot.
$ ls /sys/firmware/efi
# If this directory exists, the system booted in UEFI mode
# If it doesn't exist, the system booted in BIOS/Legacy mode

$ efibootmgr -v                        # List UEFI boot entries
BootCurrent: 0001
Boot0001* ubuntu  HD(1,GPT,...)/File(EFIubuntushimx64.efi)

GRUB Bootloader

GRUB (Grand Unified Bootloader) is the default bootloader on Ubuntu. It presents a boot menu and loads the Linux kernel with its initial RAM filesystem.

GRUB Configuration

$ cat /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=menu
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

# After editing /etc/default/grub:
$ sudo update-grub
Sourcing file `/etc/default/grub'
Found linux image: /boot/vmlinuz-5.15.0-91-generic
Found initrd image: /boot/initrd.img-5.15.0-91-generic
done

Key GRUB settings:

  • GRUB_DEFAULT: Which menu entry to boot by default (0 = first entry).
  • GRUB_TIMEOUT: Seconds to wait before auto-booting the default entry.
  • GRUB_CMDLINE_LINUX_DEFAULT: Kernel parameters for normal boot entries.
  • GRUB_CMDLINE_LINUX: Kernel parameters for all boot entries including recovery.

Booting into Recovery

If a system fails to boot normally, hold Shift (BIOS) or press Esc (UEFI) during boot to access the GRUB menu. Select “Advanced options” to access recovery mode or edit boot parameters by pressing e.

Kernel Modules

The Linux kernel is modular — functionality can be loaded and unloaded at runtime through kernel modules. Modules provide support for hardware drivers, filesystems, network protocols, and more.

$ lsmod
Module                  Size  Used by
btrfs                1548288  0
raid6_pq              114688  1 btrfs
xor                    24576  1 btrfs
ext4                  880640  2
mbcache                16384  1 ext4
jbd2                  131072  1 ext4
nvidia              39059456  0
nvidia_modeset       1228800  0

$ lsmod | wc -l                        # Count loaded modules
87

$ modinfo ext4                         # Show module information
filename:       /lib/modules/5.15.0-91-generic/kernel/fs/ext4/ext4.ko
license:        GPL
description:    Fourth Extended Filesystem
author:         Remy Card, Stephen Tweedie, Andrew Morton, and others
depends:        mbcache,jbd2

$ sudo modprobe vhost_net               # Load a module
$ sudo modprobe -r vhost_net            # Unload a module

Persistent Module Configuration

# Auto-load modules at boot
$ echo "vhost_net" | sudo tee /etc/modules-load.d/vhost.conf

# Blacklist a module (prevent it from loading)
$ echo "blacklist nouveau" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf
$ sudo update-initramfs -u              # Rebuild initramfs

dmesg — Kernel Messages

The dmesg command displays kernel ring buffer messages, useful for diagnosing hardware and driver issues:

$ sudo dmesg | head -20
[    0.000000] Linux version 5.15.0-91-generic (buildd@lcy02-amd64-045)
[    0.000000] Command line: BOOT_IMAGE=/vmlinuz-5.15.0-91-generic root=...
[    0.000000] BIOS-provided physical RAM map:
[    0.000000]  BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable

$ sudo dmesg | grep -i error            # Search for errors
$ sudo dmesg -T                         # Show human-readable timestamps
$ sudo dmesg -w                         # Watch for new messages (like tail -f)

sysctl — Kernel Parameter Tuning

The sysctl command reads and modifies kernel parameters at runtime through the /proc/sys virtual filesystem:

$ sysctl -a | head -5                  # List all parameters
$ sysctl net.ipv4.ip_forward           # Read a specific parameter
net.ipv4.ip_forward = 0

$ sudo sysctl net.ipv4.ip_forward=1    # Set parameter temporarily

# Make persistent: add to /etc/sysctl.d/
$ echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-forwarding.conf
$ sudo sysctl --system                  # Reload all sysctl files

Common kernel parameters for servers:

# /etc/sysctl.d/99-server-tuning.conf
net.ipv4.ip_forward = 1                 # Enable IP forwarding
net.core.somaxconn = 65535              # Max socket connection backlog
vm.swappiness = 10                      # Reduce swap usage
net.ipv4.tcp_max_syn_backlog = 65535    # TCP SYN backlog
fs.file-max = 2097152                   # Max open file descriptors

The /proc/sys Filesystem

Every sysctl parameter corresponds to a file under /proc/sys:

$ cat /proc/sys/net/ipv4/ip_forward
0
$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward    # Same as sysctl

$ cat /proc/sys/vm/swappiness
60

$ ls /proc/sys/
abi  crypto  debug  dev  fs  kernel  net  user  vm

Key Takeaways

  • The boot sequence is: BIOS/UEFI, GRUB bootloader, Linux kernel + initramfs, systemd (PID 1).
  • GRUB configuration lives in /etc/default/grub; run update-grub after changes.
  • Kernel modules are loaded dynamically with modprobe; list with lsmod; inspect with modinfo.
  • dmesg shows kernel messages for diagnosing hardware and driver issues.
  • sysctl tunes kernel parameters at runtime; persist changes in /etc/sysctl.d/.
  • The /proc/sys filesystem provides a direct interface to kernel parameters.

What’s Next

Congratulations! You have completed Module 1: Linux Fundamentals. You now have a solid foundation in Linux system administration. In Module 2, you will advance to TCP/IP and Networking, covering network configuration, DNS, DHCP, firewalls, and network troubleshooting tools.

繁體中文

概述

  • 學習目標:了解從 BIOS/UEFI 到 systemd 的完整 Linux 開機流程、GRUB 設定、核心模組管理和核心參數調校。
  • 先決條件:第 9 課 – 排程和自動化
  • 預計閱讀時間:18 分鐘

簡介

了解 Linux 系統如何開機對任何系統管理員來說都是必備知識。當伺服器無法啟動、需要修改開機參數、排除硬體問題或調校核心設定時,您必須了解開機過程的每個階段。

開機流程

Linux 開機過程遵循以下階段:

  1. BIOS/UEFI — 韌體初始化硬體並定位引導載入程式。
  2. GRUB — 引導載入程式載入核心和初始 RAM 檔案系統。
  3. 核心 — 核心初始化硬體驅動程式並掛載根檔案系統。
  4. initramfs — 初始 RAM 檔案系統在真正的根可用之前提供必要的驅動程式。
  5. systemd (PID 1) — 初始化系統啟動服務並將系統帶到所需的目標狀態。

BIOS 與 UEFI

  • BIOS:舊式韌體,從開機磁碟的第一個磁區讀取主開機紀錄 (MBR)。限制為 2 TB 磁碟和 4 個主要分割區。
  • UEFI:現代韌體,從格式化為 FAT32 的 EFI 系統分割區 (ESP) 讀取。支援 GPT 分割區表、更大的磁碟和安全開機。

GRUB 引導載入程式

GRUB 是 Ubuntu 的預設引導載入程式。設定檔位於 /etc/default/grub;修改後執行 update-grub

$ cat /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

$ sudo update-grub

核心模組

Linux 核心是模組化的——功能可以在執行時透過核心模組載入和卸載。

$ lsmod                                # 列出已載入的模組
$ modinfo ext4                         # 顯示模組資訊
$ sudo modprobe vhost_net              # 載入模組
$ sudo modprobe -r vhost_net           # 卸載模組

持久化模組設定

$ echo "vhost_net" | sudo tee /etc/modules-load.d/vhost.conf        # 開機自動載入
$ echo "blacklist nouveau" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf  # 黑名單

dmesg — 核心訊息

$ sudo dmesg | grep -i error            # 搜尋錯誤
$ sudo dmesg -T                         # 顯示人類可讀的時間戳記

sysctl — 核心參數調校

$ sysctl net.ipv4.ip_forward           # 讀取特定參數
$ sudo sysctl net.ipv4.ip_forward=1    # 臨時設定參數
$ echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-forwarding.conf  # 持久化

/proc/sys 檔案系統

每個 sysctl 參數對應 /proc/sys 下的一個檔案,提供與核心參數的直接介面。

重點摘要

  • 開機順序為:BIOS/UEFI → GRUB → Linux 核心 + initramfs → systemd (PID 1)。
  • GRUB 設定在 /etc/default/grub;修改後執行 update-grub
  • 核心模組使用 modprobe 動態載入;lsmod 列出;modinfo 檢查。
  • dmesg 顯示核心訊息以診斷硬體和驅動程式問題。
  • sysctl 在執行時調校核心參數;在 /etc/sysctl.d/ 中持久化更改。
  • /proc/sys 檔案系統提供核心參數的直接介面。

下一步

恭喜!您已完成第 1 模組:Linux 基礎。您現在已具備 Linux 系統管理的紮實基礎。在第 2 模組中,您將進入 TCP/IP 和網路,涵蓋網路設定、DNS、DHCP、防火牆和網路故障排除工具。

日本語

概要

  • 学習内容:BIOS/UEFI から systemd までの完全な Linux ブートシーケンス、GRUB 設定、カーネルモジュール管理、カーネルパラメータチューニング。
  • 前提条件:レッスン9 – スケジューリングと自動化
  • 推定読了時間:18分

はじめに

Linux システムのブート方法を理解することは、システム管理者にとって不可欠な知識です。サーバーの起動に失敗した場合や、ブートパラメータの変更、ハードウェアの問題のトラブルシュート、カーネル設定のチューニングが必要な場合、ブートプロセスの各段階を理解する必要があります。

ブートシーケンス

  1. BIOS/UEFI — ファームウェアがハードウェアを初期化し、ブートローダーを検出。
  2. GRUB — ブートローダーがカーネルと初期 RAM ファイルシステムをロード。
  3. カーネル — カーネルがハードウェアドライバーを初期化し、ルートファイルシステムをマウント。
  4. initramfs — 初期 RAM ファイルシステムが実際のルートが利用可能になる前に必要なドライバーを提供。
  5. systemd (PID 1) — init システムがサービスを起動し、目的のターゲットにシステムを移行。

BIOS vs UEFI

  • BIOS:レガシーファームウェア。ブートディスクの最初のセクターからマスターブートレコード (MBR) を読み取り。2TB ディスクと4つのプライマリパーティションに制限。
  • UEFI:最新のファームウェア。FAT32 でフォーマットされた EFI システムパーティション (ESP) から読み取り。GPT パーティションテーブル、大容量ディスク、セキュアブートをサポート。

GRUB ブートローダー

GRUB は Ubuntu のデフォルトブートローダーです。設定は /etc/default/grub にあり、変更後は update-grub を実行します。

$ cat /etc/default/grub
GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

$ sudo update-grub

カーネルモジュール

Linux カーネルはモジュール式で、カーネルモジュールを通じて機能を実行時にロード・アンロードできます。

$ lsmod                                # ロード済みモジュールの一覧
$ modinfo ext4                         # モジュール情報の表示
$ sudo modprobe vhost_net              # モジュールをロード
$ sudo modprobe -r vhost_net           # モジュールをアンロード

永続的なモジュール設定

$ echo "vhost_net" | sudo tee /etc/modules-load.d/vhost.conf        # ブート時に自動ロード
$ echo "blacklist nouveau" | sudo tee /etc/modprobe.d/blacklist-nouveau.conf  # ブラックリスト

dmesg — カーネルメッセージ

$ sudo dmesg | grep -i error            # エラーを検索
$ sudo dmesg -T                         # 人間が読めるタイムスタンプを表示

sysctl — カーネルパラメータチューニング

$ sysctl net.ipv4.ip_forward           # 特定のパラメータを読み取り
$ sudo sysctl net.ipv4.ip_forward=1    # パラメータを一時的に設定
$ echo "net.ipv4.ip_forward=1" | sudo tee /etc/sysctl.d/99-forwarding.conf  # 永続化

/proc/sys ファイルシステム

各 sysctl パラメータは /proc/sys 配下のファイルに対応し、カーネルパラメータへの直接インターフェースを提供します。

重要ポイント

  • ブートシーケンス:BIOS/UEFI → GRUB → Linux カーネル + initramfs → systemd (PID 1)。
  • GRUB 設定は /etc/default/grub にあり、変更後は update-grub を実行。
  • カーネルモジュールは modprobe で動的にロード。lsmod で一覧、modinfo で詳細確認。
  • dmesg はハードウェアとドライバーの問題を診断するためのカーネルメッセージを表示。
  • sysctl は実行時にカーネルパラメータをチューニング。/etc/sysctl.d/ で変更を永続化。
  • /proc/sys ファイルシステムはカーネルパラメータへの直接インターフェースを提供。

次のステップ

おめでとうございます!モジュール1:Linux 基礎を完了しました。Linux システム管理のしっかりした基礎が身につきました。モジュール2では、TCP/IP とネットワーキングに進み、ネットワーク設定、DNS、DHCP、ファイアウォール、ネットワークトラブルシューティングツールについて学びます。

You Missed