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 | cd /vmfs/volumes/DATASTORE_NAME/OpenWrt |
2. 确认磁盘文件 / Identify the Disk
通常应操作体积较小的 VMDK 描述文件,例如:
Use the small VMDK descriptor file, for example:
1 | openwrt.vmdk |
如果虚拟机使用快照,当前磁盘可能是:
If snapshots exist, the active disk may look like:
1 | openwrt-000001.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:
- 移除旧磁盘,但不要选择从数据存储中删除。
- 添加“现有硬盘”。
- 选择
openwrt-recovered.vmdk。 - 保持原有磁盘控制器和启动顺序。
- 启动虚拟机并检查 OpenWrt。
English:
- Remove the old disk without deleting it from the datastore.
- Add an Existing hard disk.
- Select
openwrt-recovered.vmdk. - Keep the original disk controller and boot order.
- Power on the VM and verify OpenWrt.
6. 检查 OpenWrt / Verify OpenWrt
OpenWrt 启动后,检查文件系统、网络接口和配置是否正常:
After OpenWrt starts, verify the filesystem, network interfaces, and configuration:
1 | logread |
确认系统稳定运行后,再择机删除旧磁盘文件。
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
.vmxfile, the snapshot chain, and the lock status.