Skip to content
Gains Summary
Main Navigation 首页 / Home
C++ 编程 / C++ Programming
系统与高性能 / Systems & Performance
Web 开发 / Web Development
人工智能 / Artificial Intelligence
工业软件 / Industrial Software
其他内容 / Other Topics
C++ 编程 / C++系统与性能 / SystemsWeb 开发 / Web人工智能 / AI工业软件 / Industrial

外观

Sidebar Navigation

← 系统与高性能 / Systems & Performance

操作系统 / Operating Systems

1. OS 底层知识学习路线 / A Learning Path for Operating System Internals

2. 存储硬件基础 — 磁盘到底怎么存数据 / Storage Hardware Fundamentals: How Disks Store Data

3. BIOS vs UEFI — 固件的本质 / BIOS and UEFI: Understanding Firmware

4. 磁盘分区表 — GPT 与 MBR / Disk Partition Tables: GPT and MBR

5. 文件系统核心概念 — inode、journal、COW / Filesystem Concepts: Inodes, Journaling, and Copy-on-Write

6. 常见文件系统格式详解 — FAT 到 ZFS 的进化史 / Filesystem Formats from FAT to ZFS

7. Linux 启动全流程 — 从通电到登录提示符 / The Linux Boot Process from Power-On to Login

8. Windows 启动全流程 — 与 Linux 的对比视角 / The Windows Boot Process in Comparison with Linux

9. Linux 文件系统层次结构 (FHS) — 目录树的哲学 / The Linux Filesystem Hierarchy Standard

10. Linux 挂载机制 — mount、VFS 与 fstab / Linux Mounting with Mount, VFS, and Fstab

11. Linux 磁盘管理实战 — 从分区到挂载全流程 / Practical Linux Disk Management from Partitioning to Mounting

12. Windows 磁盘与文件系统 — 盘符帝国的秩序 / Windows Disks and Filesystems

13. ext4 深入 — 从超级块到 Extent Tree / Ext4 in Depth from Superblocks to Extent Trees

14. btrfs 深入 — B-tree 是万能的 / Btrfs in Depth and Its B-Tree Architecture

15. 双系统 — EFI 分区共存与 GRUB chainload / Dual Boot with Shared EFI Partitions and GRUB Chainloading

本页目录

Windows 启动全流程 — 与 Linux 的对比视角 / The Windows Boot Process in Comparison with Linux ​

📅 创建时间:2026-06-17 🏷️ 标签:#Windows #启动 #BootManager #BCD #UEFI 📚 前置知识:[[06-linux-boot]], [[02-firmware-bios-uefi]]


📋 本章目标 ​

  • 理解 Windows 从 UEFI 到登录的完整启动链路
  • 掌握 Windows Boot Manager 和 BCD 的角色(相当于 GRUB + grub.cfg)
  • 理解 winload.efi 如何加载 Windows 内核
  • 与 Linux 启动链路逐步对比,理解差异的设计原因
  • 理解"快速启动"(Fast Startup)的本质——休眠了一个内核会话

第1部分:完整链路速览(并与 Linux 对比) ​

┌─────────────────────────────────────────────────────────────┐
│         Windows vs Linux 启动链路逐阶段对比                  │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  阶段      Linux                         Windows           │
│  ──────── ────────────────────────  ────────────────────   │
│                                                             │
│  1.固件    UEFI                          UEFI              │
│            ↓                             ↓                 │
│  2.BL      GRUB (grubx64.efi)          Windows Boot Manager│
│            grub.cfg                    (bootmgfw.efi)      │
│                                         BCD 数据库          │
│            ↓                             ↓                 │
│  3.内核    vmlinuz (bzImage)            ntoskrnl.exe       │
│            加载器                        winload.efi 加载   │
│            自解压                        不需要解压         │
│            ↓                             ↓                 │
│  4.早期    initramfs                    winload.efi 加载    │
│            加载驱动+挂载真实根            基本驱动           │
│            ↓                             ↓                 │
│  5.初始化  systemd (PID 1)              SMSS (会话管理器)    │
│                                                    │       │
│                                         Winlogon → 登录     │
│            ↓                             ↓                 │
│  6.就绪    getty → login → shell        explorer.exe       │
│                                                             │
│  关键差异:                                                  │
│  ┌─────────────────────────────────────────────────────┐   │
│  │ • Windows 不需要 initramfs——驱动内置或由 winload 加载 │   │
│  │ • Windows 内核不需要解压——ntoskrnl.exe 是普通 PE 文件│   │
│  │ • Windows 没有 /etc/fstab——注册表存一切配置          │   │
│  │ • Windows 的登录链: SMSS → Winlogon → explorer      │   │
│  │   Linux 的登录链: systemd → getty → login → shell    │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

