From Bare NVMe to Login Prompt: Partitions, Filesystems, Mounts & UEFI Boot

When writing user-space application code, we take directories like /etc, /var/log, and /home for granted. Rarely do we pause to ask which physical chip stores those bytes, how a partition gets grafted onto the directory tree, or how power-on firmware locates the Linux kernel in the first place. Yet the moment you work on automated OS provisioning (netboot installation), server/embedded board bring-up, or a machine that refuses to boot after a reboot, a flood of low-level terms hits all at once: /dev/nvme0 vs. /dev/nvme0n1p1, GPT, ext4 vs. vfat, mount, ESP (/boot/efi), BOOTAA64.EFI, systemd-boot vs. UKI, initramfs, and /etc/fstab.

平时在用户态写业务代码时,我们面对的是现成的 /etc、/var/log、/home 目录,很少需要关心底下到底是哪块物理盘、怎么挂上去的、机器上电后又是怎么一步步找到内核的。但只要一碰到自动化装机(netboot OS provisioning)、服务器与嵌入式板卡 bring-up,或者排查重启后进不去系统的问题,一长串底层术语就会同时蹦出来:/dev/nvme0 vs /dev/nvme0n1p1、GPT、ext4 vs vfat、mount、ESP (/boot/efi)、BOOTAA64.EFI、systemd-boot vs UKI、initramfs、/etc/fstab。

Instead of memorizing isolated textbook definitions, let’s trace one continuous physical journey—with interactive diagrams below: how a factory-blank NVMe SSD is partitioned, formatted, mounted, and booted all the way to a running systemd login prompt.

与其孤立地背概念定义,不如结合下面的交互式图解,顺着一条完整的物理链路走一遍:一块刚出厂的空白 NVMe SSD,是怎么一步步完成切 partition、format、mount,并最终独立开机跑起 systemd 的。


1. Decoding Device Names: /dev/nvme0 vs. /dev/nvme0n1 vs. /dev/nvme0n1p1 (设备命名拆解)

Plug an NVMe SSD into a Linux machine and several look-alike entries appear under /dev/. Reading /dev/nvme0n1p1 as three distinct segments makes the naming scheme completely predictable—click any segment or partition block in the interactive explorer below to inspect each layer:

在 Linux 机器上插一块 NVMe SSD,/dev/ 目录下会出现好几个长得很像的设备节点。把 /dev/nvme0n1p1 拆成三段来读,命名规律就一目了然了——可以直接点击下方交互组件里的名字或磁盘分区块查看每一层的作用:

/dev/ ← Click any segment or disk block / 点击拆解
No nvme0n0 or nvme0p0 (1-indexed)
→
Device PathSegment MeaningIndex RuleStores Files?
/dev/nvme0NVMe Controller (physical controller chip / 主控芯片本身)0-indexed (nvme0, nvme1…)No. Character device for admin commands (SMART, firmware, namespaces).
/dev/nvme0n1Namespace 1 (whole raw block device / 整块裸盘)1-indexed (no nvme0n0!)Whole unpartitioned disk; enterprise NVMe supports multiple namespaces, most use one (n1).
/dev/nvme0n1p1Partition 1 (first slice of nvme0n1 / 第 1 个分区)1-indexed (no nvme0p0!)Yes, once formatted with a filesystem and mounted.

Why does SATA use sda1, while NVMe inserts a p (nvme0n1p1)? Linux applies a simple disambiguation rule: when a disk name ends in a letter (like sda), appending a digit (sda1) is unambiguous. When a disk name already ends in a digit (like nvme0n1 or eMMC’s mmcblk0), appending 1 directly would yield nvme0n11—impossible to tell namespace 11 apart from namespace 1, partition 1. Thus Linux always inserts p before the partition number whenever the base block device ends in a digit.

为什么老式 SATA 盘叫 sda1,而 NVMe 中间要多加一个字母 p 叫 nvme0n1p1? 这是 Linux 内核的消歧规则:以字母结尾的盘名(sda)直接拼数字 sda1 不会歧义;但 nvme0n1(以及 eMMC 闪存 mmcblk0)本身以数字结尾,如果不加分隔符写成 nvme0n11,就分不清是第 11 号 namespace 还是 n1 的第 1 个 partition。因此数字结尾的 block device 后面跟 partition 号时一律加 p。


