Install VirtualBox Virtual machine on a remote server

The objective is to install MS Windows running as a VirtualBox image on a remote host provided with GNU/Linux Debian Wheezy.
This is just an example to have a mixed Linux/Windows environment, the same procedure applies to any other OS.

Windows will be set as host-only mode with IP address, bound to vboxnet0
The home local network is referenced as

Add apt VirtualBox repo to Debian and VB key

# deb wheezy contrib

# wget

# apt-key add oracle_vbox.asc

Initial preparation and settings, run as root (or better with sudo):

# wget

# VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-4.3.12-93733.vbox-extpack

# VBoxManage list extpacks

Create the VirtualBox network interface vboxnet0 (run as normal user).

$ VBoxManage hostonlyif create ipconfig vboxnet0 --ip --netmask

Create the virtual machine:

$ VBoxManage createvm --name "My Windows 7 64bit" --ostype 'Windows7_64' --register
Virtual machine 'My Windows 7 64bit' is created and registered.
 UUID:  <uuid number>
 Settings file: '/home/myuser/VirtualBox VMs/My Windows 7 64bit/My Windows 7 64bit.vbox'
$ VBoxManage modifyvm "My Windows 7 64bit" --memory 2048 --acpi on --boot1 dvd --boot2 disk --nic1 hostonly --hostonlyadapter1 vboxnet0

Create the VM main disk

$ VBoxManage createhd --filename "My_Windows_7_64.vdi" --size 15000

Add the storage controller, and attach the disk

$ VBoxManage storagectl "My Windows 7 64bit" --name "SATA Controller" --add sata --controller IntelAHCI
$ VBoxManage storageattach "My Windows 7 64bit" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "My_Windows_7_64.vdi"

then the IDE controller for CDROM and ISO image

$ VBoxManage storagectl "My Windows 7 64bit" --name "IDE Controller" --add ide
$ VBoxManage storageattach "My Windows 7 64bit" --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium /home/myuser/iso/windows_7.iso
$ VBoxHeadless --startvm "My Windows 7 64bit" --vrde on --vrdeproperty TCP/Address=

Setup a tunnel from your home workstation to connect to VirtualBox inside the remote server:

$ ssh -L

Or later, a tunnel to connect directly to the installed Windows 7 RDP service

$ ssh -L

Now you can RDP into your local workstation and  connect to VirtualBox or Windows

$ rdp

Few iptables rules allow Windows to reach out to the internet

# sysctl -w net.ipv4.ip_forward=1
# iptables -A FORWARD -o eth0 -i vboxnet0 -s -m conntrack --ctstate NEW -j ACCEPT
# iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE
# iptables -I INPUT 3 -i vboxnet0 -j ACCEPT

Everything should work by now.

Uh, and remember to add your user to the VirtualBox group otherwise some command won’t work as intended ;)

A couple of issues I’ve encountered:

Mouse pointer offset when connecting Windows through VirtualBox RDP.
VirtualBox vboxnet0 is not available after the server reboot.

Leave a Comment