第2部分:Windows Boot Manager — 微软的 GRUB ​

2.1 bootmgfw.efi 的角色 ​

┌─────────────────────────────────────────────────────────────┐
│              Windows Boot Manager 与 GRUB 的对比             │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  GRUB                          │  Windows Boot Manager      │
│  ───────────────────────────── │ ────────────────────────  │
│  文件: grubx64.efi             │  文件: bootmgfw.efi        │
│  配置: /boot/grub/grub.cfg    │  配置: BCD 数据库           │
│        (文本文件,可手写)        │        (二进制数据库,        │
│                                │         bcdedit 编辑)       │
│  功能: 加载内核+initramfs       │  功能: 加载 winload.efi    │
│        显示菜单                 │        显示菜单             │
│        传递内核参数              │        传递启动选项         │
│                                                             │
│  BCD (Boot Configuration Database):                         │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                                                     │   │
│  │  BCD 是一个注册表蜂巢文件, 存储在:                   │   │
│  │  /EFI/Microsoft/Boot/BCD (在 ESP 分区里)             │   │
│  │  也在 C:\Boot\BCD 有备份                            │   │
│  │                                                     │   │
│  │  用 bcdedit 查看:                                    │   │
│  │  > bcdedit /enum                                    │   │
│  │                                                     │   │
│  │  Windows Boot Manager                               │   │
│  │  ────────────────────                               │   │
│  │  identifier:    {bootmgr}                           │   │
│  │  path:          \EFI\Microsoft\Boot\bootmgfw.efi    │   │
│  │  timeout:       30                                  │   │
│  │                                                     │   │
│  │  Windows Boot Loader                                │   │
│  │  ────────────────────                               │   │
│  │  identifier:    {current}                           │   │
│  │  device:        partition=C:                        │   │
│  │  path:          \Windows\system32\winload.efi       │   │
│  │  osdevice:      partition=C:                        │   │
│  │                                                     │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
│  BCD ≈ Windows 版的 grub.cfg                                │
│  区别: BCD 是二进制格式 → 需要 bcdedit 工具来修改            │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

2.2 启动菜单 → 选择系统 ​

┌─────────────────────────────────────────────────────────────┐
│              Windows 多系统菜单                              │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  Windows Boot Manager 可以显示多系统菜单:                     │
│                                                             │
│  ┌─────────────────────────────────────────────────────┐   │
│  │          Choose an operating system                 │   │
│  │                                                     │   │
│  │          Windows 11                                 │   │
│  │          (或 "Arch Linux" — 如果 GRUB 没有接管)       │   │
│  │                                                     │   │
│  │     Use ↑↓ to choose, Enter to select              │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
│  这个菜单的条目也在 BCD 中                                   │
│                                                             │
│  常见场景: 开机先看到 GRUB(里面有 Arch 和 Windows)          │
│           选择 Windows → GRUB chainload 到 bootmgfw.efi     │
│           → 直接进 Windows 或再显示 Windows 自己的菜单        │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

第3部分:winload.efi → 内核 ​

3.1 winload.efi 的工作 ​

