Virtual Machine Rescue
In certain scenarios, such as errors in modifying fstab or file system errors requiring the execution of fsck, a virtual machine may fail to start normally. In such cases, you can use rescue mode to repair the rootfs or access data in the system.
Operational Steps
Obtain Image Address
-
In the left navigation bar, click on Virtualization > Images.
-
Choose the Repository as the Source and select a virtual machine image with the Operating System set to CentOS or Ubuntu. Click on the right side
> Update. -
Copy and save the Image URL. In this document, we use
192.168.1.1:11443/3rdparty/vmdisks/centos:7.9as an example. -
Click Cancel.
Modify Virtual Machine YAML File
-
Access the Container Platform.
-
In the left navigation bar, click on Virtualization > Virtual Machines.
-
Click on the right side of the virtual machine that needs repair
> Stop to either Stop or Force Stop the virtual machine. -
Click on the right side of the virtual machine
> Update. -
Switch to the YAML tab and modify the following two fields.
-
In the
spec.template.spec.domain.devices.disksfield, add the following content. AddingbootOrderallows you to control the primary boot disk when the virtual machine starts. The smaller thebootOrdervalue, the higher the priority for booting.Note: If the original
spec.template.spec.domain.devices.disksfield already hasbootOrder: 1, increase the original value to ensure that the newly addedbootOrdervalue is smaller than the original value.disks: - bootOrder: 1 disk: bus: virtio name: containerdiskModified YAML example:
domain: devices: disks: - bootOrder: 1 # Added field disk: bus: virtio name: containerdisk - disk: bus: virtio name: cloudinitdisk - disk: # Increase the original bootOrder: 1 value bus: virtio name: rootfs bootOrder: 10 - disk: bus: virtio name: "1" -
In the
spec.template.spec.volumesfield, add the following content.Note: Replace the image address in the
imagefield with the image address obtained in Obtain Image Address .- containerDisk: image: 192.168.1.1:11443/3rdparty/vmdisks/centos:7.9 name: containerdiskModified YAML example:
volumes: - containerDisk: # Added field image: 192.168.1.1:11443/3rdparty/vmdisks/centos:7.9 name: containerdisk - dataVolume: name: k2-rootfs name: rootfs - dataVolume: name: k2-1 name: "1"
-
-
Click Update.
Note: After modifying the YAML file, do not switch to the Form tab. Click Update directly.
-
Click on the right side of the virtual machine
> Start.
Mount Original Rootfs and Perform Repair
-
Log in to the virtual machine using the original password or key, and run the
df -h /command to find that the rootfs file system has been replaced. You can use mount-related commands or use fsck-related commands to mount and repair the original file system. -
After the operation is completed, shut down the virtual machine.
Restore Virtual Machine YAML File
Follow the steps in Modify Virtual Machine YAML File to restore the virtual machine YAML file to its unmodified state. At this point, the virtual machine can start normally.