#==============================================
#           INSTALLING VIRTUALBOX .deb
#==============================================
# Add the virtualbox .deb repository to your apt sources
echo "deb http://download.virtualbox.org/virtualbox/debian lenny non-free" > /etc/apt/sources.list.d/virtualbox.list

# Add the Oracle key to your apt keystore
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | apt-key add -

# Update aptitude
aptitude update
aptitude upgrade

# Install the latest kernel headers and essential build tools for your Debian installation
aptitude install linux-headers-$(uname -r) build-essential

# Download DKMS* (Dynamic Kernel Module Support)
wget http://www.backports.org/debian/pool/main/d/dkms/dkms_2.1.1.2-2~bpo50+1_all.deb

# Install DKMS using dpkg
dpkg -i dkms_2.1.1.2-2~bpo50+1_all.deb

# Install the latest version of VirtualBox (3.2 at time of writing)
aptitude install virtualbox-3.2

#==============================================
#  CREATE AND CONFIGURE VM USING COMMAND LINE
#==============================================

# Create a new Virtual Machine called XP and register it with VirtualBox
VBoxManage createvm --name XP --register

# 1GB mem, ACPI, boot from DVD, NAT networking
VBoxManage modifyvm XP --memory 1024 --acpi on --boot1 dvd --nic1 nat

# Create a new hard disk image called XP.vdi (10GB - change to suit your needs)
VBoxManage createhd --filename XP.vdi --size 10000 --register

# Create an IDE controller
VBoxManage storagectl XP --name "IDE Controller" --add ide

# Attach hard disk image to IDE port 0 device 0
VBoxManage storageattach XP --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium XP.vdi

# Attach Windows XP installer CD image to IDE port 1 device 0
VBoxManage storageattach XP --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium /home/chris/XP_DISC.iso

#==============================================
#  INSTALL WINDOWS INSIDE THE VM
#==============================================

# Start the VM to start the Windows XP installation process
VBoxHeadless --startvm XP

# To remotely manage the Windows install connect to your VirtualBox server
# from a Windows box using Remote Desktop Connection to IP_of_VirtualBox_server:3389
# or from a Linux machine using
rdesktop-vrdp IP_of_VirtualBox_server:3389

#==============================================
#  INSTALL GUEST ADDITIONS TO THE VM
#==============================================

# Helps with acceleration and correct mouse behaviour
VBoxManage modifyvm XP --dvd /usr/share/virtualbox/VBoxGuestAdditions.iso

#==============================================
#  START YOUR VM ON YOUR HEADLESS SERVER
#==============================================

VBoxHeadless --startvm XP

#==============================================
#                    FINISH
#==============================================