2. Three Steps to Usable Storage: GPT (Partition) → Filesystem (Format) → Mount

Turning a factory-blank /dev/nvme0n1 into usable directories takes three strictly ordered steps—much like turning an empty concrete warehouse into an open retail store: (1) write a GPT floor plan to divide empty rooms (partitions), (2) format each room to install shelving and catalog indexes (filesystem), and (3) mount each room onto a directory path so applications can walk in.

把一块刚出厂的 /dev/nvme0n1 变成能读写的目录,必须走完严格递进的三步——就像把空旷的毛坯大仓库改造成正式营业的商场:(1)写 GPT 户型图砌出隔断房间(partition);(2)对每个房间做 format 装上货架和目录索引本(filesystem);(3)通过 mount 把房间挂上门牌号接入目录树正式营业。

2.1 GPT (GUID Partition Table): Drawing the Floor Plan

A brand-new nvme0n1 is billions of flat, unorganized logical blocks (LBA 0, 1, 2...). GPT writes a compact partition table into the first 34 sectors (~17 KiB) at the head of the disk and automatically mirrors a Backup GPT at the very tail of the disk for crash recovery. Each entry records the slot number (1..128, which does not even have to match physical sector order!), Start/End LBA boundaries, a standardized Partition Type GUID (such as EF00 to mark an EFI System Partition), and a globally unique PARTUUID. Carving GPT partitions only builds walls—inside each room is still raw unformatted bytes.

刚出厂的 nvme0n1 只是一大片连续无序的扇区(LBA 0, 1, 2...)。GPT 在盘头前 34 个扇区写入全局户型图,同时在盘尾自动存一份 Backup GPT 防损坏自愈。每一项记录槽位号(1..128,不必与物理先后顺序一致)、起止扇区 Start/End LBA、用途标签 Partition Type GUID(如 EF00 代表 ESP 启动区)以及唯一身份证 PARTUUID。注意切完 GPT partition 只是砌好了毛坯墙,里面还不能存任何文件。

2.2 Format & Filesystem Types: Installing Shelves for Each Room

Running a format utility (mkfs.ext4, mkfs.vfat) writes inodes, directory trees, and allocation tables inside a partition. A single Linux disk deliberately mixes multiple filesystem types because firmware, user-space services, and crash handlers have completely different requirements:

执行 format(如 mkfs.ext4、mkfs.vfat),就是在 partition 内部建立管理文件名、权限和数据块的索引结构(即 filesystem)。同一块硬盘往往混用多种 filesystem types,因为不同分区的读取方和约束截然不同:

Filesystem TypeTypical UseWhy Choose It? / 核心原因
ext4/ (Root), /dataWorkhorse Linux read-write filesystem: POSIX permissions, symlinks, chattr +i, and power-loss journaling.
Linux 主力读写格式,支持完整权限、软链接与防断电损坏的日志机制。
vfat (FAT32)/boot/efi (ESP)Mandated by UEFI spec. No Unix permissions (never use for /), but simple enough for motherboard firmware (U-Boot / UEFI) to read directly.
UEFI 标准钦定格式,结构极简,主板固件无需跑 Linux 就能直接读取启动文件。
raw (none)Crash log (pstore)No mkfs and never mounted. During a Kernel Panic, the kernel writes raw crash bytes directly to sectors.
不做格式化也不挂载,供内核崩溃瞬间直接裸写现场日志。
tmpfs / ramfsnetboot root, /runPure memory-backed filesystem types; fast and wiped on reboot—ideal for network installers partitioning local disks.
纯驻留在 memory 中的临时文件系统,断电即失,常用于 netboot 内存装机环境。

2.3 How Mount and Partition Relate (Mount 与 Partition 的关系)

