VirtualBox - How to control virtual machine using shell

At the beginning of the last year, I wrote about VirtualBox image conversion, so today I will continue this topic further, and describe how to control virtual machine using command line.

How to list virtual machines

To list virtual machines and their UUID execute command:

$ VBoxManage list vms
"Debian - "Kolab dev"" {7ccf631e-a792-4aa3-b09c-96298ab41ff2}
"Crunchbang" {d485f4a1-7794-4502-8775-e6f67a16c8dc}
"Deepin" {6ce34e63-3632-42a4-8f6c-216c691c96b2}

To pretty print virtual machines use command:

$ VBoxManage list vms | sed "s/\"\(.*\)\".*/\1/"
Debian - "Kolab dev"
Crunchbang
Deepin

How to print virtual machine states

To print running virtual machines and their UUID use command:

$ VBoxManage list runningvms
"Crunchbang" {d485f4a1-7794-4502-8775-e6f67a16c8dc}

To list virtual machines and their corresponding states execute command:

$ VBoxManage list vms -l | grep -e ^Name: -e ^State | sed s/\ \ //g | cut -d: -f2- 
Debian - "Kolab dev"
 powered off (since 2013-07-19T21:17:55.000000000)
Crunchbang
 paused (since 2013-07-20T10:13:07.771000000)
Deepin
 powered off (since 2013-06-29T15:56:04.000000000)

Slightly different solution:

$ VBoxManage list vms -l | grep -e ^Name: -e ^State  | sed "s/Name:[ ]*\(.*\)/\1 \//;s/State:[\ ]*//" | paste -d " " - -
Debian - "Kolab dev" / powered off (since 2013-07-19T21:17:55.000000000)
Crunchbang / paused (since 2013-07-20T10:13:07.771000000)
Deepin / powered off (since 2013-06-29T15:56:04.000000000)

How to start virtual machine

You are not forced to use VirtuaBoxManager GUI as it is not desirable in every case, it is also not very ergonomic to use mouse all the time.

Standard GUI

To start virtual machine Crunchbang using standard GUI execute command:

$ VBoxManage startvm Crunchbang --type gui

You can safely omit type parameter in the above mentioned command as the standard GUI is used by default:

$ VBoxManage startvm Crunchbang

Simple GUI

To use simple GUI without controls use command:

$ VBoxSDL --startvm Crunchbang

To start virtual machine using simple GUI without controls in the background execute command:

$ VBoxManage startvm Crunchbang --type sdl

Headless

To start virtual machine without GUI in the background execute command:

$ VBoxManage startvm Crunchbang --type headless

To start virtual machine without GUI execute command:

$ VBoxHeadless --startvm Crunchabang

Headless with VNC

To start virtual machine without GUI, but enabled VNC service execute command:

$ VBoxHeadless --startvm Crunchbang --vnc --vncport 5901 --vncpass passw

How to pause virtual machine

To pause virtual machine execute command:

$ VBoxManage controlvm Crunchbang pause

How to resume paused virtual machine

To resume virtual machine execute command:

$ VBoxManage controlvm Crunchbang resume

How to reset virtual machine

To reset virtual machine execute command:

$ VBoxManage controlvm Crunchbang reset

How to power off virtual machine

To power off virtual machine execute command:

$ VBoxManage controlvm Crunchbang poweroff

How to save state and then stop virtual machine

To save state of the virtual machine and then stop it execute command:

$ VBoxManage controlvm Crunchbang savestate

Notes

Please note that I have not installed VirtualBox Extension Pack as I am not using VRDP.

I suggest you to read VirtualBox manual and Debian wiki - VirtualBox.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system. He is also open for new opportunities and challenges.

Gdansk, Poland https://sleeplessbeastie.eu