Home / Platform management / Virtualization / Virtual Machine Rescue

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

  1. In the left navigation bar, click on Virtualization > Images.

  2. 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.

  3. Copy and save the Image URL. In this document, we use 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 on Virtualization > Virtual Machines.

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

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

  5. Switch to the YAML tab and modify the following two fields.

    • In the spec.template.spec.domain.devices.disks field, add the following content. Adding bootOrder allows you to control the primary boot disk when the virtual machine starts. The smaller the bootOrder value, the higher the priority for booting.

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

      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"
    • In the spec.template.spec.volumes field, add the following content.

      Note: Replace the image address in the image field with the image address obtained in 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 the Form tab. Click Update directly.

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

Mount Original Rootfs and Perform Repair

  1. 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.

  2. 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.