Dmitry Leskov

Baseline Ubuntu Server Installation on VirtualBox

Update 05-Jun-2012: A few things have changed for VirtualBox 4.1 and Ubuntu 12.04 LTS.

In preparations for the migration of my personal Web sites to a new VPS provider, I’ve been playing with various Linux Web stack options in VirtualBox VMs. I did not want to fiddle with the snapshot tree, as difference disk growth is known to adversely affect performance, thus making benchmarking of different configs against each other meaningless. I also did not want to install Ubuntu on each VM from scratch. Therefore I have developed a process for VM cloning so as to fork configurations on demand. This post is the first part of a two-part series and considers installation of a baseline Ubuntu Server 10.04 LTS on a VirtualBox 3.2.12 VM.

Note: I am well aware of VirtualBox 4.0.0 release taking place a few weeks ago, but tend to wait until something like x.0.5 or x.1.2 comes out before jumping to a new major version. In any case, it should be easy to adapt this process to other versions of VirtualBox and Ubuntu, and, with some more effort, to other virtualization packages and/or Linux distros.

First, I have created a “baseline” VM with just a core Ubuntu Server 10.04 LTS installation and the following hardware configuration:

  • One fixed-size virtual hard disk. Again, I use a fixed-size disk so as to avoid the interference of the dynamic disk expansion process with performance measurements.

    There is also a trap: it is not highlighted in the VirtualBox GUI that a dynamically expanded virtual hard disk grows only up to the size you specify when you create it, so I see no point in employing dynamic virtual storage expansion when you have plenty of real hard drive space.

  • Two network adapters: the first is the default NAT, enabling the VM to connect to the Internet, and the second is host-only with a static IP address, so as to map to virtual Web hosts.

Here are the steps I’ve taken to create a new VM in VirtualBox:

  1. Invoke the New Virtual Machine Wizard and create a new VM. Some tips:

    • If you want to try many different configurations, maybe create multiple baseline VMs, use a name that would help identifying the VM later. My VM naming scheme is “ID-IN-CAPS platform-description“, so in this specific case the name was “BASELINE Ubuntu Server 10.04.1 LTS (x86)”
    • Adjust the amount of RAM to your likings, or just leave it as is – it is easy to change it later. My VPS will have 512MB of RAM, which seems to be the default in my version of VirtualBox, so I left it intact.
    • Create a new virtual boot hard disk. VirtualBox will handily name it after the VM. You better think about its size in advance though, as resizing a disk is not that easy. You may always attach and mount another virtual disk if you run out of disk space, though. For my baseline VM, I have created a 5 GB fixed-size disk.

  2. Open the Settings dialog for the new VM and make the following adjustments:
    • System: Remove floppy from boot order, make sure CD/DVD-ROM is first.
    • Storage: Load the Ubuntu ISO image into the virtual CD/DVD-ROM drive. Given the above memory constraints, I used the 32-bit version, but YMMV.
    • Audio: Disable.
    • Network: Enable Adapter 2 and attach it to the host-only adapter.
    • Shared Folders: I add one shared folder called “common” to facilitate copying of files between cloned VMs.
  3. Start the VM and install Ubuntu Server core. If the console redraws slowly, refer to my previous post for a solution.

    More tips:

    • Assuming that Adapter 1 (NAT) maps to eth0 and Adapter 2 to eth1 (there are reports that it is not always the case, but I have not seen it myself) select eth0 as the primary network interface.
    • You will likely be changing the hostname in each clone, so it does not really matter what you enter during the baseline system installation. I entered “baseline“.
    • On the Software Selection screen, only select software that you want to be present in all clones of this VM. I selected nothing.

Log in and install the latest security updates:

sudo aptitude update           # makes little sense as the installer has just done that
sudo aptitude -y safe-upgrade  # -y == --assume-yes
sudo reboot

Update 26-Mar-2011: If you want the clones to react to the ACPI shutdown signal, install acpid:

sudo apt-get install acpid

Update 05-Jun-2012: As of 12.04 LTS (and possibly some prior versions), the acpid package gets installed by default, so you may not need this.

Install VirtualBox Guest Additions, primarily to enable shared folders. To “insert” the Guest Additions image into the virtual CD/DVD drive, press Host-D or select Devices/Install Guest Additions… from the VM window menu.

sudo apt-get -y install dkms
sudo mount /dev/cdrom /media
cd /media
sudo ./

To have a shared folder mounted automatically during boot, create a mount point for it and add the line

shared-folder-name   mount-point   vboxsf   defaults   0   0

to file /etc/fstab. I added the line

common  /mnt/common   vboxsf   defaults   0   0

to have the above created “common” shared folder mounted to /mnt/common:

sudo mkdir /mnt/common
cd /etc
sudo cp fstab fstab.original
sudo bash -c "echo common$'\t'/mnt/common$'\t'vboxsf$'\t'defaults$'\t'0$'\t'0 >>fstab"
sudo mount -a   # mounts all file systems from /etc/fstab

The only thing left is enabling network access from the host. The Ubuntu installer only enables the primary network interface, presumably eth0. To enable the host-only interface and assign a static IP address to it, first look up the range of available addresses and the network mask: select File/Preferences, go to the Network tab, select the desired adapter from the list and click the Edit button.

In my case, which I suppose to be the default in VirtualBox, the host-only Ethernet adapter has the address and netmask, and the built-in DHCP server is set to allocate addresses from the range – This left me with the range for static addresses — more than enough for my needs.

Now, append the following lines to /etc/network/interfaces:

auto eth1
iface eth1 inet static
    address IPv4-address
    netmask IPv4-netmask

and restart networking:

cd /etc/network
sudo cp interfaces interfaces.original
sudo sh -c "echo \"auto eth1
iface eth1 inet static
    netmask\" >>interfaces"
sudo service networking start

Wait a bit, then IPv4-address should become pingable from the host.

That’s it! We can move on to VM cloning.

Tags: , , ,

« | »


* Copy This Password *

* Type Or Paste Password Here *