How to delete inaccessible VirtualBox VMs from the command line

How to delete inaccessible VirtualBox VMs from the command line

If VirtualBox has become unresponsive, chances are good you have an inaccessible VM. Find out how to take care of this problem with two simple commands.

virtualboxhero.jpg

Image: Jack Wallen

VirtualBox is an outstanding tool for small businesses to employ virtual machines (VMs) from the data center. With both a GUI and headless option, just about any IT admin, of any skill level, can make use of this technology. 

Although VirtualBox is a very reliable tool for the job, every so often things happen. For instance, take a recent incident I experienced wherein a single corrupt/inaccessible virtual machine prevented me from accessing all of my VMs. Said virtual machines were unable to run headless or via the GUI.

So I dug in and, with the help of a few commands, solved the problem.

Let me show you how to take care of this issue.

SEE: 10 things companies are keeping in their own data centers (TechRepublic download)

What you’ll need

In order to make this work, you’ll need VirtualBox installed and a few VMs. The VMs in question don’t have to be inaccessible in order to follow these steps. In fact, it’s good to practice this process, so you can take care of the issue when it arises.

What is an inaccessible VM?

To put it in simplest terms, an inaccessible VM can occur when a host OS has crashed, leaving the VM in an unsaved state. Since my host OS is Linux, that’s a rare occasion. But, it does happen. When you find yourself in that situation, a single inaccessible VM will cause the whole of VirtualBox to not respond.

How to locate inaccessible VMs

The first step is to locate the offending VM. In order to do that, we’ll make use of the VBoxManage command. To do this, first close the VirtualBox GUI (if it’s open). Once the GUI closes, open a terminal window and issue the command:

VBoxManage list vms

You should see a list of all of your virtual machines (Figure A).

Figure A

A partial listing of my virtual machines.

” data-credit rel=”noopener noreferrer nofollow”>vboxa.jpg

vboxa.jpg

A partial listing of my virtual machines.

In that listing, you might see a virtual machine tagged as “<inaccessible>.” If you find one with said tag, that’s the offending VM. Along with that tag, you’ll also see an ID (a long string of random characters, such as a7a80921-7a9c-45dc-b312-121660f10a73). It’s that ID you’ll use to fix the problem.

You might think you could simply delete the inaccessible VM. That’s not the case. Instead, you unregister the VM. To unregister an inaccessible VM, you would issue the command:

VBoxManage unregistervm ID

Where ID is the string of characters denoting the VM in question. 

For instance, if my “CHEF CLIENT” VM were tagged as inaccessible, I’d issue the command:

VBoxManage unregistervm 6f05799a-118e-458c-b98a-e9d2b96733f2

Once the VM has been unregistered, VirtualBox should then work as expected. Open the GUI and start a guest. All should be fine. If not, chances are you have more than one inaccessible VM and you’ll have to go back, list the VMs and unregister the offending machines.

And that’s all there is to getting rid of inaccessible VirtualBox VMs. If you ever find the VirtualBox GUI, or your headless VMs unresponsive, chances are pretty good you have inaccessible machines that must be unregistered.

Now you know how to take care of that.

Also see

Source of Article