VirtualBox Headless Administration |
Server - Virtualization |
VirtualBox is often used on the desktop through it's GUI interface. Sometimes, though, you'll need to run it on a headless server somewhere on the internet. Our demonstration setup today is on a Debian 7 (Wheezy) system, and the virtual machine we're creating will use a placeholder of $VM for it's name. We'll assume the guest OS is Debian, and that you've already installed VirtualBox itself to the host. CentOS Online Course < Start Learning CentOS Now $120 VirtualBox has one of the best manuals, even if it is a hundred pages long. Chapter 8 is of particular interest to us. You can find the manual here: http://www.virtualbox.org/manual/ Installation instructions can be found here: https://www.virtualbox.org/wiki/Linux_Downloads We'll need the VirtualBox Extension Pack to be able to use RDP to initially set up the guest OS. Download it from https://www.virtualbox.org/wiki/Downloads, and install it like so. Root is required, however this only needs to be done once on the host.
To make it easy to copy & paste these commands, set $VM to the name of the guest virtual machine. If you are using the bash shell, it goes like this:
We'll start with creating a virtual machine. If you are running on a 32 bit host, drop the “_64” part. The setting for “ostypes” doesn't really matter, however it does set a few sane defaults, so it's best to use one if at all possible.
If you aren't using Debian, you can run this to get a list of OS types:
Next we need to give it a hard drive. Make sure to adjust the argument to --size as needed. In this example, it is set to 10GB. The first line creates the file that is the drive itself, the second line adds a SATA controller to the VM, and the last line plugs the hard drive in to the controller. You can add additional drives by incrementing the argument to --port.
We'll need to boot from an ISO image to be able to install our guest operating system, so lets add a DVD drive and attach an image to it. VirtualBox does not support SATA DVD drives, so we make an IDE controller to attach it to.
While at this point it is now possible to start it up, it's best to tune it a bit so it makes proper use of the host hardware. For a full explanation of these options, please see the VirtualBox manual.
Now to set up networking. For this example, we'll assume that you want a VM that can function as a full fledged server on the Internet. This means we want bridged networking. The exact details of this will change based on your host OS, for example under FreeBSD you'll be using tun/tap interfaces.
We should probably give it more memory than the default. For the OS type of “Debian_64” it defaults to 384MB, so it would be a good idea to change it. Here we set it to 4GB.
If your host has multiple CPU cores, we can take advantage of that. We can also tell VirtualBox to not use more than some percent of CPU time. This is a good idea on shared hosts. It defaults to 100%, so without setting it, VirtualBox will gladly allow a guest VM to use all the cycles it can.
Lastly, we should change the RDP port. Later, once the VM is pushed in to production, we will want to disable RDP entirely for security.
At this point we are now done setting up the new virtual machine. Time to start it up!
Connect to it with your favorite Remote Desktop viewer, and install however you want. We're done setting up a new virtual machine. There's a few common tasks left to go over, such as safely shutting down, suspending, resetting and cloning. Do not ctrl-C the VirtualBox process, run these from a different terminal. Here they are, in order.
If your VM locks up, you can “pull the plug” with this command (use this as a last resort):
Once your VM farm starts to grow a bit, you might need a refresher as to what is what. The first command lists all registered VMs, and the second command shows the configuration of the named VM.
Article written by Michael "mngrif" Griffith |