Install VirtualBox with Ubuntu Desktop VM in bridge mode

My plan of purchasing HP N54L is having all services I deployed to ds213+ migrated to HP N54L. This allow my NAS become a centralized file server only. So I no longer need to worry my optware being corrupted by firmware update. You never know when will it break. And since I upgrade NAS every few years, I reinstall all those services like [openvpn, freeradius, openldap, bind, crontab, mysql, synopass, blah blah blah] periodically.

I am tired of these. Here are my plan:

Install Ubuntu server to HP N54L. Ubuntu server running no services, only run VirtualBox.

Then I run another Ubuntu VM on N54L. All services will run on the Ubuntu VM. I should have no more worry about switching hardware, crashing OS or whatever. All I need is to deploy my VM on the new VirtualBox and I should have all things back.

At the beginning I was going to run ESXi. But after reviewing the license things, I give up. I am going to use Virtual Box instead.

Here are my procedures to install VirtualBox with Ubuntu Desktop to my HP N54L running Ubuntu server.

Install VirtualBox

Open a terminal. Run the commands as root below to install.

# sudo echo "deb precise contrib" >> /etc/apt/sources.list
# sudo echo "deb oneiric contrib" >> /etc/apt/sources.list
# sudo echo "deb natty contrib" >> /etc/apt/sources.list
# sudo wget -q -O- | sudo apt-key add -
# sudo apt-get update
# sudo apt-cache pkgnames | grep virtualbox

This will show a list of availble virtualbox. Install the latest one.

# sudo apt-get install virtualbox-4.3

Now download and install the extension pack. If you want to Remote desktop to the VM, you will need this. Note the version of extension pack, must be match the virtual box version that you installed above. Example below install 4.3.12.

# cd ~
# wget
# sudo VBoxManage extpack install ./Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

Create a new user vboxuser to run the virtualbox process.

# sudo adduser –ingroup vboxusers vboxuser

Now switch to the vboxuser, do not run following commands as root.

# sudo su vboxuser

Create Ubuntu VM

Adjust the parameter(s) to fit your need. Sample below create a VM named ‘deadcode’ with 1GB ram. My network adaptor is named em1 instead of eth0. Check your own setting by running ifconfig under shell.

Below is the config of the new VM

  • 1024MB RAM
  • One Intel network adapter, bridged with the LAN card of HPN54L.
  • One hard drive with 50GB
  • One CDROM mounted with Ubuntu Desktop 14.04.2 ISO

# cd ~
# VBoxManage createvm --register --ostype Ubuntu --name "deadcode"
# VBoxManage modifyvm “deadcode” —memory “1024”
# VBoxManage modifyvm “deadcode” —nic1 bridged —bridgeadapter1 ‘em1’
# VBoxManage modifyvm “deadcode” —boot1 dvd —boot2 disk
# VBoxManage storagectl “deadcode" --name "SATA Controller" --add sata --bootable on
# VBoxManage storagectl "deadcode" --name "IDE Controller" --add ide --bootable on
# VBoxManage createhd --filename “/home/vboxuser/VirtualBox VMs/deadcode/disk1" --size 50000 --format VDI --variant Standard
# mkdir ~/iso
# wget
# VBoxManage storageattach "deadcode" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium “/home/vboxuser/VirtualBox VMs/deadcode/disk1.vdi”
# VBoxManage storageattach "deadcode" --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium “/home/vboxuser/iso/ubuntu-14.04.2-desktop-i386.iso"
# VBoxManage modifyvm "deadcode" --vrdeport 3389 --vrde on

Now the VM is created and configured, start it.

# VBoxHeadless –startvm “deadcode” –vrde config &

If success, following will be printed to console.

Oracle VM VirtualBox Headless Interface 4.1.22
(C) 2008-2012 Oracle Corporation
All rights reserved.Controlling the Virtual Machine

In order to allow devices in the network to reach the VM, a static route is needed to add to the broadband router. First grab the bridged adapter ip address.

Run ifconfig, looks for virbr0 entry.

# ifconfig

virbr0    Link encap:Ethernet  HWaddr xx:xx:xx:xx:xx:xx  
          inet addr:  Bcast:  Mask:
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

The ip address is

Add a static route

Gateway: (ip address of HP N54L)

Web Interface (phpvirtualbox)

A great php management interface is provided by a great open source package phpvirtualbox.

To install it

Run the commands below as root

# sudo sh -c “echo “VBOXWEB_USER=vboxuser” >> /etc/default/virtualbox”
# sudo service vboxweb-service restart
# sudo apt-get install zip

Run the commands below as vboxuser

# sudo su vboxuser
# cd ~
# wget
# unzip
# rm
# cd phpvirtualbox-4.1-10
# cp config.php-example config.php

Edit config.php, edit the user and password at lines 12 and 13.

# vim config.php

Create a symbolic link to apache.

# sudo ln -s /home/vboxuser/phpvirtualbox-4.1-10 /var/www/html/phpvirtualbox

Now you manage all the VM using a browser.

Default username and password is admin/admin.

Create an auto start script to startup Virtualbox after server reboot

# sudo vim /etc/init.d/

Copy and paste the content below

#! /bin/sh
# Provides:
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
# The location of the file containing the list of vms to start
# The name of the user running the vms
HOMEDIR=`eval "echo ~$VMUSER"`
        if [ ! -d "$HOMEDIR/VirtualBox VMs/$LINE" ]; then
        INFO=$(sudo -H -u $VMUSER /usr/bin/VBoxManage showvminfo "$VMNAME" 2>/dev/null)
        if [ $? = 0 ]; then
                STATE=$(echo "$INFO" | grep State | awk '{ print $2; }')