Why can’t you read or write /dev/nvme0n1p3/app.log right after formatting nvme0n1p3 as ext4? Unlike Windows—which assigns a separate tree root (C:\, D:\) to every formatted partition—Linux maintains a single global directory tree (Virtual File System, VFS) rooted at /. The file /dev/nvme0n1p3 is just the raw block device handle; until attached, a formatted partition is an isolated island disconnected from /.

为什么把 nvme0n1p3 格成 ext4 后,还是不能直接写 /dev/nvme0n1p3/app.log?因为 Windows 给每个 partition 发一棵独立盘符树(C:\、D:\),而 Linux 全局只有唯一一棵从 / 长出来的单棵目录树(VFS)。/dev/nvme0n1p3 代表的只是裸硬件块本身;在挂载之前,这个格式化好的 partition 只是一座跟 / 没有任何路径相连的“孤岛仓库”。

mount is the graft operation that binds the filesystem inside a partition onto an empty directory (the mount point, e.g., /data). Decoupling physical partitions from directory paths is exactly what makes OS installation possible: during a netboot install (where / is a memory tmpfs), the installer temporarily mounts nvme0n1p2 at /mnt/newroot to populate /mnt/newroot/etc and /mnt/newroot/usr; after rebooting from disk, that exact same nvme0n1p2 is mounted as /, so /mnt/newroot/etc seamlessly becomes /etc! Conversely, if you forget to mount your 200 GB nvme0n1p3 onto /data, writes to /data will quietly fill up your small root partition instead.

mount 就是“嫁接”桥梁:把某个 partition 里的 filesystem 绑定到单棵目录树的某个空目录(mount point,如 /data)上。把物理 partition 和目录路径解耦,正是重装系统的核心原理:在 netboot 装机阶段(此时 / 在 memory 的 tmpfs 里),安装器先把硬盘根分区 nvme0n1p2 临时 mount 到 /mnt/newroot 往里拷系统文件;等重启从硬盘引导时,同一个 nvme0n1p2 再被 mount 成真正的 /,刚才拷进去的 /mnt/newroot/etc 自然就变成了开机后的 /etc!反过来,如果忘了 mount 数据盘就往 /data 写日志,数据其实全塞进了根分区底下的普通文件夹里,极易把根分区撑爆。


3. The UEFI Boot Sequence: ESP, BOOTAA64.EFI, UKI, and /etc/fstab (开机接力赛)

Why does booting pass through so many handoffs instead of jumping straight into /sbin/init? Because power-on to user-space crosses separate execution worlds that share no runtime memory. Step through both tabs of the interactive UEFI Boot Explorer below to see each relay stage and compare systemd-boot against a single-file UKI:

为什么开机不能一步跳进 /sbin/init,非要经过 ESP、BOOTAA64.EFI、initramfs 和 /etc/fstab?因为开机横跨了几个互不共享运行态 memory 的独立阶段,只能靠磁盘上固定位置的约定一棒棒交接。你可以点击下方交互式导览切换查看五步接力细节,以及 systemd-boot 与 UKI 的结构差异:

UEFI Diskboot Explorer

3.1 Firmware, ESP (/boot/efi), and BOOTAA64.EFI

Motherboard firmware in SPI Flash (U-Boot on many ARM64 platforms, or EDK2 UEFI on x86/ARM servers) stays fixed while Linux kernel filenames (vmlinuz-6.12...) change constantly inside ext4. Under the UEFI standard, firmware simply finds the vfat ESP partition in GPT and executes the architecture’s default fallback path: /EFI/BOOT/BOOTAA64.EFI on 64-bit ARM (AArch64) or /EFI/BOOT/BOOTX64.EFI on x86_64. Because Linux later mounts that ESP partition at /boot/efi, the same file appears at /boot/efi/EFI/BOOT/BOOTAA64.EFI inside Linux.