┌─────────────────────────────────────────────────────────────┐
│              winload.efi — Windows 的"内核加载器"             │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  winload.efi 做的事 (和 GRUB + initramfs 的集合对应):        │
│                                                             │
│  1. 加载 ntoskrnl.exe (Windows 内核)                        │
│     → 一个普通的 PE/COFF 可执行文件                          │
│     → 不需要解压 (不像 Linux 的 bzImage)                     │
│                                                             │
│  2. 加载 hal.dll (硬件抽象层)                                │
│     → 隔离内核和具体硬件平台                                 │
│                                                             │
│  3. 加载 SYSTEM 注册表蜂巢 (≈ 内核配置)                      │
│     → C:\Windows\System32\config\SYSTEM                    │
│     → 包含驱动列表、服务列表、设备配置                      │
│                                                             │
│  4. 加载启动类驱动 (Boot-Start Drivers)                      │
│     → 磁盘控制器驱动 (NVMe/SATA/AHCI)                       │
│     → 文件系统驱动 (NTFS)                                   │
│     → 这些驱动在注册表的 SYSTEM\CurrentControlSet\Services  │
│       里标记为 Start=0 (Boot) 或 Start=1 (System)          │
│                                                             │
│  对比 Linux:                                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │ Linux: 内核自解压 → initramfs 里加载.ko 模块          │   │
│  │ Win:   winload.efi 加载 .sys 驱动 → 不需要临时的根    │   │
│  │                                                     │   │
│  │ 原因: Windows 的驱动加载顺序由注册表严格控制           │   │
│  │      不需要在"另一个根"里找驱动                       │   │
│  │      因为 winload.efi 已经能读 NTFS 了               │   │
│  │      (winload.efi 内置 NTFS 驱动)                   │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

第4部分:内核初始化 → 登录 ​

4.1 内核启动后的进程链 ​

┌─────────────────────────────────────────────────────────────┐
│              Windows 内核初始化后的启动链                    │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  ntoskrnl.exe 初始化完成后:                                  │
│      │                                                      │
│      └→ 创建 System 进程 (PID 4, 类似 Linux 的 kthreadd)    │
│      └→ 创建 SMSS.exe (会话管理器, 第一个用户态进程)         │
│            │                                                │
│            ├→ 启动 csrss.exe (客户端/服务器运行时子系统)      │
│            ├→ 启动 wininit.exe                               │
│            │     ├→ services.exe (服务控制管理器, SCM)       │
│            │     │     └→ 启动所有 Windows 服务              │
│            │     ├→ lsass.exe (本地安全认证子系统)            │
│            │     └→ ...                                     │
│            └→ winlogon.exe (登录管理器)                      │
│                  └→ logonUI.exe (登录界面)                   │
│                       └→ 你输入密码                          │
│                            └→ userinit.exe                  │
│                                 └→ explorer.exe (桌面)       │
│                                                             │
│  对比 Linux:                                                │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                                                     │   │
│  │  Linux               Windows                       │   │
│  │  ──────              ────────                       │   │
│  │  systemd (PID 1)     SMSS.exe                      │   │
│  │  getty               winlogon.exe                  │   │
│  │  login               logonUI.exe (密码界面)          │   │
│  │  bash                explorer.exe (桌面)            │   │
│  │                                                     │   │
│  │  核心区别:                                          │   │
│  │  Linux 的 PID 1 是 systemd, 负责启动一切             │   │
│  │  Windows 没有单一的"PID 1 编排者"——                  │   │
│  │  启动链是硬编码的多进程接力 (SMSS→Wininit→Winlogon)  │   │
│  │                                                     │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

第5部分:快速启动 (Fast Startup) 的秘密 ​

┌─────────────────────────────────────────────────────────────┐
│              快速启动 = 注销用户 + 休眠内核                   │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  正常关机 → 下次启动 = 完整启动链 (UEFI→BootMgr→内核→登录)  │
│                                                             │
│  "快速启动" 关机 → 下次启动:                                 │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                                                     │   │
│  │  关机时:                                            │   │
│  │  1. 结束所有用户进程 (≈ 注销)                        │   │
│  │  2. 把内核+驱动+核心服务的内存状态写入                │   │
│  │     C:\hiberfil.sys (休眠文件)                      │   │
│  │  3. 关机                                           │   │
│  │                                                     │   │
│  │  开机时:                                            │   │
│  │  1. UEFI → bootmgfw.efi                            │   │
│  │  2. winload.efi 发现 hiberfil.sys 存在              │   │
│  │  3. 不加载完整内核 → 直接从 hiberfil.sys 恢复        │   │
│  │  4. 跳过了: 驱动初始化、服务启动、用户登录链          │   │
│  │     → 比正常启动快几十秒                             │   │
│  │                                                     │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
│  对双系统用户的影响:                                        │
│  ┌─────────────────────────────────────────────────────┐   │
│  │                                                     │   │
│  │  如果 Windows 快速启动关机:                          │   │
│  │  • Windows NTFS 分区处于"脏"状态                      │   │
│  │  • Linux 挂载此 NTFS 分区 → 只读, 或拒绝挂载         │   │
│  │  • 解决方案: 在 Windows 中关闭快速启动               │   │
│  │    powercfg /h off                                  │   │
│  │    或在 Linux 用 ntfs-3g remove_hiberfile 挂载      │   │
│  │                                                     │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

