Murray Picton

How to install Windows on a Linux server

I recently found a need to use a Windows machine to run a script – particularly some rendering. I was only able to do this using a copy of Windows and therefore found it necessary to work out a way to do this. I didn’t want to have a dedicated Windows machine as it seemed overkill to dedicate a whole machine when only using it for a small amount of processing. I also find Windows completely unreliable and didn’t want to be in a situation where the machine has crashed and I need to perform a hard reboot using virtual hands.

The only option available to me was to find some way of installing Windows on a Linux machine using a Virtual Machine which would allow me to reboot, turn off and allocate resources as necessary.

A few things before I begin -
I am using the latest version of Debian as of today (5.0.5)
You have at least a basic knowledge of the UNIX console
You are going to install Windows XP
You have a decent server with root access
You wish to use Oracle Virtual Box available at http://www.virtualbox.org.
I accept no responsibility whatsoever if, by following my instructions, you manage to cause any damage to yours or anyone else’s system. This set of instructions is meant as a guide only.

Step 1 – Be prepared

The first thing you need to do to set up your virtual machine is become acquainted with the way it works. Take a look at http://www.virtualbox.org, have a read around and try and familiarise yourself.

Once you are happy with Virtual Box, what we need to do is set up a header-less Virtual Box that runs on our server as the server doesn’t have any UI (User Interface). Once we have the header-less Virtual Box working, we need to get it working when we log out of the console and install Windows XP on it.

Step 2 – Setting up the user

To start with we need to create a group and a user for the Virtual Box to run under. We don’t want the virtual box running as root do we? So, lets set up a group called virtualBox, a user called virtualBox with a home directory and give the user a password of VBoxPassword.

$ groupadd virtualBox
$ useradd -d /home/virtualBox -m -g virtualBox -s /bin/bash virtualBox
$ passwd virtualBox
Enter new UNIX password:
$ VBoxPassword
Retype new UNIX password:
$ VBoxPassword
passwd: password updated successfully
$ exit

If you don’t understand the code above, take a look at the groupadd, useradd and passwd functions in the unix manual here. Remember to log out once we have created the user. We don’t want to be logged in as root for the rest of the instructions.

Step 3 – Install VirtualBox

Thanks to the lovely programmers at Debian, installing new software is easier than ever! Let’s get started installing VirtualBox on our system.

First thing’s first, log in as our virtualBox user that we created in step 2. Once we are in, we need to use the su command to have the permissions of root. Next, we need to add the VirtualBox install package location to our apt source list so that when we use aptitude we can install it all nice and easily. We do this by running the following command:

$ echo "deb http://download.virtualbox.org/virtualbox/debian lenny non-free" > /etc/apt/sources.list.d/virtualbox.list

Next, add the key for the VirtualBox installer to the list of accepted aptitude keys using wget and apt-key, or help with wget and apt-key check out the manual pages here. Once this is done, we run the apt-get update function to update our system to the latest versions of everything. See below:

$ wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -
$ apt-get update

Next we need to make sure we have an up to date kernel, so we update linux-headers and then get VirtualBox. Once we are done, lets add the virtualBox user to the vboxusers group. Once we are done, let’s exit su, we have successfully installed VirtualBox and can get started setting up a new virtual machine.

$ aptitude install linux-headers-$(uname -r) build-essential virtualbox-3.2
$ adduser vboxadmin vboxusers
$ exit

Step 4 – Setting up the virtual machine

Now we have VirtualBox installed, we can get started creating our virtual machine. We are going to be using the VBoxManage command that comes when we install VirtualBox. For more information of VBoxManage go here.

First of all, we create our virtual machine and name it “WindowsXP” and register it with VirtualBox.

$ VBoxManage createvm -name "WindowsXP" -register

Next, lets set up the RAM for our VM (virtual machine), I will give my VM 1GB of RAM, I will turn on ACPI, tell it to boot from our virtual DVD and turn on NAT. Once this is all done, I will run the command to create a virtual hard disk (a .vdi file), this time I am going to give 10GB of file space.

$ VBoxManage modifyvm "WindowsXP" --memory "1024" --acpi on --boot1 dvd --nic1 nat
$ VBoxManage createvdi -filename "WindowsXP.vdi" -size 10000 -register

Finally, lets create a controller to access our hard disk, connect the hard disk we created to our VM and then connecting our virtual DVD drive and loading up a disk image of the Windows install disk. I am assuming the install disk has been uploaded to /home/winXp.iso.

$ VBoxManage storagectl "WindowsXP" --name "IDE Controller" --add ide
$ VBoxManage storageattach "WindowsXP" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "WindowsXP.vdi"
$ VBoxManage storageattach "WindowsXP" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium "/home/winXp.iso"

Step 5 – Running the Virtual Box with Screen

To run the virtual box I am going to use screen – this will allow me to start up the box and then close my ssh connection to the box and it will be left running. To install screen, just use apt-get install screen and everything will be installed for you.

Once screen is installed, start it up and then start up the Virtual Box in header-less mode, this will start up a remote desktop connection so we can connect to the ip address and see our new desktop. Once we have it started, let’s detach our screen and exit our ssh client.

$ screen
$ VBoxHeaderless -startvm "WindowsXP"
ctrl+a d
$ exit

Installing Windows

Now we have a virtual machine running, so if we connect to the IP address of our server using remote desktop we can install Windows.

Once Windows is installed – a common problem I had was the mouse was out of sync which made everything really hard. I found a nice fix to put everything ok, it can be found at http://code.google.com/p/virtual-box-windows-guest-additions-installer/ – just install it and restart.

Final words

Installing Windows on a virtual machine allows everything to be a lot more secure. In the past I have had a dedicated Windows machine which causes issues when it crashes or needs a restart – everyone knows Windows doesn’t like to play ball all the time. Having it in a virtual machine allows me to startup, shutdown or restart the box from within Linux – something MUCH more stable.

Check back soon for an example of what you can accomplish with the new Windows virtual box we have set up. Sign up to the RSS feed to make sure you get all the latest updates from by blog.