As the administrator of a VMware virtual environment, there are times when you have a virtual machine that won't...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
boot. To troubleshoot this, you'll have to examine the inside of the VM. The libguestfs Linux toolset can help in this situation.
Libguestfs reveals broken VM files
Libguestfs was developed to mount any file system in a VM so boot issues could be repaired. As a native Linux utility that was created to manage VMs on KVM environments, it isn't available on any VMware platform by default and may not be the first tool that comes to mind for the administrator. However, it is worth the trouble to configure and use it.
To use libguestfs, you need libvirt. Libvirt is the management interface that interacts with KVM, Xen and some other types of VMs on Linux. Libguestfs goes beyond that and is also capable of opening files on a Windows VM. That means that apart from being able to work with libguestfs, you'll need some knowledge of the VM operating system internals. But first you'll need to transfer the VM to an environment where libguestfs is available, which means transferring it over to Linux.
To copy a VM to Linux, you can SSH into the ESXi host, which means you'll first need to enable SSH access on the ESXi host. Once you've done that, from the Linux platform, run the scp command, such as:
scp –r 192.168.178.30:/vmfs/volumes/datastore1/Windows*
Use guestfish to work with the VM
After copying the VM disk image file, open it in libguestfs with a tool like guestfish. It's fine to work directly on the vmdk file. Use the command
guestfish -rw -a /path/to/windows.vmdk to open an interactive shell to the file system in the VM. From the prompt that opens, you can use specific commands to work in the VM files.
The first task would be to find out which file systems are available:
Once you've found out which file systems are available from inside the guestfish shell, you can mount them. Use mount
/dev/sda2 / to mount the contents of the second partition -- known as
/dev/sda2 in Linux -- on the guestfish root directory. In guestfish, you won't work with directories the way you're probably used to in other shell environments. The mounted partition is the root directory, and you cannot use cd to change directories, which means that all paths must be fully qualified paths, starting at the root directory. From within the guestfish shell you can use commands like
download and others to view and download files and directories. Enter
help for a complete overview. Type
exit to close the guestfish shell when you're done.
Virt-rescue delivers direct access
In the libguestfs utilities, many other tools are available. The
virt-rescue command -- the best command to make interactive ad-hoc changes using normal Linux file system tools -- boots a VM into a rescue shell. You can work with the files in a VM as if you were working on a mounted file system, which offers more direct access to the contents of the VM.
To operate the virt-rescue command on a VM, enter
virt-rescue followed by the name of the guest to open the virt-rescue shell to bring you to the ><rescue> prompt.
Mount the file systems in the VM by typing
fdisk -l /dev/sda to see how the VM is partitioned. Next, mount the partition you want to access with
mount /dev/sda1 /sysroot. Here you can make modifications to repair the VM contents.
After repairing the VM, close the virt-rescue shell and copy the VM back to the data store on the ESXi server. Once the VM is back, you should be able to access it provided that you have done your work well.
Sander van Vugt asks:
What do you use to fix a VM that won't boot?
2 ResponsesJoin the Discussion