How to start and stop VirtualBox guests via command line

Solution 1:

This can all be accomplished by using VBoxManage after you have established an ssh connection:

1. List your VMS:

First list your available Virtual Machines with the command VBoxManage list vms, I illustrate this on my own setup:

andrew@ilium~$ VBoxManage list vms
"Windows 8" {c4422acd-727b-45a0-9eef-65636bcde44d}
"Windows 10" {a8e262be-a032-4918-9085-63185318a979}
"Trusty Tahr Clean Copy" {c99bcf4b-9fea-4971-b190-425cb0b0cdeb}
"Xenial Xerus Clean Copy" {850122b9-c65f-425b-abb3-ffda68e159c6}
"Precise Pangolin Clean Copy" {169086e6-a3f4-42e7-8a89-63dcb273143f}
"Precise Pangolin Working Copy" {ff8312b6-cfae-4877-aa93-d71036d8882c}
"Xenial Xerus for MPlayer" {44902710-4368-4c06-9d24-3cb55328d31c}
"Xenial Xerus for vlc" {a62ad306-17d9-4ee3-8c1a-e4439c3b0e05}
"Xenial Xerus mingw64" {584d8513-6a16-49c7-b020-d657b93d5552}
"Trusty Tahr Working copy..." {433349e9-52eb-4066-bae7-623592871839}
"Xenial Xerus Working copy..." {dda23e74-cdb5-4c7d-8836-31be4129c02a}
andrew@ilium~$ 

Note: If you are unsure which VM is actually running you could use VBoxManage list runningvms instead...

2. Start a VM:

The VBoxManage command and options that you are after to start a Virtual Machine are these:

  startvm                   <uuid|vmname>...
                            [--type gui|sdl|headless|separate]

So to start the "Trusty Tahr Clean Copy" VM in my example you would use:

VBoxManage startvm "Trusty Tahr Clean Copy" --type gui

3. Stop a VM:

To stop the VM you would again use VBoxManage but this time with controlvm option:

  controlvm                 <uuid|vmname>
                            pause|resume|reset|poweroff|savestate|

And in my example to close the "Trusty Tahr Clean Copy" VM the command would be:

VBoxManage controlvm "Trusty Tahr Clean Copy" savestate

This should all work nicely over ssh, who needs a gui after all :)

Solution 2:

For graceful shutdown use:

VBoxManage controlvm "Name" acpipowerbutton