Using VirtualBox to test Ubuntu Server configurations
October 31st, 2008
In a previous article, we discussed configuring Postfix, Dovecot, SpamAssassin, Amavisd and ClamAV for secure mail relaying. It's a lot of configuration, and if something is done wrong, the whole setup doesn't work. It's great to have a test plaform for all of this. Ideally a test plaform should be easy to use from a desktop computer and should not require dedicated hardware. VirtualBox is the way to go for this usage. In this article, we'll use VirtualBox to run Ubuntu Hardy Heron Server within Ubuntu Hardy Heron desktop.
Step 1: install VirtualBox
Use the normal package tools (
apt-get) to install.
Make sure to install the propper
module. Activate VirtualBox and create a new guest. It's straightforward
to create a guest Ubuntu Server, booting from the ISO image.
Boot from the image and go through a normal installation.
Step 2: make the installation bootable
The installation will not actually boot. It needs to be fixed. Boot the guest again from the ISO image, and go to recovery mode, and run a shell on the installation device. Run the following:
apt-get update apt-get install linux-386 apt-get remove linux-server
Now you can boot from the hard drive of the guest.
I hope that some future release of Ubuntu Server will be directly installable on a VirtualBox
Step 3: Configure port forwarding to access the virtual server
Shut down the guest, using a normal
shutdown -h now
There are many advanced networking options within VirtualBox for many different types of usage. We'll use the simplest: NAT networking, which is the default, with port forwarding. Port forwarding allows us to bind a port of the guest to a port on the host. For example, let's turn on port forwarding for SSHD:
VBoxManage setextradata global \ "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP VBoxManage setextradata global \ "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22 VBoxManage setextradata global \ "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222
This changes the setting globally (for all virtual machines). This assumes
pcnet device is being used. If you get an error like
VERR_PDM_DEVICE_NOT_FOUND it means the device name
Now restart the VM and you can telnet to it with:
ssh localhost -p 2222
We'll open additional ports for whichever services we need to work on.