case "$1" in
        echo "Starting VirtualBox VM..."
        cat $CONFFILE | while read LINE
                if [ $STATE = "running" ]; then
                        echo "$VMNAME is already running"
                elif [ $RC = 0 ]; then
                        sudo -H -u $VMUSER /usr/bin/VBoxManage startvm "$VMNAME" -type vrdp
                        echo "$VMNAME is $STATE"
        echo "Saving state of Virtualbox VM..."
        tac $CONFFILE | while read LINE
                if [ $STATE = "running" ]; then
                        echo "Stopping $VMNAME:"
                        sudo -H -u $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate
                        echo "$VMNAME isn't running"
        echo "Virtual Machines state:"
        cat $CONFFILE | while read LINE
                echo "\"$VMNAME\" is: $STATE"
    echo "Usage: /etc/init.d/ {start|stop|status}"
    exit 1
exit 0

Once the script is created, run the commands below to install the script.

# sudo chmod +x /etc/init.d/
# sudo update-rc.d defaults 90

Create a text file. This text file contains a list of VM to be auto start during server reboot.

# vim /home/vboxuser/autostart.txt

Sample content of autostart.txt. One VM per line.


Now you should be able to use Remote Desktop to connect to the new VM and continue the Ubuntu Desktop installation.

Use Remote Desktop to connect to the VM with ip

If you have firewall on, you need to allow Remote Desktop traffic.

# sudo ufw allow proto tcp from to port 3389
# sudo ufw allow proto tcp from to port 3389

Suppose is the macbook that I used to Remote Desktop to the VM. is the Ubuntu server running the VM. is the bridge adapter.

Notes on Remote Desktop

It does not works initially. I don’t know why it didn’t work. After a few VM restart, it start working… be patient if you encountered the same scenario… Remote desktop is the only trouble I encountered during the whole installation. And it suddenly works… and once it works, it just works well.

2015-04-09 Notes on OpenVPN

To allow openvpn clients to access devices on the network, following must be done:

  • Add route to router
  • Setup IP Masquerade on the VM
  • push “192.168.x.x” in server.conf
  • Enable Promiscuous Mode to the VM’s network adapter


I’m following the instructions below to perform my installation. You will find the procedures are pretty much the same. Some essential steps were not mentioned though, I try to make the procedures more complete for my future reference. Thanks a lot to the author of the original post. The restart script is particular helpful.

Installation is a bit long but once things works, it is very rewarding. Now I can run all sort of OS on my Ubuntu server.

Update 2015-05-02 Install Guest Addition

Guest addition must be installed in VM otherwise remote desktop size will be VERY small resolution and cannot control the Ubuntu Desktop at all. Also the mouse will not able to synchronize with your actual mouse pointer.

Must install guest addition for GUI remote control.

In the host server, run following command to download Guest Addition ISO

# sudo apt-get install virtualbox-guest-additions-iso

Once downloaded, mount the iso using phpvirtualbox for use with the VM.

The ISO is here


Then ssh to VM as normal user, i.e. ray.

For Ubuntu Desktop, login the Ubuntu Desktop, open a file explorer, the Virtual CD of Guest Addition should be shown.

Open a terminal.

$ sudo su
# cd /media/ray/VBOXADDITIONS_4.3.26_98988
# ./
Verifying archive integrity… All good.
Uncompressing VirtualBox 4.3.26 Guest Additions for Linux…………
VirtualBox Guest Additions installer
Copying additional installer modules …
Installing additional modules …
Removing existing VirtualBox DKMS kernel modules …done.
Removing existing VirtualBox non-DKMS kernel modules …done.
Building the VirtualBox Guest Additions kernel modules …done.
Doing non-kernel setup of the Guest Additions …done.
Starting the VirtualBox Guest Additions …done.
Installing the Window System drivers
Installing X.Org Server 1.16 modules …done.
Setting up the Window System to use the Guest Additions …done.
You may need to restart the hal service and the Window System (or just restart
the guest system) to enable the Guest Additions.

Installing graphics libraries and desktop services components …done.

Update 2015-05-02 Auto start VM after server reboot – The fix

The auto start procedures somehow, not working. I managed to fix by the link below

  • Create the file /etc/default/virtualbox

    # virtualbox defaults file

  • Create the file /etc/vbox/vbox.cfg


  • Execute commands below

    # sudo chgrp vboxusers /etc/vbox
    # sudo chmod 1775 /etc/vbox
    # sudo su vboxuser
    $ VBoxManage setproperty autostartdbpath /etc/vbox
    $ VBoxManage modifyvm “Name of VM” –autostart-enabled on
    $ exit
    # sudo service vboxautostart-service restart

Update 2015-05-02 Google Authenticator for SSH

None of the guide actually works. Got to write down the full procedures myself.

  1. sudo apt-get install libpam-google-authenticator
  2. vi /etc/pam.d/sshd, add following line to the top of the file

    auth required nullok

  3. vi /etc/ssh/sshd_config, add/edit the following lines

    RSAAuthentication yes
    PubkeyAuthentication yes
    AuthorizedKeysFile .ssh/authorized_keys
    #PermitRootLogin without-password
    PermitEmptyPasswords no
    ChallengeResponseAuthentication yes
    AuthenticationMethods publickey,keyboard-interactive
    PasswordAuthentication no

  4. This setup ssh to required both publickey and google authenticator code to login. Login as root is rejected. Plain account password login is disabled.

Leave a Reply

Your email address will not be published. Required fields are marked *