Monday, February 8, 2016

How to delete a VirtualBox VM using command line

VirtualBox comes with a GUI that let you easily manage your virtual machines.
However, you may have no Desktop and have to manage your virtual machines via command line.

There is a great tools called vboxmanage that let you do anything you want. I will show you how to completely delete a virtual machine with vboxmanage.

First you should get the name of the VM you want to delete:
$ vboxmanage list vms
"MyVM" {bc0f9b2a-1c49-4771-8179-610a5bf10578}
"My second VM" {a2b9f0ea-3c48-4770-8179-610a5bf10578}
"My third VM" {9b2aae0f-6c48-4771-8179-610a5bf10578}

Identify the VM you want to delete and make sure you don't delete the wrong one, because once you execute the following command, there is no confirmation.

Here is what will do the following command:

  •     all hard disk image files, including differencing files, which are used by the machine and not shared with other machines;
  •     saved state files that the machine created, if any (one if the machine was in "saved" state and one for each online snapshot);
  •     the machine XML file and its backups;
  •     the machine log files, if any;
  •     the machine directory, if it is empty after having deleted all the above.

Ready to run the command to delete the VM? Here is the command:
$ vboxmanage unregistervm < name or uid > --delete

For example:
$ vboxmanage unregistervm MyVM --delete
$ vboxmanage unregistervm "My second VM" --delete
$ vboxmanage unregistervm 9b2aae0f-6c48-4771-8179-610a5bf10578 --delete

Remember there is no confirmation, as soon as you press enter the VM will be deleted.


No comments: