內核啟動需要掛載根文件系統,但根文件系統驅動(如 SCSI、SATA、NVMe、文件系統驅動)又在根文件系統上。Linux 通過多種機制打破這個循環依賴。
# 內核命令行
root=/dev/sda2 rootfstype=ext4
=y),非模組 (=m)root= → 根據主/次設備號查找驅動 → 直接掛載init/do_mounts.c 中 root_dev_names[] 定義 (hd, sd, vd, nvme, mmc, mtd, nfs, ram...)
# 內核命令行
root=/dev/fd0 # 軟驅
root=/dev/ram0 # 內存盤
/dev/ram0 → 掛載CONFIG_BLK_DEV_RAM=y,預設 16 個 (/dev/ram0-15)
# Bootloader 傳遞參數
initrd=0x80000000,0x200000 # 起始地址、大小
# 或編譯進內核
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE=""
/dev/ram0/dev/ram0/dev/ram0 為根文件系統/linuxrc 腳本:載入模組、掃描硬體、掛載真實根分區pivot_root 切換根文件系統CONFIG_BLK_DEV_RAM + CONFIG_BLK_DEV_INITRD 同時啟用CONFIG_INITRAMFS_SOURCE 指定源目錄自動打包populate_rootfs() 解壓 cpio 至 rootfs/init → 執行之 (systemd/busybox init)prepare_namespace() 掛載真實根分區| 架構 | Bootloader | 內核參數 | 根文件系統 | 備註 |
|---|---|---|---|---|
| Flash 直啟 | U-Boot | root=/dev/mtdblock2 rootfstype=jffs2 | JFFS2/UBIFS | 無 initramfs,驅動內建 |
| SD/eMMC 啟動 | U-Boot/SPL | root=/dev/mmcblk0p2 rootwait | ext4/f2fs | rootwait 等待設備就緒 |
| NFS 根文件系統 | U-Boot | root=/dev/nfs nfsroot=192.168.1.100:/nfsroot ip=dhcp | NFSv3/v4 | 無磁碟工作站、開發調試 |
| initramfs + 切換 | U-Boot | root=/dev/mmcblk0p2 | initramfs → ext4 | 模組化驅動、加密磁碟、RAID |
# 基本參數
root= # 根設備 (設備節點、UUID、LABEL、PARTUUID)
rootfstype= # 文件系統類型 (ext4, xfs, btrfs, jffs2, ubifs, nfs...)
rootflags= # 掛載選項 (ro, rw, noatime, compress=zstd...)
rootdelay= # 等待設備就緒秒數 (預設 0,嵌入式常設 5-10)
rootwait # 無限等待 (塊設備熱插拔、MMC、USB 儲存)
# initramfs 相關
rd.init= # 指定 init 程式路徑
rd.shell # 失敗時進入 shell
rd.break= # 在特定階段中斷 (cmdline, pre-udev, pre-trigger, initqueue, pre-mount, mount, pre-pivot, cleanup)
rd.debug # 開啟調試輸出
# NFS 根文件系統
nfsroot= # 格式: [server:]path[,options]
ip= # 格式: client-ip:server-ip:gateway:netmask:hostname:device:autoconf
CONFIG_BLK_DEV_INITRD=y、CONFIG_INITRAMFS_SOURCE=""CONFIG_BLK_DEV_RAM 依賴 (initramfs 不需要)/linuxrc 遷移為 /init (systemd/busybox)dracut/mkinitcpio/update-initramfs 生成 cpio 歸檔lsinitramfs /boot/initramfs-$(uname -r).img | head 內容正確