Skip to content

VirtualBox on a Headless Debian Server

I’ve got too many computers.  It’s become increasingly difficult to convince people “I’m not *that* nerdy” when I have servers and wires laying around everywhere.  A consolidation project is in order.

For this exercise, our goal is to combine a Linux file server and a Windows workstation elegantly into one machine.  “Windows?!?!” you gasp in horror?  No need to be alarmed; I use Linux/BSD exclusively on servers and Mac OS X on my desktops.  I have only one very specific need for a standalone Windows machine, so let’s leave it at that for now.

The Linux file server is headless and of course doesn’t run X-Windows or any other GUI.  I need to have a full Windows environment available which I can RDP into at any time.  I first experimented with Xen which is a solid enterprise solution but overkill for this project.  Next, I spent a significant amount of time with KVM which is easy to set up but has a bit of quirky management in my opinion.  Finally, I settled upon Oracle VirtualBox; it’s free, fast, and can be elegantly controlled at the command line.

We’ll be using Debian 5.0 (Lenny) on a Dell Poweredge T110 with 2GB of RAM for the base file server. Let’s get started with the installation.

1. Add the VirtualBox repositories to apt-get via the sources.lst file:

nano -w /etc/apt/sources.lst
deb http://download.virtualbox.org/virtualbox/debian lenny non-free

2. Download and install Oracle’s APT key:

wget http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
apt-key add oracle_vbox.asc
OK

3. Install VirtualBox and DKMS:
According to the information found here, DKMS ensures that the VirtualBox host kernel modules are properly updated the next time your kernel is updated.

apt-get update
apt-get install dkms
apt-get install virtualbox-3.2

4. Add your local user to the “vboxusers” group:

adduser andrei vboxusers

Now, be sure to su out of root and into your local user environment.

5. Create the virtual machine:
We will name it “Windows XP SP3” and configure it to have 512MB of RAM, have the first boot device as a virtual DVD, and include bridged networking.

VBoxManage createvm -name "Windows XP SP3" --ostype WindowsXP -register
VBoxManage modifyvm "Windows XP SP3" --memory "512" --acpi on --boot1 dvd --nic1 bridged --bridgeadapter1 eth0

6. Create a virtual IDE controller:
Right off the bat, some of you may point out that SATA is a faster interface than IDE and may question my sanity.  Well, indeed you are correct and the VirtualBox documentation confirms the performance advantages of SATA.  However, Windows XP doesn’t have any native SATA support at install time so instead of fiddling around with a virtual floppy drive image to load via “F6” at the blue DOS install screen, we’ll switch over to SATA after the OS is loaded and the proper drivers are installed.

VBoxManage storagectl "Windows XP SP3" --name IDE0 --add ide

7. Create the virtual hard drive.
Here, I chose to have a 500GB virtual HD of fixed size.  When selecting a “fixed” virtual drive, all the space is allocated up front so you need to plan accordingly.  However, the better IO performance of the “fixed” drive over the “standard” expanding drive, which grows and shrinks on demand, is worth the extra space allocation for me personally.

VBoxManage createhd -filename "Windows XP SP3.vdi" --size 512000 --variant Fixed  --remember

This takes a long time – go make a protein shake.

8. Attach the virtual hard drive to the virtual machine:

VBoxManage storageattach "Windows XP SP3" --storagectl IDE0 --port 0 --device 0 --type hdd --medium /home/andrei/.VirtualBox/HardDisks/"Windows XP SP3.vdi"

9. Attach Windows XP ISO to virtual DVD drive of virtual machine:

VBoxManage storageattach "Windows XP SP3" --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium /home/andrei/windows_xp.iso

10. Start the virtual machine:

VBoxHeadless -startvm "Windows XP SP3" &

11. Log into your virtual machine and install XP:
Using a Remote Desktop Client, log to the VM as you would any standard server over port 3389 (RDP default) with the IP of the host (physical server) machine.  You should see the Windows installation screen and you can go through the install steps as normal.

12. Install VirtualBox Guest Additions
The first thing you will want to do after XP has been loaded is install the VirtualBox Guest Additions.  Otherwise, the quirkiness of the mouse, as you may have noticed during the install, will drive you absolutely nuts.

VBoxManage storageattach "Windows XP SP3" --storagectl IDE0 --port 1 --device 0 --type dvddrive --medium /usr/share/virtualbox/VBoxGuestAdditions.iso

13. Switch from IDE to SATA for increased performance:

  • Power off the virtual machine.
  • Add a SATA controller to your VM:
    VBoxManage storagectl "Windows XP SP3" --name SATA0 --add sata
  • Start your VM:
    VBoxHeadless -startvm "Windows XP SP3" &
  • Download install the Intel Matrix Storage Manager
  • Power off the virtual machine again.
  • Remove the HD from the IDE controller:
    VBoxManage storageattach "Windows XP SP3" --storagectl IDE0 --port 0 --device 0 --type hdd --medium none
  • Add the HD to the SATA controller:
    VBoxManage storageattach "Windows XP SP3" --storagectl SATA0 --port 0 --device 0 --type hdd --medium /home/andrei/.VirtualBox/HardDisks/"Windows XP SP3.vdi"

You should now have a fully-working Windows XP environment ready for hours of fun installing Windows Updates and random software which should have been included in the base OS.  Feel free to let me know if you need any help with your own VirtualBox Headless installation as you go through the steps I’ve covered here.

EDIT (10/29/10) – A big “thank you” goes to Tim (@7coding) from http://7coding.com for catching two typos in this post!

Categories: Linux.

Tags: , , , , , ,