How-to: Headless Linux-hosted VirtualBox Hyper-Visor
Over the last two or three months I have spent a great deal of time learning about Linux generally in the hopes of eventually setting up a headless virtualbox server. I happen to be standardized on Ubuntu server 12.04 LTS for my home lab.
First, what is a Hypervisor? (Click to show) I'll let Wikipedia's entry field that one:
Quote:
In computing, a hypervisor or virtual machine manager (VMM) is a piece of computer software, firmware or hardware that creates and runs virtual machines.
A computer on which a hypervisor is running one or more virtual machines is defined as a host machine. Each virtual machine is called a guest machine. The hypervisor presents the guest operating systems with a virtual operating platform and manages the execution of the guest operating systems. Multiple instances of a variety of operating systems may share the virtualized hardware resources.
My attempt at even simpler explanation (Click to show) You've got a host operating system (like windows 7) running a piece of software that is pretending to be all the hardware of a hardware PC: video card, sound card, hard drive controller and virtual hard drives, memory, etc. An ISO of a OS like Windows XP or Ubuntu server is used against this software to install that operating system. This same ISO could be burned to a disc and used to install on real physical hardware, and the OS is given all the pieces of information it needs to successfully install, but it's all in software.
For more information on virtualization and VirtualBox in particular see OCN guide Forget dual-booting! Virtualization 101 user error10.
The next most common question is going to be Why Virtualbox? Why not Xen/KVM/Hyper-V/VMWare/et al? (Click to show) It's true, VirtualBox isn't really intended for commercial/production environment use. It is what is considered a type 2 or "hosted" hypervisor.
Some notes on how the enclosed commands work: since I don't enjoy retyping my password a hundred times I always sudo su upon logging in. I'm not in a production/critical environment so I don't really care about running as root the whole time. It just makes setting up much easier. This is not the recommended method for day-to-day use (and would normally send old school unix vets into bouts of rage).
Several reasons I'm using VirtualBox for this instance:
What you may need for making it through this how-to:
Optional step 0: static IP address and backing up soon to be modified files (Click to show) In an attempt to develop good habits from the start in my linux server CLI adventure I have been creating copies of files that I will soon be modifying. This isn't required but it's not a bad idea!
I usually just make a simple duplicate when I logon with the copy command:
Code:
[/CODE]
Also technically not required, I find it easier to manage various Linux boxen by SSH if they have a consistent IP address. To set a static IP address modify the file /etc/network/interfaces with the following, obviously modifying the IP address etc. to fit your local network:
Code:
[/CODE]
I typically use vim to edit. If you don't know any CLI editors this can be done with webmin once that is installed a little further down.
These first steps are at a vanilla first login for a freshly installed ubuntu 12.04 server. These are the first commands in other words.
The first set of command consists of adding some entries for VirtualBox and Webmin to your apt repository config file, sources.list. Then some keys are downloaded and added so that apt-get update will find what it needs to find. Finally, this is as good a time as any to install some extra components that will be needed later such as unzip, lvm, apache and webmin. The lack of an apt-get upgrade command is on purpose...
First set of commands (Click to show) Code:
[/CODE]
At this point you should be able to reach your Ubuntu server's webmin login at port 10000 (ten thousand). For instance, for me it is available at my statically assigned IP address of https://192.168.0.115:10000/ with the logon created during the server install process
Go back in to your /etc/apt/sources.list file and add the following lines (hint: this file can be edited through the recently installed webmin interface)
Code:
[/CODE]
Now reboot the system for the first time (I prefer shutdown -r now but to each his own)
Once rebooted update apt again and now do the upgrades: this is going to take while, may want to get a cup of coffee...
Code:
[/CODE]
Next install VirtualBox,download/install the extension pack and reboot again...
Now, install Virtualbox 4.2 and the extension pack (Click to show) This also is going to take a while (in case you want a second up of coffee)
Code:
[/CODE]
May want to do another apt get update and upgrade, to be sure you're up to date:
Code:
[/CODE]
Next is installing phpVirtualBox. Below will change to the WWW directory of Apache, download the latest version of phpvirtualbox via a handy command I got from the phpVirtualBox web site, extract the phpVirtualBox zip file to the WWW directory and rename that directory to a more convenient name, "vbox".
Obtaining/extracting phpVirtualBox (Click to show) Code:
[/CODE]
Setting up the vbox user (Click to show) The virtualbox installation created the vbox user and user group for us, we just need to add it to the group:
Add vbox user to vboxusers group:
Code:
[/CODE]
Then set the vbox password:
Code:
[/CODE]
I actually used vboxvbox as my password to meet complexity requirements yet make simple enough I'm not going to forget it. This is a limited user account that will only be used for Virtualbox-related operations.
Now copy over the example config file for phpVirtualBox to plain config.php (and copy that as well, but that's really optional)
Code:
[/CODE]
Modifying the phpVirtualBox config file (Click to show) Now for modifying /var/www/vbox/config.php (this can done with either vim or webmin)
Modify these lines as indicated. This is the password used on my system, modify as necessary...
Code:
[/CODE]
This line already exists commented out (with a '#'). You can uncomment it and enter in the host IP address of your server in place of the one supplied:
Code:
[/CODE]
This line enables the console tab in phpVirtualBox. Trust me, you want it
Creating the default virtualbox file (Click to show) First you can create the file with touch
Code:
[/CODE]
Then modify the file with the follwoing lines:
Code:
[/CODE]
Once this /etc/default/virtualbox file is saved and closed restart the VirtualBox web service with
Code:
[/CODE]
Or rebooting the whole system works just as well.
At this point you should be able to go to ip address of your server/vbox (in my case this is http://192.168.0.115/vbox/ ) and login to the site with the logon of admin/admin.
The first thing that is recommended to do in phpVirtualBox is reset the password for the admin user at the very least.
Next is setting up my example virtual machine, Caprica-V, to start as the host starts and power down properly when the host powers down.
Note that phpVirtualBox is going to look a lot like the regular Windows GUI version of VirtualBox but not act and react exactly the same way. I would have to select an ISO and HDD file at least twice before it would acknowledging the change, for instance. The Machine menu has a refresh option that I found useful several times.
This GUI also has convenient methods of changing where the savestates (Settings-->General-->Advanced tab) are stored and where VirtualMachines will be saved (File-->Preferences) -- useful if you're using a limited size OS boot drive.
Once your VM is setup it would definitely be a good time to start up the VM and then switch over to the Console at upper right. The resolution of the window you will be seeing is definable there. Hit connect and you'll be able to see the OS booting up. You can also enter in that same address in the Windows version of RDP (use mstsc in the run line) to connect to the VM, such as 192.168.0.115:9000.
Setting one particular VM to start up at host boot and power off (savestate) at host power down
change to cd /etc/init.d/, download the template, make the file executable:
change to cd /etc/init.d/, download the template, make the file executable: (Click to show) Code:
[/CODE]
Editing the newly created init.d VM file (caprica-v) (Click to show) Open the newly created init.d file and fill in these lines as appropriate for your own environment:
Code:
[/CODE]
Set the vbox-caprica-v file to start up and the hosts systems startup:
Code:
[/CODE]
Only thing left to do is reboot the host machine and see it works or not. During startup you should see a line stating that the virutal machine is trying to startup. If all goes as it should you should now have a running VM. A test of rebooting the host system should be done as well.
Over the last two or three months I have spent a great deal of time learning about Linux generally in the hopes of eventually setting up a headless virtualbox server. I happen to be standardized on Ubuntu server 12.04 LTS for my home lab.
First, what is a Hypervisor? (Click to show) I'll let Wikipedia's entry field that one:
Quote:
In computing, a hypervisor or virtual machine manager (VMM) is a piece of computer software, firmware or hardware that creates and runs virtual machines.
A computer on which a hypervisor is running one or more virtual machines is defined as a host machine. Each virtual machine is called a guest machine. The hypervisor presents the guest operating systems with a virtual operating platform and manages the execution of the guest operating systems. Multiple instances of a variety of operating systems may share the virtualized hardware resources.
My attempt at even simpler explanation (Click to show) You've got a host operating system (like windows 7) running a piece of software that is pretending to be all the hardware of a hardware PC: video card, sound card, hard drive controller and virtual hard drives, memory, etc. An ISO of a OS like Windows XP or Ubuntu server is used against this software to install that operating system. This same ISO could be burned to a disc and used to install on real physical hardware, and the OS is given all the pieces of information it needs to successfully install, but it's all in software.
For more information on virtualization and VirtualBox in particular see OCN guide Forget dual-booting! Virtualization 101 user error10.
The next most common question is going to be Why Virtualbox? Why not Xen/KVM/Hyper-V/VMWare/et al? (Click to show) It's true, VirtualBox isn't really intended for commercial/production environment use. It is what is considered a type 2 or "hosted" hypervisor.
Some notes on how the enclosed commands work: since I don't enjoy retyping my password a hundred times I always sudo su upon logging in. I'm not in a production/critical environment so I don't really care about running as root the whole time. It just makes setting up much easier. This is not the recommended method for day-to-day use (and would normally send old school unix vets into bouts of rage).
Several reasons I'm using VirtualBox for this instance:
- Linux-hosted VirtualBox does not require the VM CPU extension to run Windows virtual machines while Xen, for one instance, has this requirement.
- VirtualBox can run on a large variety of host operating systems (from Windows XP to server 2008 to Linux/Solaris and possibly some *BSDs) providing for maximum theoretical portability as far as a host OS.
- Relative simplicity/familiarity: I had already been using VirtualBox for Windows for years so this task mainly required learning the CLI end of what I had already used.
- Learning Linux-hosted VirtualBox provided motivation/catalyst for learning a lot about linux and will be a jumping off point to the next step: production environment hypervisors like Xen etc.
- An installation of webmin for general linux system administration when needed
- A web-gui for creating/modifying virtual machines thanks to phpvirtualbox
- Perhaps the most important part: the VM starting at host system power up and shutting itself down at host system power down
- The physical server "host " will be Ubuntu Server 12.04 x64, referred to as "Caprica-P" (Physical box, named caprica, get it?)
- Caprica-P only had "SSH Daemon" selected during installation as optional component
- The static IP address for the "Caprica-P" Ubuntu server will be 192.168.0.115 for the duration of the how-to
- Once Caprica-P is up and running it will be purely a "headless" server" -- no keyboard or monitor
- I am using VirtualBox 4.2 and phpVirtualBox 4.2 (this important)
- Since I am using VirtualBox 4.2.x I have to use both phpVirtualBox 4.2.x and the Virtualbox Extensions 4.2.x
- If a newer version of VirtualBox has come out make appropriate changes below to be sure the version of phpVirtualBox and the VirtualBox extensions are the same version as the VirtualBox you have installed
- The virtual machine "guest" will have Windows Home Server v1, referred to as "Caprica-V" (too clever?)
- I will mainly be communicating with the via my Windows 7 system using the SSH client Putty, webmin and phpVirtualBox.
- My Windows machine has the latest version of Java 7 installed, only needed for phpVirtualBox and certain components of webmin
What you may need for making it through this how-to:
- Braveness to face if not familiar with Linux at the command line (CLI) - X windows will not be used
- Ubuntu Server 12.04 (x86 and x64 should work equally well) installed with defaults
- SSH deamon installed (easy check box during ubuntu server installation, easy to install afterwards)
- Some form of SSH client for connecting - Putty is free/common/easy to use on MS Windows
- Webmin - for administering the Linux server
- VirtualBox - 4.2 as of this writing
- PHPVirtualBox - for creating/modifying virtual machine(s) - note phpvirtualbox versions are now in sync with virtualbox versions
- Java on the client (win 7) side to fully utilize phpvirtualbox
- Apache/PHP installation
- Enough storage space for virtual machines/virtual hard drives
Optional step 0: static IP address and backing up soon to be modified files (Click to show) In an attempt to develop good habits from the start in my linux server CLI adventure I have been creating copies of files that I will soon be modifying. This isn't required but it's not a bad idea!
I usually just make a simple duplicate when I logon with the copy command:
Code:
Code:
[CODE]cp /etc/network/interfaces /etc/network/interfaces.original
cp /etc/fstab /etc/fstab.original
cp /etc/apt/sources.list /etc/apt/sources.list.original
Also technically not required, I find it easier to manage various Linux boxen by SSH if they have a consistent IP address. To set a static IP address modify the file /etc/network/interfaces with the following, obviously modifying the IP address etc. to fit your local network:
Code:
Code:
[CODE]#usually "eth0" - Ethernet zero - but your mileage may vary (tm)
auto eth0
#iface eth0 inet dhcp # Won't be needing DHCP!
# customize below addresses to local environment
iface eth0 inet static
address 192.168.0.115
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 8.8.8.8 8.8.4.4 # these are google's public alternative DNS servers. Need something for DNS for apt-get to work
I typically use vim to edit. If you don't know any CLI editors this can be done with webmin once that is installed a little further down.
These first steps are at a vanilla first login for a freshly installed ubuntu 12.04 server. These are the first commands in other words.
The first set of command consists of adding some entries for VirtualBox and Webmin to your apt repository config file, sources.list. Then some keys are downloaded and added so that apt-get update will find what it needs to find. Finally, this is as good a time as any to install some extra components that will be needed later such as unzip, lvm, apache and webmin. The lack of an apt-get upgrade command is on purpose...
First set of commands (Click to show) Code:
Code:
[CODE]echo "deb http://download.webmin.com/download/repository sarge contrib" >> /etc/apt/sources.list
echo "deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib" >> /etc/apt/sources.list
echo "deb http://download.virtualbox.org/virtualbox/debian maverick contrib non-free" >> /etc/apt/sources.list
cd /root
wget http://www.webmin.com/jcameron-key.asc
wget http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
apt-key add oracle_vbox.asc
apt-key add jcameron-key.asc
apt-get update
apt-get -y install webmin unzip lvm2 apache2 php5-common php5
At this point you should be able to reach your Ubuntu server's webmin login at port 10000 (ten thousand). For instance, for me it is available at my statically assigned IP address of https://192.168.0.115:10000/ with the logon created during the server install process
Go back in to your /etc/apt/sources.list file and add the following lines (hint: this file can be edited through the recently installed webmin interface)
Code:
Code:
[CODE]deb http://download.virtualbox.org/virtualbox/debian oneiric contrib
deb http://download.virtualbox.org/virtualbox/debian natty contrib
deb http://download.virtualbox.org/virtualbox/debian lucid contrib non-free
deb http://download.virtualbox.org/virtualbox/debian karmic contrib non-free
deb http://download.virtualbox.org/virtualbox/debian hardy contrib non-free
deb http://download.virtualbox.org/virtualbox/debian wheezy contrib
deb http://download.virtualbox.org/virtualbox/debian squeeze contrib non-free
deb http://download.virtualbox.org/virtualbox/debian lenny contrib non-free
Now reboot the system for the first time (I prefer shutdown -r now but to each his own)
Once rebooted update apt again and now do the upgrades: this is going to take while, may want to get a cup of coffee...
Code:
Code:
[CODE]apt-get update
apt-get -y upgrade
shutdown -r now
Next install VirtualBox,download/install the extension pack and reboot again...
Now, install Virtualbox 4.2 and the extension pack (Click to show) This also is going to take a while (in case you want a second up of coffee)
Code:
Code:
[CODE]apt-get -y install virtualbox-4.2
wget http://download.virtualbox.org/virtualbox/4.2.4/Oracle_VM_VirtualBox_Extension_Pack-4.2.4-81684.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.2.4-81684.vbox-extpack
shutdown -r now
May want to do another apt get update and upgrade, to be sure you're up to date:
Code:
Code:
[CODE]apt-get update
apt-get -y upgrade
Next is installing phpVirtualBox. Below will change to the WWW directory of Apache, download the latest version of phpvirtualbox via a handy command I got from the phpVirtualBox web site, extract the phpVirtualBox zip file to the WWW directory and rename that directory to a more convenient name, "vbox".
Obtaining/extracting phpVirtualBox (Click to show) Code:
Code:
[CODE]cd /var/www
wget `wget -q -O - http://phpvirtualbox.googlecode.com/files/LATEST.txt` -O phpvirtualbox-latest.zip
unzip phpvirtualbox-latest.zip -d /var/www/
mv phpvirtualbox-4.2-4/ vbox
Setting up the vbox user (Click to show) The virtualbox installation created the vbox user and user group for us, we just need to add it to the group:
Add vbox user to vboxusers group:
Code:
Code:
[CODE]useradd -m vbox -G vboxusers
Then set the vbox password:
Code:
Code:
[CODE]passwd vbox
I actually used vboxvbox as my password to meet complexity requirements yet make simple enough I'm not going to forget it. This is a limited user account that will only be used for Virtualbox-related operations.
Now copy over the example config file for phpVirtualBox to plain config.php (and copy that as well, but that's really optional)
Code:
Code:
[CODE]cp /var/www/vbox/config.php-example /var/www/vbox/config.php
cp /var/www/vbox/config.php /var/www/vbox/config.php.original
Modifying the phpVirtualBox config file (Click to show) Now for modifying /var/www/vbox/config.php (this can done with either vim or webmin)
Modify these lines as indicated. This is the password used on my system, modify as necessary...
Code:
Code:
[CODE]var $username = 'vbox';
var $password = 'vboxvbox';
This line already exists commented out (with a '#'). You can uncomment it and enter in the host IP address of your server in place of the one supplied:
Code:
Code:
[CODE]var $consoleHost = '192.168.0.115';
This line enables the console tab in phpVirtualBox. Trust me, you want it

Code:
Code:
[CODE]touch /etc/default/virtualbox
Then modify the file with the follwoing lines:
Code:
Code:
[CODE]VBOXWEB_USER=vbox
# these two lines will come into use later
SHUTDOWN_USERS="vbox" # space-delimited list of users who might have runnings vms -- I just put in the only vbox user
SHUTDOWN=savestate # if any are found, suspend them to disk
Once this /etc/default/virtualbox file is saved and closed restart the VirtualBox web service with
Code:
Code:
[CODE]/etc/init.d/vboxweb-service restart
Or rebooting the whole system works just as well.
At this point you should be able to go to ip address of your server/vbox (in my case this is http://192.168.0.115/vbox/ ) and login to the site with the logon of admin/admin.
The first thing that is recommended to do in phpVirtualBox is reset the password for the admin user at the very least.
Next is setting up my example virtual machine, Caprica-V, to start as the host starts and power down properly when the host powers down.
Note that phpVirtualBox is going to look a lot like the regular Windows GUI version of VirtualBox but not act and react exactly the same way. I would have to select an ISO and HDD file at least twice before it would acknowledging the change, for instance. The Machine menu has a refresh option that I found useful several times.
This GUI also has convenient methods of changing where the savestates (Settings-->General-->Advanced tab) are stored and where VirtualMachines will be saved (File-->Preferences) -- useful if you're using a limited size OS boot drive.
Once your VM is setup it would definitely be a good time to start up the VM and then switch over to the Console at upper right. The resolution of the window you will be seeing is definable there. Hit connect and you'll be able to see the OS booting up. You can also enter in that same address in the Windows version of RDP (use mstsc in the run line) to connect to the VM, such as 192.168.0.115:9000.
Setting one particular VM to start up at host boot and power off (savestate) at host power down
change to cd /etc/init.d/, download the template, make the file executable:
change to cd /etc/init.d/, download the template, make the file executable: (Click to show) Code:
Code:
[CODE]cd /etc/init.d/
wget https://raw.github.com/bkidwell/vbox-service-template/master/vbox-service-template
cp vbox-service-template vbox-caprica-v
chmod +x vbox-caprica-v
Editing the newly created init.d VM file (caprica-v) (Click to show) Open the newly created init.d file and fill in these lines as appropriate for your own environment:
Code:
Code:
[CODE]# 4.
VM_LONG_NAME="Caprica-V"
# 5. What user owns the virtual machine?
VM_OWNER=vbox
# 6. Which stop command? "hibernate" or "powerbutton"
VM_STOP=hibernate
# 7. For the 'start-wait' command -- waiting until network is up, what is the
# VM's hostname?
VM_HOSTNAME="caprica-v"
Set the vbox-caprica-v file to start up and the hosts systems startup:
Code:
Code:
[CODE]update-rc.d vbox-caprica-v defaults 90
Only thing left to do is reboot the host machine and see it works or not. During startup you should see a line stating that the virutal machine is trying to startup. If all goes as it should you should now have a running VM. A test of rebooting the host system should be done as well.