If you’re using VirtualBox as a virtual machine (VM) server in your data center, chances are you’re going to want to know how to run those VMs without having to rely on the VirtualBox GUI. This makes it much easier to run your VMs without having to be at the host machine (you can ssh into the host and then manage the VMs) or without having a number of GUI windows open to clutter your server desktops (or be readily available for prying eyes).
To make this happen, you’ll use a very powerful command that comes with VirtualBox called VBoxManage; it allows you to manage a number of aspects of your VMs. I’ll show how to use VBoxManage to start, stop, and pause your VMs. I assume you have VirtualBox installed, and your VMs are ready to run on the host machine.
SEE: Building the Software Defined Data Center (ZDNet/TechRepublic special feature)
Before you fire up a VM
If you go directly to the VBoxManage command and fire up a VM, you’ll probably find that VM isn’t reachable via network–this renders the VM worthless, especially if it is a server.
In order to get the networking of your headless VM up and running, you have to install the VirtualBox extension pack. Here’s how.
- Download the extension pack that matches your VirtualBox release.
- Open the VirtualBox GUI.
- Click File | Preferences.
- Go to the Extensions section.
- Click the downward-pointing arrow (Figure A).
- Navigate to where you saved the Extension Pack and select the .vbox-extpack file.
- Click Open.
- When prompted, type your admin password for the host machine.
- Click OK.
Installing the VirtualBox Extension Pack
You’re ready to run your VMs, which will include the ability to reach them via network.
Starting/stopping/pausing a VM
Now the fun begins. First, you must know the name of the VM you want to run. To find a list of the VMs, issue the command VBoxManage list vms. This command will display all the VMs, as well as their unique IDs, in a form that you can use (Figure B).
All of my available VMs
Say we want to run the “Ubuntu Server” VM as a headless instance. To do this, you would issue the command:
VBoxManage startvm "Ubuntu Server" --type headless
The VM will start up and hand you back your bash prompt. Your virtual server (if that’s how you’re using the VM) is now available to you.
If you need to pause that VM, issue the command:
VBoxManage controlvm "Ubuntu Server" pause --type headless
To restart that paused VM, issue the command:
VBoxManage controlvm "Ubuntu Server" resume --type headless
To shut down the VM, issue the command:
VBoxManage controlvm "Ubuntu Server" poweroff --type headless
You have the capability to start, stop, and pause your VMs…all from the command line.
A very handy feature
The ability to run VMs from the command line is incredibly handy. When you have a host running numerous guests, and you don’t want every guest visible on the host platform, or you want to be able to manage the VMs remotely, you’ll be glad to have the VBoxManage command at the ready.