How to fix a damaged virtual machine

Source: Internet
Author: User
Tags scp command ssh access

As a VMware virtualization environment Administrator, you must have experienced a situation in which a virtual machine could not be started. When you implement a schedule, you need to check the internal of the virtual machine. The Libguestfslinux toolset can help you in this case.

Use Libguestfs to find corrupted virtual machine files

Libguestfs allows any type of file system to be mounted on a virtual machine in order to repair startup failures. As a native Linux tool that manages virtual machines in a KVM environment, it is not available to all VMware platforms by default. So the administrator doesn't use it as a preferred tool, but it's worth the time it takes to configure and use it.

Using Libguestfs, the first thing you need to do with Libvirt.libvirt is a management interface that connects to KVM, Xen, and some other Liunx-based virtual machines. The Libguestfs feature is more powerful and can open files on Windows virtual machines. This means that in addition to being able to use LIBGUESTFS, you also need some knowledge about the internal architecture of the virtual machine operating system. But first you need to migrate the virtual machine to the LIBGUESTFS available environment, which is the Linux environment.

To migrate a virtual machine to Linux, you can use SSH to connect to an ESXi host, which means that you first need to enable SSH access on the ESXi host.

When you are finished, run the following SCP command on the Linux platform: scp–r192.168.178.30:/vmfs/volumes/datastore1/windows*

Using Guestfish to manipulate virtual machines

After you have copied the virtual machine disk image file, you can use a tool such as guestfish to open it in libguestfs so that you can operate directly on the VMDK file. Use the GUESTFISH-RW-A/PATH/TO/WINDOWS.VMDK command to create an interactive shell in the virtual machine that connects to the file system. In the new window, you can use specific commands to manipulate the virtual machine files.

The first task is to find a usable file system:

> Run

> List-filesystems

/dev/sda1:ntfs

/dev/sda2:ntfs

Once you have used the Guestfish shell to find the available file system type, you can mount it. Use the command mount/dev/sda2/to mount the contents of two partitions-in Linux,/dev/sda2--to the Guestfish root directory. In Guestfish, you cannot manipulate the directory as you would in other shell environments. The mounted partition is the root directory, and you cannot use the CD command to switch directories, which means that all paths must be fully qualified paths, starting with the root directory. In Guestfishshell, you can use commands like LS, cat, more, download to view and download files and directories, and enter Help to see the complete command information. You can use Exit to close Guestfishshell after all operations have been completed.

Virt-rescue provides a direct access method

There are many other tools available in the Libguestfs tool. The Virt-rescue command is the best command to implement AD-HOC changes using normal Linux file System Tools--you can start a virtual machine in a secure shell. You can manipulate these files in a virtual machine, just as you do on mounted file systems, which provides more direct access to virtual machine content.

In order to use the Virt-rescue command on the virtual machine, use the Virt-rescure plus the client host name to open Virt-rescueshell, and then enter the > mode.

If you need to mount system files in a virtual machine, you can use the Fdisk-l/DEV/SDA command to view the partition of the virtual machine, and then use the command mount/dev/sda1/sysroot to mount the partition you want to access. This allows you to fix the contents of the virtual machine by changing it.

After the virtual machine is repaired, turn off Virt-rescueshell and move the virtual machine back to the ESXi server's data store. After the virtual machine returns to its original location, you should be able to access it if everything goes well with the previous operation.


How to fix a damaged virtual machine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.