01 - iPXE + Clonezilla 网络装机原理解析

本文档中的 IP 地址(如 192.xxx.xxx.10)为实验环境示例,请根据你的实际网络环境替换。

目录

  1. [PXE vs iPXE](#PXE vs iPXE)
  2. [iPXE 完整引导链路](#iPXE 完整引导链路)
  3. 两阶段引导原理
  4. [安装器式 vs 镜像式部署](#安装器式 vs 镜像式部署)
  5. [Clonezilla 工作原理](#Clonezilla 工作原理)
  6. [boot.ipxe 脚本语法简介](#boot.ipxe 脚本语法简介)

1. PXE vs iPXE

1.1 传统 PXE

PXE(Preboot eXecution Environment)是 Intel 开发的网络启动标准,几乎所有现代网卡都内置了 PXE 固件。工作流程:

  1. 客户机 BIOS 设置为 Network boot
  2. 网卡 PXE 固件发出 DHCP 请求
  3. DHCP 服务器返回 IP 地址 + 引导文件名(如 undionly.kpxe
  4. 客户机通过 TFTP 下载引导文件并执行

PXE 的局限

局限 影响
只支持 TFTP 协议 TFTP 是 UDP 传输,大文件容易丢包超时
不支持 HTTP / iSCSI 无法利用 Web 服务器或存储网络
没有脚本能力 不能做菜单、条件判断、变量
TFTP 传输速度慢 传输 488MB 的 squashfs 几乎不可能

1.2 iPXE

iPXE 是 PXE 的开源增强替代,核心优势:

  • HTTP 传输:通过 Web 服务器传输内核和 initrd,速度比 TFTP 快数倍
  • 脚本菜单 :支持 menuitemchoosegoto 等脚本语法,可以做出交互式菜单
  • 条件判断:支持变量赋值、条件跳转、链式加载
  • 多协议:HTTP、TFTP、iSCSI、SAN、AoE、FCoE 等
  • 链式加载 :可以从 HTTP URL 加载下一个 iPXE 脚本(chain),实现模块化设计

1.3 对比总结

特性 传统 PXE iPXE
传输协议 仅 TFTP(UDP) HTTP / TFTP / iSCSI
大文件传输 慢,容易超时 HTTP 稳定快速
脚本能力 完整脚本语言(变量/菜单/条件)
菜单支持 无(需第三方 SYSLINUX) 内置 menu/choose
引导文件大小 TFTP 有实际限制(~30MB) HTTP 无限制
链式加载 不支持 支持 chain 从 HTTP 加载子脚本

本实验使用 iPXE 通过 HTTP 传输 Clonezilla live 的 filesystem.squashfs(488MB),如果用 TFTP 传输这么大的文件会非常慢甚至失败。


2. iPXE 完整引导链路

以下是客户机从开机到进入操作系统的完整流程:
#mermaid-svg-oAJugnqkQVLZQeCz{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-oAJugnqkQVLZQeCz .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-oAJugnqkQVLZQeCz .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-oAJugnqkQVLZQeCz .error-icon{fill:#552222;}#mermaid-svg-oAJugnqkQVLZQeCz .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-oAJugnqkQVLZQeCz .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-oAJugnqkQVLZQeCz .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-oAJugnqkQVLZQeCz .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-oAJugnqkQVLZQeCz .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-oAJugnqkQVLZQeCz .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-oAJugnqkQVLZQeCz .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-oAJugnqkQVLZQeCz .marker{fill:#333333;stroke:#333333;}#mermaid-svg-oAJugnqkQVLZQeCz .marker.cross{stroke:#333333;}#mermaid-svg-oAJugnqkQVLZQeCz svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-oAJugnqkQVLZQeCz p{margin:0;}#mermaid-svg-oAJugnqkQVLZQeCz .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-oAJugnqkQVLZQeCz .cluster-label text{fill:#333;}#mermaid-svg-oAJugnqkQVLZQeCz .cluster-label span{color:#333;}#mermaid-svg-oAJugnqkQVLZQeCz .cluster-label span p{background-color:transparent;}#mermaid-svg-oAJugnqkQVLZQeCz .label text,#mermaid-svg-oAJugnqkQVLZQeCz span{fill:#333;color:#333;}#mermaid-svg-oAJugnqkQVLZQeCz .node rect,#mermaid-svg-oAJugnqkQVLZQeCz .node circle,#mermaid-svg-oAJugnqkQVLZQeCz .node ellipse,#mermaid-svg-oAJugnqkQVLZQeCz .node polygon,#mermaid-svg-oAJugnqkQVLZQeCz .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-oAJugnqkQVLZQeCz .rough-node .label text,#mermaid-svg-oAJugnqkQVLZQeCz .node .label text,#mermaid-svg-oAJugnqkQVLZQeCz .image-shape .label,#mermaid-svg-oAJugnqkQVLZQeCz .icon-shape .label{text-anchor:middle;}#mermaid-svg-oAJugnqkQVLZQeCz .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-oAJugnqkQVLZQeCz .rough-node .label,#mermaid-svg-oAJugnqkQVLZQeCz .node .label,#mermaid-svg-oAJugnqkQVLZQeCz .image-shape .label,#mermaid-svg-oAJugnqkQVLZQeCz .icon-shape .label{text-align:center;}#mermaid-svg-oAJugnqkQVLZQeCz .node.clickable{cursor:pointer;}#mermaid-svg-oAJugnqkQVLZQeCz .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-oAJugnqkQVLZQeCz .arrowheadPath{fill:#333333;}#mermaid-svg-oAJugnqkQVLZQeCz .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-oAJugnqkQVLZQeCz .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-oAJugnqkQVLZQeCz .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-oAJugnqkQVLZQeCz .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-oAJugnqkQVLZQeCz .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-oAJugnqkQVLZQeCz .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-oAJugnqkQVLZQeCz .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-oAJugnqkQVLZQeCz .cluster text{fill:#333;}#mermaid-svg-oAJugnqkQVLZQeCz .cluster span{color:#333;}#mermaid-svg-oAJugnqkQVLZQeCz div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-oAJugnqkQVLZQeCz .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-oAJugnqkQVLZQeCz rect.text{fill:none;stroke-width:0;}#mermaid-svg-oAJugnqkQVLZQeCz .icon-shape,#mermaid-svg-oAJugnqkQVLZQeCz .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-oAJugnqkQVLZQeCz .icon-shape p,#mermaid-svg-oAJugnqkQVLZQeCz .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-oAJugnqkQVLZQeCz .icon-shape .label rect,#mermaid-svg-oAJugnqkQVLZQeCz .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-oAJugnqkQVLZQeCz .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-oAJugnqkQVLZQeCz .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-oAJugnqkQVLZQeCz :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 非 iPXE 客户端
iPXE 客户端
选 1: Debian13 金盘还原
选 2: Ubuntu26 金盘还原
选 3: Clonezilla 手动
客户机开机
BIOS: Network boot
网卡 PXE 固件发出 DHCP 请求
DHCP 服务器响应
下发 undionly.kpxe 文件名
下发 HTTP URL 指向 boot.ipxe
通过 TFTP 下载 undionly.kpxe
执行 undionly.kpxe → iPXE 固件启动
iPXE 再次发出 DHCP 请求

携带 user-class: iPXE
通过 HTTP 下载 boot.ipxe 菜单脚本
iPXE 显示菜单

等待用户选择
HTTP 下载 Clonezilla

vmlinuz + initrd + squashfs
imgargs 传入内核参数

包括 ocs_live_run / NFS挂载 / fetch squashfs
boot → 内核启动
Clonezilla live 运行

自动挂载 NFS → restoredisk → poweroff

链路中的关键组件

步骤 组件 作用
DHCP isc-dhcp-server 分配 IP + 根据客户端类型下发不同引导文件
TFTP tftpd-hpa 提供 undionly.kpxe 下载(仅第一阶段使用)
HTTP nginx 提供 boot.ipxe 菜单 + 内核/initrd/squashfs 下载
NFS nfs-kernel-server 存储 Clonezilla 镜像,供 savedisk/restoredisk 读写
iPXE undionly.kpxe PXE → iPXE 的桥梁,支持 HTTP 和脚本

各组件间的数据流

复制代码
客户机 ──DHCP──→ DHCP服务器(返回IP + 引导文件名)
客户机 ──TFTP──→ TFTP服务器(下载 undionly.kpxe,仅190KB)
客户机 ──DHCP──→ DHCP服务器(第二次,返回 HTTP URL)
客户机 ──HTTP──→ nginx(下载 boot.ipxe 菜单脚本)
客户机 ──HTTP──→ nginx(下载 vmlinuz + initrd.img + filesystem.squashfs)
客户机 ──NFS───→ NFS服务器(挂载 /home/partimag 读写镜像)

3. 两阶段引导原理

iPXE 引导采用"两阶段"设计,这是为了兼容传统 PXE 网卡。

3.1 第一阶段:PXE → iPXE

客户机网卡的内置 PXE 固件不支持 HTTP 和脚本。DHCP 服务器检测到这是普通 PXE 客户端(DHCP 请求中无 user-class: iPXE),于是通过 TFTP 下发 undionly.kpxe------这就是 iPXE 固件本身,体积仅约 190KB,TFTP 传输毫无压力。

3.2 第二阶段:iPXE → boot.ipxe

undionly.kpxe 执行后,iPXE 固件再次发出 DHCP 请求,这次携带 user-class: iPXE 标识。DHCP 服务器检测到这是 iPXE 客户端,不再下发 TFTP 文件,而是返回一个 HTTP URL(如 http://192.xxx.xxx.xxx/boot.ipxe`),指向 iPXE 菜单脚本。iPXE 通过 HTTP 下载并执行该脚本。

3.3 流程图

#mermaid-svg-HUEPy3R9WHILjzud{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-HUEPy3R9WHILjzud .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-HUEPy3R9WHILjzud .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-HUEPy3R9WHILjzud .error-icon{fill:#552222;}#mermaid-svg-HUEPy3R9WHILjzud .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-HUEPy3R9WHILjzud .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-HUEPy3R9WHILjzud .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-HUEPy3R9WHILjzud .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-HUEPy3R9WHILjzud .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-HUEPy3R9WHILjzud .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-HUEPy3R9WHILjzud .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-HUEPy3R9WHILjzud .marker{fill:#333333;stroke:#333333;}#mermaid-svg-HUEPy3R9WHILjzud .marker.cross{stroke:#333333;}#mermaid-svg-HUEPy3R9WHILjzud svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-HUEPy3R9WHILjzud p{margin:0;}#mermaid-svg-HUEPy3R9WHILjzud .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-HUEPy3R9WHILjzud .cluster-label text{fill:#333;}#mermaid-svg-HUEPy3R9WHILjzud .cluster-label span{color:#333;}#mermaid-svg-HUEPy3R9WHILjzud .cluster-label span p{background-color:transparent;}#mermaid-svg-HUEPy3R9WHILjzud .label text,#mermaid-svg-HUEPy3R9WHILjzud span{fill:#333;color:#333;}#mermaid-svg-HUEPy3R9WHILjzud .node rect,#mermaid-svg-HUEPy3R9WHILjzud .node circle,#mermaid-svg-HUEPy3R9WHILjzud .node ellipse,#mermaid-svg-HUEPy3R9WHILjzud .node polygon,#mermaid-svg-HUEPy3R9WHILjzud .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-HUEPy3R9WHILjzud .rough-node .label text,#mermaid-svg-HUEPy3R9WHILjzud .node .label text,#mermaid-svg-HUEPy3R9WHILjzud .image-shape .label,#mermaid-svg-HUEPy3R9WHILjzud .icon-shape .label{text-anchor:middle;}#mermaid-svg-HUEPy3R9WHILjzud .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-HUEPy3R9WHILjzud .rough-node .label,#mermaid-svg-HUEPy3R9WHILjzud .node .label,#mermaid-svg-HUEPy3R9WHILjzud .image-shape .label,#mermaid-svg-HUEPy3R9WHILjzud .icon-shape .label{text-align:center;}#mermaid-svg-HUEPy3R9WHILjzud .node.clickable{cursor:pointer;}#mermaid-svg-HUEPy3R9WHILjzud .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-HUEPy3R9WHILjzud .arrowheadPath{fill:#333333;}#mermaid-svg-HUEPy3R9WHILjzud .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-HUEPy3R9WHILjzud .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-HUEPy3R9WHILjzud .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-HUEPy3R9WHILjzud .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-HUEPy3R9WHILjzud .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-HUEPy3R9WHILjzud .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-HUEPy3R9WHILjzud .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-HUEPy3R9WHILjzud .cluster text{fill:#333;}#mermaid-svg-HUEPy3R9WHILjzud .cluster span{color:#333;}#mermaid-svg-HUEPy3R9WHILjzud div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-HUEPy3R9WHILjzud .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-HUEPy3R9WHILjzud rect.text{fill:none;stroke-width:0;}#mermaid-svg-HUEPy3R9WHILjzud .icon-shape,#mermaid-svg-HUEPy3R9WHILjzud .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-HUEPy3R9WHILjzud .icon-shape p,#mermaid-svg-HUEPy3R9WHILjzud .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-HUEPy3R9WHILjzud .icon-shape .label rect,#mermaid-svg-HUEPy3R9WHILjzud .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-HUEPy3R9WHILjzud .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-HUEPy3R9WHILjzud .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-HUEPy3R9WHILjzud :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 第二阶段
第一阶段
DHCP 请求
无 user-class
TFTP 下载
DHCP 请求

携带 user-class: iPXE
检测到 user-class
HTTP 下载
客户机 PXE 固件
DHCP 服务器
返回 undionly.kpxe 文件名
undionly.kpxe

约190KB
iPXE 固件启动
DHCP 服务器
返回 HTTP URL
boot.ipxe 菜单脚本
显示菜单 → 选择 → 启动内核

3.4 DHCP 配置中的 user-class 判断

DHCP 服务器通过 user-class 选项区分两个阶段:

text 复制代码
# /etc/dhcp/dhcpd.conf 中的关键配置(简化版)

if exists user-class and option user-class = "iPXE" {
    # 第二阶段:iPXE 客户端 → 通过 HTTP 下发菜单脚本
    filename "http://192.xxx.xxx.xxx/boot.ipxe";
} else {
    # 第一阶段:普通 PXE 客户端 → 通过 TFTP 下发 iPXE 固件
    filename "undionly.kpxe";
}

3.5 为什么需要两阶段

方案 问题
直接用 PXE 下载内核 TFTP 太慢,大文件(488MB squashfs)几乎不可能传输成功
直接用 iPXE 固件 网卡内置的 PXE 固件不支持 iPXE 脚本和 HTTP
两阶段方案 先用 TFTP 传小文件(190KB undionly.kpxe),再用 HTTP 传大文件

简单来说:网卡自带的 PXE 太弱,我们先通过 TFTP 送一个"增强包"(undionly.kpxe),让网卡获得 HTTP 和脚本能力,然后再通过 HTTP 传输大文件和菜单脚本。


4. 安装器式 vs 镜像式部署

本实验支持两种部署方式,各有优劣。

4.1 安装器式部署(preseed / autoinstall)

#mermaid-svg-1JgByDHJwaV4OpEW{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-1JgByDHJwaV4OpEW .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-1JgByDHJwaV4OpEW .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-1JgByDHJwaV4OpEW .error-icon{fill:#552222;}#mermaid-svg-1JgByDHJwaV4OpEW .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-1JgByDHJwaV4OpEW .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-1JgByDHJwaV4OpEW .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-1JgByDHJwaV4OpEW .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-1JgByDHJwaV4OpEW .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-1JgByDHJwaV4OpEW .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-1JgByDHJwaV4OpEW .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-1JgByDHJwaV4OpEW .marker{fill:#333333;stroke:#333333;}#mermaid-svg-1JgByDHJwaV4OpEW .marker.cross{stroke:#333333;}#mermaid-svg-1JgByDHJwaV4OpEW svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-1JgByDHJwaV4OpEW p{margin:0;}#mermaid-svg-1JgByDHJwaV4OpEW .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-1JgByDHJwaV4OpEW .cluster-label text{fill:#333;}#mermaid-svg-1JgByDHJwaV4OpEW .cluster-label span{color:#333;}#mermaid-svg-1JgByDHJwaV4OpEW .cluster-label span p{background-color:transparent;}#mermaid-svg-1JgByDHJwaV4OpEW .label text,#mermaid-svg-1JgByDHJwaV4OpEW span{fill:#333;color:#333;}#mermaid-svg-1JgByDHJwaV4OpEW .node rect,#mermaid-svg-1JgByDHJwaV4OpEW .node circle,#mermaid-svg-1JgByDHJwaV4OpEW .node ellipse,#mermaid-svg-1JgByDHJwaV4OpEW .node polygon,#mermaid-svg-1JgByDHJwaV4OpEW .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-1JgByDHJwaV4OpEW .rough-node .label text,#mermaid-svg-1JgByDHJwaV4OpEW .node .label text,#mermaid-svg-1JgByDHJwaV4OpEW .image-shape .label,#mermaid-svg-1JgByDHJwaV4OpEW .icon-shape .label{text-anchor:middle;}#mermaid-svg-1JgByDHJwaV4OpEW .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-1JgByDHJwaV4OpEW .rough-node .label,#mermaid-svg-1JgByDHJwaV4OpEW .node .label,#mermaid-svg-1JgByDHJwaV4OpEW .image-shape .label,#mermaid-svg-1JgByDHJwaV4OpEW .icon-shape .label{text-align:center;}#mermaid-svg-1JgByDHJwaV4OpEW .node.clickable{cursor:pointer;}#mermaid-svg-1JgByDHJwaV4OpEW .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-1JgByDHJwaV4OpEW .arrowheadPath{fill:#333333;}#mermaid-svg-1JgByDHJwaV4OpEW .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-1JgByDHJwaV4OpEW .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-1JgByDHJwaV4OpEW .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-1JgByDHJwaV4OpEW .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-1JgByDHJwaV4OpEW .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-1JgByDHJwaV4OpEW .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-1JgByDHJwaV4OpEW .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-1JgByDHJwaV4OpEW .cluster text{fill:#333;}#mermaid-svg-1JgByDHJwaV4OpEW .cluster span{color:#333;}#mermaid-svg-1JgByDHJwaV4OpEW div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-1JgByDHJwaV4OpEW .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-1JgByDHJwaV4OpEW rect.text{fill:none;stroke-width:0;}#mermaid-svg-1JgByDHJwaV4OpEW .icon-shape,#mermaid-svg-1JgByDHJwaV4OpEW .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-1JgByDHJwaV4OpEW .icon-shape p,#mermaid-svg-1JgByDHJwaV4OpEW .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-1JgByDHJwaV4OpEW .icon-shape .label rect,#mermaid-svg-1JgByDHJwaV4OpEW .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-1JgByDHJwaV4OpEW .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-1JgByDHJwaV4OpEW .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-1JgByDHJwaV4OpEW :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} iPXE 菜单
HTTP 下载内核 + initrd
内核启动 → 进入安装器
读取 preseed / autoinstall 配置
从镜像站逐包下载安装
配置系统 → 安装 GRUB → 完成

特点

  • 灵活:可以自定义分区方案、软件包列表、网络配置
  • :需要从镜像站逐个下载 .deb 包安装
  • 依赖外网:安装过程中需要持续访问外网(需要服务器做网关)
  • 适用场景:首次制作金盘母机、需要不同配置的机器

技术方案

系统 无人值守技术 配置文件 数据源机制
Debian 13 preseed preseed.cfg 通过 url= 参数指定 HTTP 路径
Ubuntu 26.04 autoinstall + cloud-init user-data + meta-data 通过 ds=nocloud-net;s= 指定 HTTP 路径

4.2 镜像式部署(Clonezilla savedisk / restoredisk)

#mermaid-svg-nrcH5c7diJBw2rRE{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-nrcH5c7diJBw2rRE .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-nrcH5c7diJBw2rRE .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-nrcH5c7diJBw2rRE .error-icon{fill:#552222;}#mermaid-svg-nrcH5c7diJBw2rRE .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-nrcH5c7diJBw2rRE .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-nrcH5c7diJBw2rRE .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-nrcH5c7diJBw2rRE .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-nrcH5c7diJBw2rRE .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-nrcH5c7diJBw2rRE .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-nrcH5c7diJBw2rRE .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-nrcH5c7diJBw2rRE .marker{fill:#333333;stroke:#333333;}#mermaid-svg-nrcH5c7diJBw2rRE .marker.cross{stroke:#333333;}#mermaid-svg-nrcH5c7diJBw2rRE svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-nrcH5c7diJBw2rRE p{margin:0;}#mermaid-svg-nrcH5c7diJBw2rRE .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-nrcH5c7diJBw2rRE .cluster-label text{fill:#333;}#mermaid-svg-nrcH5c7diJBw2rRE .cluster-label span{color:#333;}#mermaid-svg-nrcH5c7diJBw2rRE .cluster-label span p{background-color:transparent;}#mermaid-svg-nrcH5c7diJBw2rRE .label text,#mermaid-svg-nrcH5c7diJBw2rRE span{fill:#333;color:#333;}#mermaid-svg-nrcH5c7diJBw2rRE .node rect,#mermaid-svg-nrcH5c7diJBw2rRE .node circle,#mermaid-svg-nrcH5c7diJBw2rRE .node ellipse,#mermaid-svg-nrcH5c7diJBw2rRE .node polygon,#mermaid-svg-nrcH5c7diJBw2rRE .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-nrcH5c7diJBw2rRE .rough-node .label text,#mermaid-svg-nrcH5c7diJBw2rRE .node .label text,#mermaid-svg-nrcH5c7diJBw2rRE .image-shape .label,#mermaid-svg-nrcH5c7diJBw2rRE .icon-shape .label{text-anchor:middle;}#mermaid-svg-nrcH5c7diJBw2rRE .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-nrcH5c7diJBw2rRE .rough-node .label,#mermaid-svg-nrcH5c7diJBw2rRE .node .label,#mermaid-svg-nrcH5c7diJBw2rRE .image-shape .label,#mermaid-svg-nrcH5c7diJBw2rRE .icon-shape .label{text-align:center;}#mermaid-svg-nrcH5c7diJBw2rRE .node.clickable{cursor:pointer;}#mermaid-svg-nrcH5c7diJBw2rRE .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-nrcH5c7diJBw2rRE .arrowheadPath{fill:#333333;}#mermaid-svg-nrcH5c7diJBw2rRE .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-nrcH5c7diJBw2rRE .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-nrcH5c7diJBw2rRE .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-nrcH5c7diJBw2rRE .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-nrcH5c7diJBw2rRE .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-nrcH5c7diJBw2rRE .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-nrcH5c7diJBw2rRE .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-nrcH5c7diJBw2rRE .cluster text{fill:#333;}#mermaid-svg-nrcH5c7diJBw2rRE .cluster span{color:#333;}#mermaid-svg-nrcH5c7diJBw2rRE div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-nrcH5c7diJBw2rRE .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-nrcH5c7diJBw2rRE rect.text{fill:none;stroke-width:0;}#mermaid-svg-nrcH5c7diJBw2rRE .icon-shape,#mermaid-svg-nrcH5c7diJBw2rRE .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-nrcH5c7diJBw2rRE .icon-shape p,#mermaid-svg-nrcH5c7diJBw2rRE .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-nrcH5c7diJBw2rRE .icon-shape .label rect,#mermaid-svg-nrcH5c7diJBw2rRE .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-nrcH5c7diJBw2rRE .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-nrcH5c7diJBw2rRE .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-nrcH5c7diJBw2rRE :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} iPXE 菜单
HTTP 下载 Clonezilla

内核 + initrd + squashfs
Clonezilla live 启动
NFS 挂载镜像存储
restoredisk 直接写入磁盘
还原完成 → poweroff

特点

  • 快速:直接克隆磁盘镜像,无需逐包安装
  • 一致性:所有还原机器完全相同(包括软件配置、用户、密码)
  • 不依赖外网:只需要 NFS 访问镜像
  • 适用场景:批量部署相同配置的机器

4.3 两种方式对比

#mermaid-svg-UCPtXjh9C4AZwIvj{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-UCPtXjh9C4AZwIvj .error-icon{fill:#552222;}#mermaid-svg-UCPtXjh9C4AZwIvj .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-UCPtXjh9C4AZwIvj .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-UCPtXjh9C4AZwIvj .marker{fill:#333333;stroke:#333333;}#mermaid-svg-UCPtXjh9C4AZwIvj .marker.cross{stroke:#333333;}#mermaid-svg-UCPtXjh9C4AZwIvj svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-UCPtXjh9C4AZwIvj p{margin:0;}#mermaid-svg-UCPtXjh9C4AZwIvj .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-UCPtXjh9C4AZwIvj .cluster-label text{fill:#333;}#mermaid-svg-UCPtXjh9C4AZwIvj .cluster-label span{color:#333;}#mermaid-svg-UCPtXjh9C4AZwIvj .cluster-label span p{background-color:transparent;}#mermaid-svg-UCPtXjh9C4AZwIvj .label text,#mermaid-svg-UCPtXjh9C4AZwIvj span{fill:#333;color:#333;}#mermaid-svg-UCPtXjh9C4AZwIvj .node rect,#mermaid-svg-UCPtXjh9C4AZwIvj .node circle,#mermaid-svg-UCPtXjh9C4AZwIvj .node ellipse,#mermaid-svg-UCPtXjh9C4AZwIvj .node polygon,#mermaid-svg-UCPtXjh9C4AZwIvj .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-UCPtXjh9C4AZwIvj .rough-node .label text,#mermaid-svg-UCPtXjh9C4AZwIvj .node .label text,#mermaid-svg-UCPtXjh9C4AZwIvj .image-shape .label,#mermaid-svg-UCPtXjh9C4AZwIvj .icon-shape .label{text-anchor:middle;}#mermaid-svg-UCPtXjh9C4AZwIvj .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-UCPtXjh9C4AZwIvj .rough-node .label,#mermaid-svg-UCPtXjh9C4AZwIvj .node .label,#mermaid-svg-UCPtXjh9C4AZwIvj .image-shape .label,#mermaid-svg-UCPtXjh9C4AZwIvj .icon-shape .label{text-align:center;}#mermaid-svg-UCPtXjh9C4AZwIvj .node.clickable{cursor:pointer;}#mermaid-svg-UCPtXjh9C4AZwIvj .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-UCPtXjh9C4AZwIvj .arrowheadPath{fill:#333333;}#mermaid-svg-UCPtXjh9C4AZwIvj .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-UCPtXjh9C4AZwIvj .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-UCPtXjh9C4AZwIvj .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-UCPtXjh9C4AZwIvj .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-UCPtXjh9C4AZwIvj .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-UCPtXjh9C4AZwIvj .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-UCPtXjh9C4AZwIvj .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-UCPtXjh9C4AZwIvj .cluster text{fill:#333;}#mermaid-svg-UCPtXjh9C4AZwIvj .cluster span{color:#333;}#mermaid-svg-UCPtXjh9C4AZwIvj div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-UCPtXjh9C4AZwIvj .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-UCPtXjh9C4AZwIvj rect.text{fill:none;stroke-width:0;}#mermaid-svg-UCPtXjh9C4AZwIvj .icon-shape,#mermaid-svg-UCPtXjh9C4AZwIvj .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-UCPtXjh9C4AZwIvj .icon-shape p,#mermaid-svg-UCPtXjh9C4AZwIvj .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-UCPtXjh9C4AZwIvj .icon-shape .label rect,#mermaid-svg-UCPtXjh9C4AZwIvj .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-UCPtXjh9C4AZwIvj .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-UCPtXjh9C4AZwIvj .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-UCPtXjh9C4AZwIvj :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 镜像式
iPXE 菜单
下载 Clonezilla

内核+initrd+squashfs ~550MB
Clonezilla live 启动
NFS 挂载镜像
restoredisk 磁盘克隆

~500MB-2GB
还原完成 → poweroff

约3-5分钟
安装器式
iPXE 菜单
下载内核+initrd

~50MB
安装器启动
下载 preseed/autoinstall

配置文件
从镜像站逐包安装

~300-500MB
配置系统
安装完成

约15-30分钟

4.4 速度对比

方式 Debian 13 Ubuntu 26.04 说明
安装器式 约 15-20 分钟 约 20-30 分钟 取决于镜像站速度和软件包数量
镜像式 约 3-5 分钟 约 3-5 分钟 取决于磁盘大小和 NFS 带宽

镜像式部署的速度主要取决于磁盘大小和网络带宽,与操作系统类型无关。这是批量部署场景下的首选方案。

4.5 本实验的策略

本实验采用两阶段策略

  1. 先安装器式:通过 preseed / autoinstall 装好一台"金盘母机",配置好软件、用户、密码
  2. 再镜像式 :用 Clonezilla savedisk 把金盘母机打包成镜像,后续所有机器用 restoredisk 秒级还原

这样既保留了安装器式的灵活性(金盘可以定制),又获得了镜像式的速度优势(批量部署快速)。


5. Clonezilla 工作原理

Clonezilla 是一个基于 Debian live 的磁盘克隆工具,支持整盘(disk)和分区(partition)级别的备份与恢复。

5.1 savedisk 打包过程

#mermaid-svg-4YxHbZuPL1L5KxXM{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-4YxHbZuPL1L5KxXM .error-icon{fill:#552222;}#mermaid-svg-4YxHbZuPL1L5KxXM .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-4YxHbZuPL1L5KxXM .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-4YxHbZuPL1L5KxXM .marker{fill:#333333;stroke:#333333;}#mermaid-svg-4YxHbZuPL1L5KxXM .marker.cross{stroke:#333333;}#mermaid-svg-4YxHbZuPL1L5KxXM svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-4YxHbZuPL1L5KxXM p{margin:0;}#mermaid-svg-4YxHbZuPL1L5KxXM .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-4YxHbZuPL1L5KxXM .cluster-label text{fill:#333;}#mermaid-svg-4YxHbZuPL1L5KxXM .cluster-label span{color:#333;}#mermaid-svg-4YxHbZuPL1L5KxXM .cluster-label span p{background-color:transparent;}#mermaid-svg-4YxHbZuPL1L5KxXM .label text,#mermaid-svg-4YxHbZuPL1L5KxXM span{fill:#333;color:#333;}#mermaid-svg-4YxHbZuPL1L5KxXM .node rect,#mermaid-svg-4YxHbZuPL1L5KxXM .node circle,#mermaid-svg-4YxHbZuPL1L5KxXM .node ellipse,#mermaid-svg-4YxHbZuPL1L5KxXM .node polygon,#mermaid-svg-4YxHbZuPL1L5KxXM .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-4YxHbZuPL1L5KxXM .rough-node .label text,#mermaid-svg-4YxHbZuPL1L5KxXM .node .label text,#mermaid-svg-4YxHbZuPL1L5KxXM .image-shape .label,#mermaid-svg-4YxHbZuPL1L5KxXM .icon-shape .label{text-anchor:middle;}#mermaid-svg-4YxHbZuPL1L5KxXM .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-4YxHbZuPL1L5KxXM .rough-node .label,#mermaid-svg-4YxHbZuPL1L5KxXM .node .label,#mermaid-svg-4YxHbZuPL1L5KxXM .image-shape .label,#mermaid-svg-4YxHbZuPL1L5KxXM .icon-shape .label{text-align:center;}#mermaid-svg-4YxHbZuPL1L5KxXM .node.clickable{cursor:pointer;}#mermaid-svg-4YxHbZuPL1L5KxXM .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-4YxHbZuPL1L5KxXM .arrowheadPath{fill:#333333;}#mermaid-svg-4YxHbZuPL1L5KxXM .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-4YxHbZuPL1L5KxXM .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-4YxHbZuPL1L5KxXM .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-4YxHbZuPL1L5KxXM .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-4YxHbZuPL1L5KxXM .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-4YxHbZuPL1L5KxXM .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-4YxHbZuPL1L5KxXM .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-4YxHbZuPL1L5KxXM .cluster text{fill:#333;}#mermaid-svg-4YxHbZuPL1L5KxXM .cluster span{color:#333;}#mermaid-svg-4YxHbZuPL1L5KxXM div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-4YxHbZuPL1L5KxXM .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-4YxHbZuPL1L5KxXM rect.text{fill:none;stroke-width:0;}#mermaid-svg-4YxHbZuPL1L5KxXM .icon-shape,#mermaid-svg-4YxHbZuPL1L5KxXM .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-4YxHbZuPL1L5KxXM .icon-shape p,#mermaid-svg-4YxHbZuPL1L5KxXM .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-4YxHbZuPL1L5KxXM .icon-shape .label rect,#mermaid-svg-4YxHbZuPL1L5KxXM .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-4YxHbZuPL1L5KxXM .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-4YxHbZuPL1L5KxXM .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-4YxHbZuPL1L5KxXM :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Clonezilla live 启动
挂载 NFS 存储到 /home/partimag
选择 savedisk 模式
选择源盘 sda
读取分区表 + MBR/GPT
逐分区压缩打包

使用 zstd 压缩
生成镜像元数据文件
写入 NFS 存储
校验镜像完整性
完成 → poweroff

5.2 镜像目录结构

以 Debian 13 金盘镜像 debian13-img 为例:

复制代码
/home/partimag/debian13-img/
├── disk                         # 磁盘设备名(sda)
├── parts                        # 分区列表(sda1 sda5)
├── clonezilla-img               # 镜像元数据
├── sda-mbr                      # 主引导记录备份
├── sda-pt.sf                    # 分区表备份(sfdisk 格式)
├── sda1.ext4-ptcl-img.zst       # sda1 分区镜像(ext4,zstd 压缩)
├── sda5.swap-ptcl-img.zst       # sda5 分区镜像(swap)
├── blkdev.list                  # 块设备列表
├── blkid.list                   # 分区 UUID
├── fdisk.list                   # 分区表信息
├── Info-dmi.txt                 # 硬件 DMI 信息
├── Info-lshw.txt                # 硬件信息
└── Info-smart.txt               # SMART 信息

以 Ubuntu 26.04 金盘镜像 ubuntu26.img 为例(LVM 布局):

复制代码
/home/partimag/ubuntu26.img/
├── disk
├── parts
├── clonezilla-img
├── sda-gpt-1st / sda-gpt-2nd    # GPT 头备份
├── sda1.dd-ptcl-img.zst         # ESP 分区(dd 模式)
├── sda2.ext4-ptcl-img.zst       # boot 分区(ext4)
├── ubuntu-vg-ubuntu-lv.ext4-ptcl-img.zst  # LVM 根分区
├── lvm_ubuntu-vg.conf           # LVM 配置
└── Info-*.txt

5.3 restoredisk 还原过程

#mermaid-svg-gLew6urXrjOx33QP{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-gLew6urXrjOx33QP .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-gLew6urXrjOx33QP .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-gLew6urXrjOx33QP .error-icon{fill:#552222;}#mermaid-svg-gLew6urXrjOx33QP .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-gLew6urXrjOx33QP .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-gLew6urXrjOx33QP .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-gLew6urXrjOx33QP .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-gLew6urXrjOx33QP .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-gLew6urXrjOx33QP .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-gLew6urXrjOx33QP .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-gLew6urXrjOx33QP .marker{fill:#333333;stroke:#333333;}#mermaid-svg-gLew6urXrjOx33QP .marker.cross{stroke:#333333;}#mermaid-svg-gLew6urXrjOx33QP svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-gLew6urXrjOx33QP p{margin:0;}#mermaid-svg-gLew6urXrjOx33QP .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-gLew6urXrjOx33QP .cluster-label text{fill:#333;}#mermaid-svg-gLew6urXrjOx33QP .cluster-label span{color:#333;}#mermaid-svg-gLew6urXrjOx33QP .cluster-label span p{background-color:transparent;}#mermaid-svg-gLew6urXrjOx33QP .label text,#mermaid-svg-gLew6urXrjOx33QP span{fill:#333;color:#333;}#mermaid-svg-gLew6urXrjOx33QP .node rect,#mermaid-svg-gLew6urXrjOx33QP .node circle,#mermaid-svg-gLew6urXrjOx33QP .node ellipse,#mermaid-svg-gLew6urXrjOx33QP .node polygon,#mermaid-svg-gLew6urXrjOx33QP .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-gLew6urXrjOx33QP .rough-node .label text,#mermaid-svg-gLew6urXrjOx33QP .node .label text,#mermaid-svg-gLew6urXrjOx33QP .image-shape .label,#mermaid-svg-gLew6urXrjOx33QP .icon-shape .label{text-anchor:middle;}#mermaid-svg-gLew6urXrjOx33QP .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-gLew6urXrjOx33QP .rough-node .label,#mermaid-svg-gLew6urXrjOx33QP .node .label,#mermaid-svg-gLew6urXrjOx33QP .image-shape .label,#mermaid-svg-gLew6urXrjOx33QP .icon-shape .label{text-align:center;}#mermaid-svg-gLew6urXrjOx33QP .node.clickable{cursor:pointer;}#mermaid-svg-gLew6urXrjOx33QP .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-gLew6urXrjOx33QP .arrowheadPath{fill:#333333;}#mermaid-svg-gLew6urXrjOx33QP .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-gLew6urXrjOx33QP .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-gLew6urXrjOx33QP .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-gLew6urXrjOx33QP .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-gLew6urXrjOx33QP .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-gLew6urXrjOx33QP .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-gLew6urXrjOx33QP .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-gLew6urXrjOx33QP .cluster text{fill:#333;}#mermaid-svg-gLew6urXrjOx33QP .cluster span{color:#333;}#mermaid-svg-gLew6urXrjOx33QP div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-gLew6urXrjOx33QP .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-gLew6urXrjOx33QP rect.text{fill:none;stroke-width:0;}#mermaid-svg-gLew6urXrjOx33QP .icon-shape,#mermaid-svg-gLew6urXrjOx33QP .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-gLew6urXrjOx33QP .icon-shape p,#mermaid-svg-gLew6urXrjOx33QP .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-gLew6urXrjOx33QP .icon-shape .label rect,#mermaid-svg-gLew6urXrjOx33QP .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-gLew6urXrjOx33QP .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-gLew6urXrjOx33QP .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-gLew6urXrjOx33QP :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Clonezilla live 启动
通过 ocs_prerun 自动挂载 NFS
ocs-sr 执行 restoredisk
读取镜像元数据
恢复 MBR/GPT 分区表
逐分区解压写入磁盘
如有 LVM 则恢复 LVM 配置
更新 GRUB 引导
-p poweroff 自动关机

5.4 NFS 存储机制

Clonezilla 默认使用 /home/partimag 作为镜像存储目录。

工作方式

  1. 服务器端通过 NFS 导出 /home/partimag 目录
  2. Clonezilla 客户端通过 NFS 挂载到本地 /home/partimag
  3. savedisk 时将镜像写入该目录
  4. restoredisk 时从该目录读取镜像

自动挂载 :在全自动还原模式下,通过 ocs_prerun 参数在 Clonezilla 启动时自动挂载 NFS:

text 复制代码
ocs_prerun="mount -t nfs 192.xxx.xxx.xxx:/home/partimag /home/partimag"

关键坑 :Clonezilla 的 NFS 服务器配置框只填纯 IP 地址 (如 192.xxx.xxx.xxx),不要填路径。Clonezilla 会自动追加 /home/partimag,如果填了 192.xxx.xxx.xxx:/srv/images,路径会拼接成 /srv/images:/home/partimag/,导致 access denied。

5.5 ocs-sr 命令参数详解

全自动还原使用的核心命令:

text 复制代码
ocs-sr -g auto -e1 auto -e2 -r -j2 -p poweroff restoredisk debian13-img sda
参数 含义
ocs-sr Clonezilla Save/Restore 主命令
-g auto 自动安装 GRUB 引导程序到目标盘
-e1 auto 自动调整文件系统大小到目标盘
-e2 还原后执行 fsck 检查文件系统
-r 如果目标盘大于金盘,自动调整分区大小
-j2 保留原分区 UUID(避免 UUID 变化导致的问题)
-p poweroff 还原完成后自动关机
restoredisk 操作模式:还原整盘
debian13-img 镜像名称(对应 /home/partimag/debian13-img/
sda 目标磁盘设备名

6. boot.ipxe 脚本语法简介

以下是实验中使用的真实 boot.ipxe 菜单脚本(从运行中的服务器通过 HTTP 下载):

ipxe 复制代码
#!ipxe

set server_ip 192.xxx.xxx.xxx

menu 请选择要安装的操作系统
item --key 1 debian13    1) Debian13 - 金盘还原(全自动)
item --key 2 ubuntu26    2) Ubuntu26 - 全新安装(做金盘用)
item --key 3 clonezilla  3) Clonezilla - 手动模式
choose --default debian13 --timeout 10000 target && goto ${target}

:debian13
kernel http://${server_ip}/clonezilla/vmlinuz
initrd http://${server_ip}/clonezilla/initrd.img
imgargs vmlinuz boot=live union=overlay username=user config components noswap noprompt locales=en_US.UTF-8 keyboard-layouts=us ocs_live_keymap=NONE ocs_lang=en_US.UTF-8 ocs_live_batch=yes ocs_live_run="ocs-sr -g auto -e1 auto -e2 -r -j2 -p poweroff restoredisk debian13-img sda" ocs_prerun="mount -t nfs 192.xxx.xxx.xxx:/home/partimag /home/partimag" vga=788 fetch=http://${server_ip}/clonezilla/filesystem.squashfs
boot

:ubuntu26
kernel http://${server_ip}/ubuntu26/linux
initrd http://${server_ip}/ubuntu26/initrd.gz
imgargs linux autoinstall ds=nocloud-net;s=http://${server_ip}/ubuntu26/ --- quiet
boot

:clonezilla
kernel http://${server_ip}/clonezilla/vmlinuz
initrd http://${server_ip}/clonezilla/initrd.img
imgargs vmlinuz boot=live union=overlay username=user config components noswap ocs_live_run=ocs-live-general ocs_live_batch=no vga=788 fetch=http://${server_ip}/clonezilla/filesystem.squashfs
boot

6.1 基本语法

语法 作用 示例
#!ipxe iPXE 脚本声明 必须在第一行
set 变量名 值 定义变量 set server_ip 192.xxx.xxx.xxx
${变量名} 引用变量 http://${server_ip}/boot.ipxe
menu 标题 显示菜单 menu 请选择要安装的操作系统
item --key N 标签 显示文字 添加菜单项 item --key 1 debian13 1) Debian13
choose --default 项 --timeout 毫秒 变量 等待选择 choose --default debian13 --timeout 10000 target
goto 标签 跳转 goto ${target}
:标签 标签定义 :debian13
kernel URL 下载内核 kernel http://.../vmlinuz
initrd URL 下载 initrd initrd http://.../initrd.img
imgargs 内核名 参数... 设置内核参数 imgargs vmlinuz boot=live ...
boot 启动内核 boot
chain URL 加载另一个 iPXE 脚本 chain http://.../restore.ipxe

6.2 三个菜单项说明

菜单 模式 说明
1) Debian13 金盘还原 镜像式(全自动) Clonezilla restoredisk 还原 debian13-img,10秒超时默认选中,ocs_live_batch=yes 跳过所有交互
2) Ubuntu26 全新安装 安装器式 autoinstall + nocloud-net 无人值守安装,用于制作金盘母机
3) Clonezilla 手动 交互式 进入 Clonezilla 手动模式,可做 savedisk 打包或 restoredisk 还原

6.3 imgargs 参数分类

菜单 1(Debian13 金盘还原)的 imgargs 参数可以分为几类:

Clonezilla live 引导参数(让 Clonezilla live 正常启动):

参数 含义
boot=live 以 live 模式启动
union=overlay 使用 overlay 联合文件系统
username=user live 系统用户名
config 加载 live 配置
components 加载额外组件
noswap 不自动挂载 swap
noprompt 不等待用户确认
locales=en_US.UTF-8 语言设置
keyboard-layouts=us 键盘布局
ocs_live_keymap=NONE Clonezilla 不询问键盘布局
ocs_lang=en_US.UTF-8 Clonezilla 语言
vga=788 设置显示模式(800x600)

Clonezilla 自动操作参数(实现全自动还原):

参数 含义
ocs_live_batch=yes 批处理模式,跳过所有交互确认(注意:不能加引号!)
ocs_live_run="ocs-sr ..." 启动后自动执行的命令
ocs_prerun="mount -t nfs ..." 在 ocs_live_run 之前执行的预处理命令

文件获取参数

参数 含义
fetch=http://.../filesystem.squashfs 通过 HTTP 下载 Clonezilla live 根文件系统

6.4 菜单 1 vs 菜单 3 的差异

参数 菜单 1(全自动还原) 菜单 3(手动模式)
ocs_live_run ocs-sr -g auto ... restoredisk debian13-img sda ocs-live-general(进入交互菜单)
ocs_live_batch yes(跳过所有确认) no(需要手动确认)
ocs_prerun 自动挂载 NFS 无(需要手动选择存储)
noprompt
locales/keyboard 无(使用默认)
-p poweroff 有(还原完自动关机)

6.5 菜单 2(Ubuntu autoinstall)参数说明

ipxe 复制代码
imgargs linux autoinstall ds=nocloud-net;s=http://${server_ip}/ubuntu26/ --- quiet
参数 含义
autoinstall 启用 Ubuntu autoinstall 无人值守安装
ds=nocloud-net;s=http://... 指定 nocloud 数据源 URL(从该路径读取 user-datameta-data
--- 分隔内核参数和 init 参数
quiet 安静模式,减少输出

注意 :nocloud 数据源只认 user-datameta-data 文件名,不认 autoinstall.yaml。这是 Ubuntu autoinstall 的一个常见坑点。


小结

本实验的完整装机链路可以概括为:

  1. 基础环境:VMware + VMnet2 + 双网卡服务器 + DHCP/TFTP/HTTP/NFS 四件套
  2. 引导链路:PXE → TFTP(undionly.kpxe) → iPXE → HTTP(boot.ipxe) → 内核启动
  3. 部署策略:先安装器式装金盘母机 → Clonezilla savedisk 打包 → restoredisk 批量还原
  4. 自动化 :通过 imgargs 传入 ocs_live_run + ocs_prerun + ocs_live_batch=yes 实现全自动还原

后续文档将详细介绍环境搭建、软件配置、配置文件模板、金盘制作与还原、踩坑排障等内容。

相关推荐
虎头金猫1 小时前
如何在群晖NAS上通过Docker部署CloudSaver?群晖部署CloudSaver教程|聚合资源搜索并实现远程访问
运维·服务器·网络·python·docker·容器·pandas
dog2501 小时前
网络优化,还是降低各阶矩
服务器·网络·php
反转180度2 小时前
Qt 6 + C++17 实现 SFTP 批量部署:工业设备运维工具实战解析
运维·c++·qt
liuqs3322 小时前
nat123安卓和nat123全端口选型指南,映射工具怎么挑
网络·笔记
雨辰AI2 小时前
RAG 知识库搭建:基于人大金仓构建信创运维问答机器人|全栈国产化落地完整版
运维·ai·机器人·ai编程
x_x-F3 小时前
网络数据从网卡到用户态:一场基于内存所有权转移的接力赛
开发语言·网络·php
-今昭-3 小时前
Ansible
linux·运维·ansible
星野川崎2063 小时前
电商多店运维:云机长期挂机频繁掉线、账号无故风控原因剖析与解决方案
大数据·运维·云计算·电商
mounter6254 小时前
MACsec 全景解析:从技术演进、核心架构到 DPU 硬件卸载与 K8s 大规模调度实战
linux·kubernetes·linux kernel·kernel·macsec