Virtual Machine Recovery

In certain scenarios, such as incorrect modifications to fstab or filesystem errors requiring fsck, virtual machines may fail to start properly. In such cases, you can utilize rescue mode to repair the root filesystem (rootfs) or retrieve data from the system.

TOC

Steps to Operate

Obtain Image Address

  1. In the left navigation bar, click Virtualization Management > Virtual Machine Images.

  2. Select the platform-provided Source as Image Repository, and the Operating System as either CentOS or Ubuntu. Click ⋮ > Update on the right.

  3. Copy and save the Image Address. This document uses 192.168.1.1:11443/3rdparty/vmdisks/centos:7.9 as an example.

  4. Click Cancel.

Modify Virtual Machine YAML File

  1. Access the Container Platform.

  2. In the left navigation bar, click Virtualization > Virtual Machines.

  3. Click ⋮ > Stop on the right side of the virtual machine that needs repair to Stop or Force Stop it.

  4. Click ⋮ > Update on the right side of the virtual machine.

  5. Switch to YAML and modify the following fields.

    • Add the following content under spec.template.spec.domain.devices.disks. Adding a bootOrder parameter can control which disk is prioritized during the virtual machine's boot process; a lower bootOrder value indicates higher priority.

      Note: If the original spec.template.spec.domain.devices.disks field contains bootOrder: 1, increase the original value to ensure that the newly added bootOrder value is lower than the original.

      disks:
        - bootOrder: 1
          disk:
            bus: virtio
          name: containerdisk

      Modified 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"
    • Add the following content under spec.template.spec.volumes.

      Note: Please replace the image address in the following image field with the one obtained from Obtain Image Address.

      - containerDisk:
          image: 192.168.1.1:11443/3rdparty/vmdisks/centos:7.9
        name: containerdisk

      Modified 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"
  6. Click Update.

    Note: After modifying the YAML file, do not switch to Form, just click Update directly.

  7. Click ⋮ > Start on the right side of the virtual machine.

Mount the Original rootfs and Perform Repair

  1. Log in to the virtual machine using the original password or key and enter the command df -h / to find that the rootfs filesystem has been replaced. You can use mount-related commands to mount it or fsck-related commands to check and repair the original filesystem.

  2. After completion, shut down the virtual machine.

Restore the Virtual Machine YAML File

Follow the steps in Modify Virtual Machine YAML File to restore the virtual machine YAML file to its original state. At this point, the virtual machine can start normally.