核心总结 ​

总结1:两个 OS 启动链的本质差异 ​

Linux:   内核精简 + initramfs 补驱动 → systemd 编排一切
         → 灵活性极高, 可以换内核/换 init/换 bootloader

Windows: winload.efi 内置 NTFS 驱动 → 直接加载内核+驱动
         → 启动链是硬编码的, 但更简单, 不需要"临时根文件系统"
1
2
3
4
5

总结2:配置文件对比 ​

Linux:     /etc/default/grub (文本)
           /boot/grub/grub.cfg (文本)
           /etc/mkinitcpio.conf (文本)

Windows:   BCD (二进制, bcdedit 编辑)
           注册表 SYSTEM\...\Services (驱动启动顺序)
1
2
3
4
5
6

总结3:快速启动的代价 ​

快是因为跳过了内核初始化
但 NTFS 分区会处于"脏"状态 → Linux 无法正常读写
双系统用户建议关掉 Fast Startup
1
2
3

章节测试 ​

测试1:bootmgfw.efi ​

Windows Boot Manager 对应 Linux 启动链的哪个组件?它们用什么来存储配置?

测试2:无 initramfs ​

为什么 Windows 不需要 initramfs 这种"临时根文件系统"?

测试3:快速启动 ​

快速启动(Fast Startup)的关机本质上做了什么?为什么它对双系统用户不友好?

测试4:BCB 配置 ​

如何查看和修改 Windows 的启动配置?


参考答案 ​

测试1答案 ​

Windows Boot Manager (bootmgfw.efi) 对应 Linux 的 GRUB(grubx64.efi)。GRUB 用文本文件 grub.cfg 存配置,Boot Manager 用 BCD 二进制数据库存配置。BCD 用 bcdedit 命令行工具编辑,grub.cfg 可以直接 vim 编辑。

测试2答案 ​

Windows 的 winload.efi 内置了 NTFS 文件系统驱动,可以直接读取 Windows 系统分区。它也内置了核心磁盘控制器驱动。所以 winload.efi 不需要先挂载一个"临时的根"来加载驱动——它从系统分区的注册表 SYSTEM 蜂巢里读取驱动列表,按顺序加载。Linux 的内核没有内置所有驱动(为了内核精简),所以需要 initramfs。

测试3答案 ​

快速启动的"关机"实际上是:注销所有用户进程 + 把内核/驱动/核心服务的内存状态写入 hiberfil.sys(休眠文件)。下次开机时 winload.efi 从 hiberfil.sys 直接恢复,跳过驱动初始化和服务启动。问题在于:关机时 NTFS 分区被标记为"脏"(有未写入的数据在休眠文件中),Linux 挂载时会因为一致性检查失败而拒绝挂载或只读挂载。

测试4答案 ​

用 bcdedit:bcdedit /enum 查看所有条目,bcdedit /set {current} description "Windows 11" 修改描述,bcdedit /timeout 5 设置超时,bcdedit /set {current} path \Windows\system32\winload.efi 修改加载器路径。


相关笔记 ​

  • [[06-linux-boot]] - Linux 启动链,本章的对照对象
  • [[02-firmware-bios-uefi]] - 两个系统共享的前一步:UEFI
  • [[14-dual-boot]] - 两个系统如何在同一台机器上实现启动链的衔接

下一步学习 ​

  • [ ] 阅读 08 - Linux 文件系统层次结构 (FHS)

学习状态:🟡 开始学习

最后更新于:

Pager
上一篇7. Linux 启动全流程 — 从通电到登录提示符 / The Linux Boot Process from Power-On to Login
下一篇9. Linux 文件系统层次结构 (FHS) — 目录树的哲学 / The Linux Filesystem Hierarchy Standard

持续记录,持续成长

Copyright © Tidenflow