主板 SPI Flash 里的固件(ARM64 常见为 U-Boot,x86/通用服务器常见为 EDK2 UEFI)是固化少变的,而 ext4 里的内核文件名每次升级都在变。因此 UEFI 标准规定:固件在空白新盘上只需找到 GPT 里打标为 ESP 的 vfat 分区,直接加载写死的默认入口路径——ARM64 叫 /EFI/BOOT/BOOTAA64.EFI(AA64 = AArch64),x86_64 叫 /EFI/BOOT/BOOTX64.EFI。等进入 Linux 后,因为习惯把 ESP mount 在 /boot/efi 目录,它在系统里的完整路径就成了 /boot/efi/EFI/BOOT/BOOTAA64.EFI。

3.2 Menu Bootloader (systemd-boot) vs. Unified Kernel Image (UKI)

Any valid UEFI PE/COFF executable can sit at BOOTAA64.EFI. In Pattern A (Menu Loader), BOOTAA64.EFI is a tiny ~100 KB manager like systemd-bootaa64.efi that parses /loader/entries/*.conf and loads separate vmlinuz and initrd files—flexible for local kernel upgrades and rollbacks. In Pattern B (UKI), tools like ukify or objcopy glue a UEFI stub (linuxaa64.efi.stub), .cmdline, .linux (vmlinuz), and .initrd into a single self-contained ~50 MB .EFI binary—ideal for single-file HTTP netboot and atomic Secure Boot cryptographic signing.

BOOTAA64.EFI 有两种主流形态:形态 A(菜单加载器,如 systemd-boot)放的是约 100 KB 的小引导器,读取 /loader/entries/*.conf 文本菜单再去加载独立的 vmlinuz 和 initrd,本地升级内核与回滚非常灵活;形态 B(单文件 UKI)用 ukify 或 objcopy 把引导壳 linuxaa64.efi.stub、.cmdline、vmlinuz 和 initrd 封进同一个 ~50 MB 的 .EFI 大文件里,零外部配置依赖,天然适合单文件 HTTP netboot 下载即启动以及整包安全签名。

3.3 Kernel + initramfs (switch_root) → systemd + /etc/fstab

Once the kernel starts, a small memory archive called initramfs loads block/encryption drivers, mounts the physical root partition specified by root=... on the kernel command line, and runs switch_root to hand PID 1 over to systemd. At that moment, only / is mounted! Early in initialization, systemd-fstab-generator parses /etc/fstab to automatically fsck and mount /data, /boot/efi, and all remaining partitions before launching user-space services.

内核启动后,先由驻留在 memory 里的微型 initramfs 加载存储或解密驱动,按 cmdline 里的 root=... 把物理根分区 mount 好,再通过 switch_root 扶正为真正的 / 并拉起 1 号进程 systemd。注意此时整台机器只有 / 这一个分区挂好了!随后 systemd 通过 systemd-fstab-generator 读取 /etc/fstab 清单,自动把 /data 和 /boot/efi 等其余 partition 依次 mount 到位。


4. 30-Second Diagnostic Cheat Sheet (实战速查命令)

Run these five read-only commands on any unfamiliar Linux machine to map out its entire storage and boot chain in 30 seconds:

在任何陌生的 Linux 机器上敲完下面 5 条只读命令,30 秒就能摸清它的完整存储与启动拓扑:

# 1. Block devices -> partitions -> filesystem types -> UUIDs -> mount points
# 1. 一眼看清:裸盘 -> partition -> filesystem type -> UUID -> mount point
lsblk -f

# 2. Raw GPT partition table (LBA boundaries, sizes, Partition Type GUIDs)
# 2. 查看裸盘 GPT 分区表(起止扇区、大小、用途 GUID 标签)
sudo sgdisk -p /dev/nvme0n1

# 3. Active physical mounts and mount options (filtering out virtual fs noise)
# 3. 查看当前生效的所有真实物理 mount 关系与参数
findmnt --real

# 4. Kernel boot arguments passed by UEFI / systemd-boot / UKI
# 4. 查看上一棒(固件 / systemd-boot / UKI)传给内核的启动参数
cat /proc/cmdline

# 5. Persistent boot-time mount table
# 5. 查看开机自动 mount 清单,核对是否与 findmnt 一致
cat /etc/fstab

Leave a Reply

Your email address will not be published. Required fields are marked *