ESXi 意外断电后修复 OpenWrt VMDK 镜像 Repair OpenWrt VMDK After ESXi Power Failure

ESXi 意外断电后,OpenWrt 虚拟机可能无法启动,并提示虚拟磁盘损坏或无法打开。可以使用 ESXi 自带的 vmkfstools 检查并修复 VMDK 文件。

After an unexpected ESXi power failure, the OpenWrt VM may fail to start because its virtual disk is corrupted or cannot be opened. The built-in vmkfstools utility can check and repair the VMDK file.

1. 关闭虚拟机并备份 / Power Off and Back Up

确保 OpenWrt 虚拟机已经关闭。修复前建议备份虚拟机目录,至少保留原始 VMDK 文件。

Make sure the OpenWrt VM is powered off. Back up the VM directory, or at least keep a copy of the original VMDK files before repairing.

通过 SSH 登录 ESXi:

Log in to ESXi through SSH:

1
ssh root@ESXI_IP

进入 OpenWrt 虚拟机目录:

Go to the OpenWrt VM directory:

1
2
cd /vmfs/volumes/DATASTORE_NAME/OpenWrt
ls -lh

2. 确认磁盘文件 / Identify the Disk

通常应操作体积较小的 VMDK 描述文件,例如:

Use the small VMDK descriptor file, for example:

1
2
openwrt.vmdk
openwrt-flat.vmdk

如果虚拟机使用快照,当前磁盘可能是:

If snapshots exist, the active disk may look like:

1
2
openwrt-000001.vmdk
openwrt-000001-delta.vmdk

不要直接对 -flat.vmdk-delta.vmdk 文件执行以下命令。

Do not run the following commands directly against -flat.vmdk or -delta.vmdk files.

3. 检查 VMDK / Check the VMDK

以当前虚拟机实际使用的 VMDK 描述文件为准:

Use the VMDK descriptor currently attached to the VM:

1
vmkfstools -x check openwrt.vmdk

部分 ESXi 版本也支持:

Some ESXi versions also support:

1
vmkfstools --fix check openwrt.vmdk

如果返回磁盘没有错误,可以重新启动虚拟机测试。

If no errors are reported, try powering on the VM again.

4. 修复 VMDK / Repair the VMDK

如果检查结果提示需要修复,执行:

If the check reports that repair is required, run:

1
vmkfstools -x repair openwrt.vmdk

或:

Or:

1
vmkfstools --fix repair openwrt.vmdk

修复完成后再次检查:

Check the disk again after repairing:

1
vmkfstools -x check openwrt.vmdk

5. 克隆为新磁盘 / Clone to a New Disk

为了避免继续使用可能存在隐患的原始磁盘,可以将其克隆为新的 VMDK:

To avoid continuing to use a potentially damaged disk, clone it to a new VMDK:

1
vmkfstools -i openwrt.vmdk openwrt-recovered.vmdk -d thin

完成后,在 ESXi 管理界面中编辑 OpenWrt 虚拟机:

After cloning, edit the OpenWrt VM in the ESXi web interface:

  1. 移除旧磁盘,但不要选择从数据存储中删除。
  2. 添加“现有硬盘”。
  3. 选择 openwrt-recovered.vmdk
  4. 保持原有磁盘控制器和启动顺序。
  5. 启动虚拟机并检查 OpenWrt。

English:

  1. Remove the old disk without deleting it from the datastore.
  2. Add an Existing hard disk.
  3. Select openwrt-recovered.vmdk.
  4. Keep the original disk controller and boot order.
  5. Power on the VM and verify OpenWrt.

6. 检查 OpenWrt / Verify OpenWrt

OpenWrt 启动后,检查文件系统、网络接口和配置是否正常:

After OpenWrt starts, verify the filesystem, network interfaces, and configuration:

1
2
3
4
logread
dmesg
df -h
ip addr

确认系统稳定运行后,再择机删除旧磁盘文件。

Delete the old disk files only after confirming that the recovered VM works correctly.

注意:如果 VMDK 描述文件丢失、快照链断裂,或者命令提示文件被锁定,不要反复执行修复。应先检查 .vmx 中引用的磁盘、快照链和锁定状态。

Note: If the VMDK descriptor is missing, the snapshot chain is broken, or the file is locked, do not repeatedly run repairs. First inspect the disk referenced by the .vmx file, the snapshot chain, and the lock status.