05 - 黄金镜像与全自动还原

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

目录

  1. 金盘母机准备
  2. [Clonezilla savedisk 打包过程](#Clonezilla savedisk 打包过程)
  3. [Clonezilla restoredisk 还原过程](#Clonezilla restoredisk 还原过程)
  4. 全自动还原脚本详解
  5. [savedisk / restoredisk 流程图](#savedisk / restoredisk 流程图)
  6. 注意事项

1. 金盘母机准备

金盘母机是后续所有批量部署的"模板机器"。母机上安装好的软件、配置的用户和密码、网络设置等,都会被 Clonezilla 完整克隆到每一台目标机器上。

1.1 Debian 13 金盘母机

安装系统

通过 iPXE 菜单选择安装器式部署,使用 preseed 无人值守安装:

  1. 客户机 VM 从 PXE 启动
  2. iPXE 菜单出现后选择安装 Debian 13(如果菜单中没有安装选项,可通过 imgargs 传入 auto=true url=http://192.168.xxx.10/debian13/preseed.cfg
  3. preseed 自动完成安装(约 15-20 分钟)
  4. 安装完成后系统自动重启
金盘出厂整理

安装完成后,登录系统进行"出厂整理":

bash 复制代码
# 1. 以 root 登录(密码 zxcvbn)

# 2. 配置 SSH root 登录
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart sshd

# 3. 预装常用软件
apt update
apt install -y htop net-tools vim

# 4. 清理缓存和日志
apt clean
rm -rf /var/log/*.log /var/log/*.gz
rm -rf /var/cache/apt/archives/*.deb

# 5. 清除命令历史
history -c

# 6. 关机
poweroff
金盘信息
项目
主机名 pxe-debian
root 密码 zxcvbn
分区结构 sda1(ext4) + sda5(swap)
预装软件 htop, net-tools, vim, openssh-server, curl, wget
金盘 IP(装机时) 192.168.xxx.53(DHCP 分配)

1.2 Ubuntu 26.04 金盘母机

安装系统

Ubuntu 26.04 通过手动挂载 ISO 安装(也可以通过 autoinstall 无人值守安装):

  1. VMware 挂载 ISO:编辑虚拟机设置 → CD/DVD → 选择 Ubuntu 26.04 ISO → 勾选"启动时连接"
  2. 从 CD 启动:开机按 ESC → 选择 CD-ROM Drive
  3. 安装配置
    • 语言/键盘:English / English (US)
    • 用户名:ubuntu
    • 密码:xxx
    • 磁盘:Use Entire Disk(Subiquity 默认使用 LVM 布局)
    • 勾选 Install OpenSSH server
  4. 装完提示重启 → 不要重启,先关机(VMware 强制关电)
金盘出厂整理
bash 复制代码
# 1. 以 ubuntu 用户登录,切换到 root
sudo -i

# 2. 设置 root 密码
echo "root:xxx" | chpasswd

# 3. 配置 SSH root 登录
sed -i 's/^#*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
systemctl restart sshd

# 4. 预装常用软件
apt update
apt install -y htop net-tools vim

# 5. 清理
apt clean
rm -rf /var/log/*.log /var/log/*.gz
history -c

# 6. 关机
poweroff
金盘信息
项目
主机名 pxe-ubuntu
用户名 ubuntu
密码 xxx
root 密码 xxx
分区结构 sda1(ESP) + sda2(ext4 boot) + ubuntu-vg/ubuntu-lv(LVM 根)
预装软件 openssh-server, curl, wget, vim

1.3 切换到 PXE 启动

金盘母机关机后,需要将启动方式从硬盘/光驱切换为 PXE 网络启动:

  1. VMware 编辑虚拟机设置 → CD/DVD → 取消勾选"启动时连接"
  2. 开机按 ESC 进入 BIOS Setup
  3. 调整启动顺序 :光标移到 Network boot from Intel E1000,按 + 上移到第一位
  4. F10 保存退出

这样下次开机就会直接从 PXE 启动,进入 iPXE 菜单。


2. Clonezilla savedisk 打包过程

2.1 进入 Clonezilla 手动模式

  1. 客户机从 PXE 启动
  2. iPXE 菜单出现后,10 秒内按 3 选择 Clonezilla 手动模式
  3. 等待 Clonezilla live 启动(通过 HTTP 下载 vmlinuz + initrd + squashfs)

⚠️ 不要超时进入菜单 1(Debian13 金盘还原),否则会自动还原 Debian13 到 sda,覆盖金盘母机上的系统!

2.2 savedisk 菜单选择路径

进入 Clonezilla 后,按以下步骤选择:
#mermaid-svg-tdIO9XcsYU9BK3I1{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-tdIO9XcsYU9BK3I1 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-tdIO9XcsYU9BK3I1 .error-icon{fill:#552222;}#mermaid-svg-tdIO9XcsYU9BK3I1 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-tdIO9XcsYU9BK3I1 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .marker.cross{stroke:#333333;}#mermaid-svg-tdIO9XcsYU9BK3I1 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-tdIO9XcsYU9BK3I1 p{margin:0;}#mermaid-svg-tdIO9XcsYU9BK3I1 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .cluster-label text{fill:#333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .cluster-label span{color:#333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .cluster-label span p{background-color:transparent;}#mermaid-svg-tdIO9XcsYU9BK3I1 .label text,#mermaid-svg-tdIO9XcsYU9BK3I1 span{fill:#333;color:#333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .node rect,#mermaid-svg-tdIO9XcsYU9BK3I1 .node circle,#mermaid-svg-tdIO9XcsYU9BK3I1 .node ellipse,#mermaid-svg-tdIO9XcsYU9BK3I1 .node polygon,#mermaid-svg-tdIO9XcsYU9BK3I1 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-tdIO9XcsYU9BK3I1 .rough-node .label text,#mermaid-svg-tdIO9XcsYU9BK3I1 .node .label text,#mermaid-svg-tdIO9XcsYU9BK3I1 .image-shape .label,#mermaid-svg-tdIO9XcsYU9BK3I1 .icon-shape .label{text-anchor:middle;}#mermaid-svg-tdIO9XcsYU9BK3I1 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-tdIO9XcsYU9BK3I1 .rough-node .label,#mermaid-svg-tdIO9XcsYU9BK3I1 .node .label,#mermaid-svg-tdIO9XcsYU9BK3I1 .image-shape .label,#mermaid-svg-tdIO9XcsYU9BK3I1 .icon-shape .label{text-align:center;}#mermaid-svg-tdIO9XcsYU9BK3I1 .node.clickable{cursor:pointer;}#mermaid-svg-tdIO9XcsYU9BK3I1 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .arrowheadPath{fill:#333333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-tdIO9XcsYU9BK3I1 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-tdIO9XcsYU9BK3I1 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-tdIO9XcsYU9BK3I1 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-tdIO9XcsYU9BK3I1 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-tdIO9XcsYU9BK3I1 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-tdIO9XcsYU9BK3I1 .cluster text{fill:#333;}#mermaid-svg-tdIO9XcsYU9BK3I1 .cluster span{color:#333;}#mermaid-svg-tdIO9XcsYU9BK3I1 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-tdIO9XcsYU9BK3I1 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-tdIO9XcsYU9BK3I1 rect.text{fill:none;stroke-width:0;}#mermaid-svg-tdIO9XcsYU9BK3I1 .icon-shape,#mermaid-svg-tdIO9XcsYU9BK3I1 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-tdIO9XcsYU9BK3I1 .icon-shape p,#mermaid-svg-tdIO9XcsYU9BK3I1 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-tdIO9XcsYU9BK3I1 .icon-shape .label rect,#mermaid-svg-tdIO9XcsYU9BK3I1 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-tdIO9XcsYU9BK3I1 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-tdIO9XcsYU9BK3I1 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-tdIO9XcsYU9BK3I1 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Clonezilla 启动
选择语言

en_US.UTF-8 English
键盘布局

Don't touch keymap
Start Clonezilla
模式: device-image
镜像存储: nfs_server
NFS 服务器 IP:

192.168.xxx.10

⚠️ 只填纯 IP,不填路径!
NFS 挂载点:

默认 /home/partimag
模式: Beginner
操作: savedisk
输入镜像名:

debian13-img 或 ubuntu26.img
选择源盘: sda

空格勾选
压缩方式: -z3p

zstd 多线程
校验镜像: Yes
加密: No
复制日志到 USB: No
确认打包: y
开始打包...
打包完成
选择: poweroff

⚠️ 不能选 reboot!

2.3 详细步骤说明

步骤 选择 说明
1. 语言 en_US.UTF-8 English 默认高亮,直接 Enter
2. 键盘 Don't touch keymap 不修改键盘布局
3. 启动 Start Clonezilla 不选 Enter shell
4. 模式 device-image 镜像模式(不是 device-disk)
5. 存储 nfs_server 通过 NFS 存储镜像
6. NFS IP 192.168.xxx.10 只填纯 IP!不填路径!
7. NFS 路径 默认 /home/partimag Clonezilla 自动追加
8. 级别 Beginner 初学者模式
9. 操作 savedisk 打包整盘
10. 镜像名 debian13-imgubuntu26.img 自定义名称
11. 源盘 sda 空格勾选,Tab 到 OK
12. 压缩 -z3p zstd 多线程压缩
13. 校验 Yes 打包完校验镜像完整性
14. 加密 No 不加密镜像
15. 日志 No 不复制日志到 USB
16. 确认 y 最终确认开始打包
17. 完成后 poweroff 不能选 reboot!

2.4 关键注意事项

⚠️ NFS 服务器框只填纯 IP

Clonezilla 会自动在 IP 后面追加 :/home/partimag。如果你填了 192.168.xxx.10:/srv/images,路径会拼接成 192.168.xxx.10:/srv/images:/home/partimag/,导致 NFS access denied。

正确做法:服务器端导出 /home/partimag,客户端只填 192.168.xxx.10
⚠️ 打包完必须选 poweroff

如果选了 reboot,客户机重启后会从 PXE 启动,iPXE 菜单默认 10 秒超时会自动进入 Debian13 金盘还原,把刚打包好的金盘母机系统覆盖掉!

一定要选 poweroff!

2.5 镜像打包结果

打包完成后,镜像存储在服务器的 /home/partimag/ 目录下:

Debian 13 镜像debian13-img):

文件 说明 大小
sda1.ext4-ptcl-img.zst sda1 分区镜像(ext4,zstd 压缩) ~500MB
sda5.swap-ptcl-img.zst sda5 分区镜像(swap) 极小
sda-mbr 主引导记录 512B
disk / parts 磁盘和分区信息 极小
clonezilla-img 镜像元数据 ~9KB
总计 ~522MB

Ubuntu 26.04 镜像ubuntu26.img):

文件 说明 大小
sda1.dd-ptcl-img.zst ESP 分区(dd 模式) ~57KB
sda2.ext4-ptcl-img.zst boot 分区(ext4) ~172MB
ubuntu-vg-ubuntu-lv.ext4-ptcl-img.zst LVM 根分区 ~1.7GB
sda-gpt-1st / 2nd GPT 头备份 ~17KB
lvm_ubuntu-vg.conf LVM 配置 ~1.3KB
总计 ~1.9GB

3. Clonezilla restoredisk 还原过程

3.1 新建空白 VM

  1. 创建新虚拟机

    • 网络:VMnet2(与服务器同一网络)
    • 磁盘:≥ 10G(必须 ≥ 金盘大小)
    • 光驱:无 ISO(不需要光驱)
    • 启动方式:BIOS(不是 UEFI)
    • 启动顺序:Network boot 优先
  2. 开机:虚拟机会从 PXE 启动,进入 iPXE 菜单

3.2 全自动还原

  1. iPXE 菜单出现后,不操作,等 10 秒超时
  2. 默认选中菜单 1(Debian13 金盘还原),10 秒后自动开始
  3. Clonezilla live 启动 → 自动挂载 NFS → ocs-sr restoredisk → 写入磁盘 → poweroff

如果要还原 Ubuntu 26.04,在 10 秒内按 2 选择 Ubuntu26 菜单(需提前将 :ubuntu26 段改为 Clonezilla 还原路径)。

3.3 还原后调整 BIOS 启动顺序

⚠️ 这一步非常重要!

还原完成后机器自动关机。如果不调整 BIOS 启动顺序,下次开机会再次从 PXE 启动,10 秒超时后又自动还原------陷入无限循环。

  1. 开机按 ESC 进入 BIOS Setup
  2. +Hard Drive 移到第一位(按 + 上移)
  3. F10 保存退出

3.4 验证

  1. 机器从硬盘启动,进入操作系统
  2. 使用 root 登录(密码 zxcvbn
  3. 验证系统配置:
bash 复制代码
# 检查主机名
hostname

# 检查磁盘
df -h
lsblk

# 检查网络
ip addr

# 检查预装软件
which htop vim curl

4. 全自动还原脚本详解

4.1 boot.ipxe 菜单 1(Debian13 全自动还原)

以下是 boot.ipxe 中菜单 1 的完整配置:

ipxe 复制代码
: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.168.xxx.10:/home/partimag /home/partimag" vga=788 fetch=http://${server_ip}/clonezilla/filesystem.squashfs
boot

4.2 逐参数详解

kernel / initrd:下载启动文件
含义
kernel http://.../clonezilla/vmlinuz 通过 HTTP 下载 Clonezilla 内核
initrd http://.../clonezilla/initrd.img 通过 HTTP 下载 Clonezilla initrd
Clonezilla live 引导参数
参数 含义 不设会怎样
boot=live 以 live 模式启动 无法启动
union=overlay overlay 联合文件系统 文件系统可能只读
username=user live 用户名 使用默认值
config 加载 live 配置 可能缺少某些配置
components 加载额外组件 可能缺少驱动
noswap 不挂载 swap 可能挂载到错误的 swap
noprompt 不等待确认 卡在确认界面
locales=en_US.UTF-8 语言环境 卡在语言选择
keyboard-layouts=us 键盘布局 卡在键盘布局选择
ocs_live_keymap=NONE Clonezilla 不问键盘 卡在 "Change keyboard layout?"
ocs_lang=en_US.UTF-8 Clonezilla 语言 使用默认值
vga=788 显示模式 800x600 可能分辨率不对
Clonezilla 自动操作参数
参数 含义 不设会怎样
ocs_live_batch=yes 批处理模式,跳过所有交互 每一步都要手动确认
ocs_live_run="ocs-sr ..." 自动执行的还原命令 进入 Clonezilla 交互菜单
ocs_prerun="mount -t nfs ..." 预处理:自动挂载 NFS 需要手动选择存储

⚠️ ocs_live_batch=yes 不能加引号ocs_live_batch="yes" 会导致引号被当字面值传入,批处理模式失效。

ocs_live_run 命令逐参数
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 目标磁盘设备名
ocs_prerun 命令
text 复制代码
mount -t nfs 192.168.xxx.10:/home/partimag /home/partimag

ocs_live_run 执行之前,先挂载 NFS 镜像存储到本地 /home/partimag。这样 Clonezilla 就能读取到镜像文件。

fetch 参数
text 复制代码
fetch=http://192.168.xxx.10/clonezilla/filesystem.squashfs

通过 HTTP 下载 Clonezilla live 的根文件系统(488MB)。这个参数让 Clonezilla live 从 HTTP 获取 squashfs 而不是从本地存储。

4.3 菜单 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 mount -t nfs ...
noprompt
locales / keyboard-layouts
-p poweroff
交互程度 零交互,全自动 每步需手动选择

4.4 改为 Ubuntu 26.04 金盘还原

:ubuntu26 段从 autoinstall 改为 Clonezilla 还原,只需复制 :debian13 段并修改镜像名:

ipxe 复制代码
:ubuntu26
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 ubuntu26.img sda" ocs_prerun="mount -t nfs 192.168.xxx.10:/home/partimag /home/partimag" vga=788 fetch=http://${server_ip}/clonezilla/filesystem.squashfs
boot

:debian13 唯一的区别是镜像名从 debian13-img 改为 ubuntu26.img


5. savedisk / restoredisk 流程图

5.1 savedisk 打包流程

#mermaid-svg-1NSsGAGVvBqhxoos{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-1NSsGAGVvBqhxoos .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-1NSsGAGVvBqhxoos .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-1NSsGAGVvBqhxoos .error-icon{fill:#552222;}#mermaid-svg-1NSsGAGVvBqhxoos .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-1NSsGAGVvBqhxoos .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-1NSsGAGVvBqhxoos .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-1NSsGAGVvBqhxoos .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-1NSsGAGVvBqhxoos .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-1NSsGAGVvBqhxoos .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-1NSsGAGVvBqhxoos .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-1NSsGAGVvBqhxoos .marker{fill:#333333;stroke:#333333;}#mermaid-svg-1NSsGAGVvBqhxoos .marker.cross{stroke:#333333;}#mermaid-svg-1NSsGAGVvBqhxoos svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-1NSsGAGVvBqhxoos p{margin:0;}#mermaid-svg-1NSsGAGVvBqhxoos .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-1NSsGAGVvBqhxoos .cluster-label text{fill:#333;}#mermaid-svg-1NSsGAGVvBqhxoos .cluster-label span{color:#333;}#mermaid-svg-1NSsGAGVvBqhxoos .cluster-label span p{background-color:transparent;}#mermaid-svg-1NSsGAGVvBqhxoos .label text,#mermaid-svg-1NSsGAGVvBqhxoos span{fill:#333;color:#333;}#mermaid-svg-1NSsGAGVvBqhxoos .node rect,#mermaid-svg-1NSsGAGVvBqhxoos .node circle,#mermaid-svg-1NSsGAGVvBqhxoos .node ellipse,#mermaid-svg-1NSsGAGVvBqhxoos .node polygon,#mermaid-svg-1NSsGAGVvBqhxoos .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-1NSsGAGVvBqhxoos .rough-node .label text,#mermaid-svg-1NSsGAGVvBqhxoos .node .label text,#mermaid-svg-1NSsGAGVvBqhxoos .image-shape .label,#mermaid-svg-1NSsGAGVvBqhxoos .icon-shape .label{text-anchor:middle;}#mermaid-svg-1NSsGAGVvBqhxoos .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-1NSsGAGVvBqhxoos .rough-node .label,#mermaid-svg-1NSsGAGVvBqhxoos .node .label,#mermaid-svg-1NSsGAGVvBqhxoos .image-shape .label,#mermaid-svg-1NSsGAGVvBqhxoos .icon-shape .label{text-align:center;}#mermaid-svg-1NSsGAGVvBqhxoos .node.clickable{cursor:pointer;}#mermaid-svg-1NSsGAGVvBqhxoos .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-1NSsGAGVvBqhxoos .arrowheadPath{fill:#333333;}#mermaid-svg-1NSsGAGVvBqhxoos .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-1NSsGAGVvBqhxoos .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-1NSsGAGVvBqhxoos .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-1NSsGAGVvBqhxoos .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-1NSsGAGVvBqhxoos .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-1NSsGAGVvBqhxoos .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-1NSsGAGVvBqhxoos .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-1NSsGAGVvBqhxoos .cluster text{fill:#333;}#mermaid-svg-1NSsGAGVvBqhxoos .cluster span{color:#333;}#mermaid-svg-1NSsGAGVvBqhxoos 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-1NSsGAGVvBqhxoos .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-1NSsGAGVvBqhxoos rect.text{fill:none;stroke-width:0;}#mermaid-svg-1NSsGAGVvBqhxoos .icon-shape,#mermaid-svg-1NSsGAGVvBqhxoos .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-1NSsGAGVvBqhxoos .icon-shape p,#mermaid-svg-1NSsGAGVvBqhxoos .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-1NSsGAGVvBqhxoos .icon-shape .label rect,#mermaid-svg-1NSsGAGVvBqhxoos .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-1NSsGAGVvBqhxoos .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-1NSsGAGVvBqhxoos .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-1NSsGAGVvBqhxoos :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 金盘母机准备完成

已关机
VMware BIOS

Network boot 设为第一启动项
开机 → PXE 启动
iPXE 菜单

10秒内按 3 选 Clonezilla 手动
Clonezilla live 启动

HTTP 下载 vmlinuz + initrd + squashfs
选择语言/键盘
device-image 模式
NFS 挂载

服务器填纯 IP 192.168.xxx.10
Beginner → savedisk
输入镜像名

选择源盘 sda
压缩 -z3p

校验 Yes

不加密

不复制日志
开始打包

逐分区压缩写入 NFS
打包完成
选择 poweroff 关机

⚠️ 不能选 reboot!
镜像存入

/home/partimag/镜像名/

5.2 restoredisk 还原流程

#mermaid-svg-xPzkYottZ0ktrBZv{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-xPzkYottZ0ktrBZv .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-xPzkYottZ0ktrBZv .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-xPzkYottZ0ktrBZv .error-icon{fill:#552222;}#mermaid-svg-xPzkYottZ0ktrBZv .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-xPzkYottZ0ktrBZv .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-xPzkYottZ0ktrBZv .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-xPzkYottZ0ktrBZv .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-xPzkYottZ0ktrBZv .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-xPzkYottZ0ktrBZv .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-xPzkYottZ0ktrBZv .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-xPzkYottZ0ktrBZv .marker{fill:#333333;stroke:#333333;}#mermaid-svg-xPzkYottZ0ktrBZv .marker.cross{stroke:#333333;}#mermaid-svg-xPzkYottZ0ktrBZv svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-xPzkYottZ0ktrBZv p{margin:0;}#mermaid-svg-xPzkYottZ0ktrBZv .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-xPzkYottZ0ktrBZv .cluster-label text{fill:#333;}#mermaid-svg-xPzkYottZ0ktrBZv .cluster-label span{color:#333;}#mermaid-svg-xPzkYottZ0ktrBZv .cluster-label span p{background-color:transparent;}#mermaid-svg-xPzkYottZ0ktrBZv .label text,#mermaid-svg-xPzkYottZ0ktrBZv span{fill:#333;color:#333;}#mermaid-svg-xPzkYottZ0ktrBZv .node rect,#mermaid-svg-xPzkYottZ0ktrBZv .node circle,#mermaid-svg-xPzkYottZ0ktrBZv .node ellipse,#mermaid-svg-xPzkYottZ0ktrBZv .node polygon,#mermaid-svg-xPzkYottZ0ktrBZv .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-xPzkYottZ0ktrBZv .rough-node .label text,#mermaid-svg-xPzkYottZ0ktrBZv .node .label text,#mermaid-svg-xPzkYottZ0ktrBZv .image-shape .label,#mermaid-svg-xPzkYottZ0ktrBZv .icon-shape .label{text-anchor:middle;}#mermaid-svg-xPzkYottZ0ktrBZv .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-xPzkYottZ0ktrBZv .rough-node .label,#mermaid-svg-xPzkYottZ0ktrBZv .node .label,#mermaid-svg-xPzkYottZ0ktrBZv .image-shape .label,#mermaid-svg-xPzkYottZ0ktrBZv .icon-shape .label{text-align:center;}#mermaid-svg-xPzkYottZ0ktrBZv .node.clickable{cursor:pointer;}#mermaid-svg-xPzkYottZ0ktrBZv .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-xPzkYottZ0ktrBZv .arrowheadPath{fill:#333333;}#mermaid-svg-xPzkYottZ0ktrBZv .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-xPzkYottZ0ktrBZv .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-xPzkYottZ0ktrBZv .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-xPzkYottZ0ktrBZv .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-xPzkYottZ0ktrBZv .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-xPzkYottZ0ktrBZv .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-xPzkYottZ0ktrBZv .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-xPzkYottZ0ktrBZv .cluster text{fill:#333;}#mermaid-svg-xPzkYottZ0ktrBZv .cluster span{color:#333;}#mermaid-svg-xPzkYottZ0ktrBZv 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-xPzkYottZ0ktrBZv .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-xPzkYottZ0ktrBZv rect.text{fill:none;stroke-width:0;}#mermaid-svg-xPzkYottZ0ktrBZv .icon-shape,#mermaid-svg-xPzkYottZ0ktrBZv .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-xPzkYottZ0ktrBZv .icon-shape p,#mermaid-svg-xPzkYottZ0ktrBZv .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-xPzkYottZ0ktrBZv .icon-shape .label rect,#mermaid-svg-xPzkYottZ0ktrBZv .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-xPzkYottZ0ktrBZv .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-xPzkYottZ0ktrBZv .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-xPzkYottZ0ktrBZv :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 新建空白 VM

VMnet2 + 磁盘≥10G + 无光驱
开机 → PXE 启动
iPXE 菜单

不操作,等10秒超时
自动进入菜单 1

Debian13 金盘还原
Clonezilla live 启动

HTTP 下载 vmlinuz + initrd + squashfs
ocs_prerun 自动挂载 NFS

mount -t nfs ...:/home/partimag
ocs_live_batch=yes

跳过所有交互
ocs-sr restoredisk

读取镜像 → 恢复 MBR/GPT
逐分区解压写入磁盘
安装 GRUB 引导
-p poweroff 自动关机
调整 BIOS 启动顺序

Hard Drive 移到第一位
开机 → 从硬盘启动
验证 root 登录

密码 zxcvbn


6. 注意事项

6.1 hostname 冲突

金盘镜像会完整克隆主机名,所有还原出来的机器主机名相同(如 pxe-debian)。在批量部署场景下:

  • DHCP 环境:可能引起 DNS 冲突
  • 解决方案:还原后通过脚本或 Ansible 修改主机名
bash 复制代码
# 还原后修改主机名
hostnamectl set-hostname new-hostname
sed -i "s/pxe-debian/new-hostname/" /etc/hosts

6.2 磁盘大小要求

要求 说明
目标盘 ≥ 金盘 Clonezilla restoredisk 要求目标盘不小于金盘
目标盘 = 金盘 最佳情况,分区大小完全一致
目标盘 > 金盘 -r 参数会自动扩展分区到目标盘大小

如果目标盘小于金盘,还原会失败。

6.3 还原后必须调整 BIOS 启动顺序

还原完成后机器自动关机。如果不调整 BIOS 启动顺序:

  1. 下次开机 → PXE 启动 → iPXE 菜单
  2. 10 秒超时 → 自动进入菜单 1(Debian13 金盘还原)
  3. 又开始还原 → 还原完又关机
  4. 陷入无限循环

解决方案:还原后开机按 ESC 进 BIOS,把 Hard Drive 移到第一位。

6.4 iPXE imgargs 中的引号问题

在 iPXE 的 imgargs 行中传内核参数时:

写法 结果
ocs_live_batch=yes ✅ 正确,批处理模式生效
ocs_live_batch="yes" ❌ 错误,引号被当字面值,批处理模式失效
ocs_live_run="ocs-sr ..." ✅ 正确,引号用于分组参数值

规则:参数值中有空格的才需要引号(如 ocs_live_run 的命令),简单的 yes/no 不能加引号。

6.5 Clonezilla live 完整引导参数

Clonezilla live 需要完整的引导参数才能正常运行。以下参数缺一不可:

参数 缺失的后果
boot=live 无法启动
union=overlay 文件系统只读
username=user 使用默认值,可能不兼容
config 缺少配置
components 缺少驱动
noswap 可能挂载到错误的 swap
noprompt 卡在确认界面
locales=en_US.UTF-8 卡在语言选择
keyboard-layouts=us 卡在键盘布局选择
ocs_live_keymap=NONE 卡在 "Change keyboard layout?"

6.6 Ubuntu autoinstall 与 Clonezilla 的关系

本实验采用"两阶段策略":

  1. 阶段一(安装器式):通过 autoinstall 或手动 ISO 安装一台 Ubuntu 26.04,配置好软件和密码
  2. 阶段二(镜像式):用 Clonezilla savedisk 打包成镜像,后续所有机器用 restoredisk 还原

两个阶段不冲突------autoinstall 用于"造金盘",Clonezilla 用于"批量还原"。

6.7 金盘更新策略

当需要更新金盘(如安装新软件、修改配置)时:

  1. 从 iPXE 菜单选 1 还原旧金盘到一台机器
  2. 调整 BIOS 启动顺序,从硬盘启动
  3. 登录系统,安装新软件/修改配置
  4. 清理(apt clean、清日志、history -c)
  5. 关机,调整 BIOS 回 Network boot
  6. iPXE 菜单选 3 进 Clonezilla 手动模式
  7. savedisk 打包新镜像(可用新名称如 debian13-img-v2
  8. 更新 boot.ipxe 中的镜像名
相关推荐
OsDepK1 小时前
在安卓Termux终端中部署openssh
linux·服务器
小马9267 小时前
插件化 Agent 架构:DeepSeek Harness 如何让智能体重构不再需要 Fork
架构·deepseek·agent架构
雨白7 小时前
深入理解 Java/Kotlin 反射、注解与泛型:从原理到实战
android·架构
Python私教9 小时前
多个项目怎么安全合并?先适配,再切换
后端·python·架构
动力 continue9 小时前
Linux 基础篇 · 压缩打包与用户管理
linux·服务器·基础命令linux
hey you~9 小时前
呼叫中心系统全链路自研架构:如何实现99.999%通话高可用
架构·故障切换·多活架构·呼叫中心高可用·全链路自研·通信paas
画中有画10 小时前
软件架构中质量属性(性能、安全、可扩展性)的权衡设计
java·运维·安全
g3voip10 小时前
防爆电话如何接入SIP调度系统?工业通信系统架构解析
服务器·tcp/ip·系统架构·信息与通信·ip
Python私教10 小时前
从表格到管理系统:别先写页面,先补齐权限、流程和审计
数据库·后端·架构