{"id":2936,"date":"2013-10-21T20:18:37","date_gmt":"2013-10-21T19:18:37","guid":{"rendered":"http:\/\/blog.ed.gs\/?p=2936"},"modified":"2013-10-21T20:18:37","modified_gmt":"2013-10-21T19:18:37","slug":"installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3","status":"publish","type":"post","link":"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/","title":{"rendered":"Installing Windows Server 2012 on Ubuntu 12.04 with VirtualBox 4.3"},"content":{"rendered":"

My current day job is basically working in numerous schools looking after their networks of computers. I’ve tried to minimise the amount of running computers in my house due to space and rising electricity costs. I have the ed.gs dedicated server hosted by FastHosts, so I thought it would be good to create a constantly accessible Windows machine for testing and other shenanigans that arise from working with Windows networks, taking advantage of the spare resources available on the server. I’ve used VirtualBox many times before, but only with its GUI; the ed.gs box is an Ubuntu server with no GUI, so it was time to get my hands dirty. Below is the simplified process I went through to create a Window Server 2012 R2 installation, using only the command line and a single publicly accessible IP address. Running all the commands should be enough to get a basic image up and running on most servers, as long as you have the VirtualBox deb files and Windows Server ISO ready on your server.<\/p>\n

Note: Windows Server 2012 R2 is specifically supported by VirtualBox 4.3 and above.<\/p>\n

Download the latest version of VirtualBox from their site @ https:\/\/www.virtualbox.org\/wiki\/Linux_Downloads<\/a>. You could use apt-get if you wish, but as of writing this the latest version available was 4.1 from official apt repositories and 4.2 was the latest PPA<\/a> release. The deb file on their site does the job nicely, so just use that. Here’s the one I downloaded for Ubuntu 12.04 x64.<\/p>\n

wget http://download.virtualbox.org/virtualbox/4.3.0/virtualbox-4.3_4.3.0-89960~Ubuntu~precise_amd64.deb<\/pre>\n

We also need to download the VirtualBox Extension Pack to enable remote access for installation, it can be downloaded from the VirtualBox downloads page or from the link below for the 4.3 compatible version.<\/p>\n

wget http://download.virtualbox.org/virtualbox/4.3.0/Oracle_VM_VirtualBox_Extension_Pack-4.3.0-89960.vbox-extpack<\/pre>\n

Download the Windows Server 2012 R2 ISO and put it somewhere you’ll remember like your home directory.<\/p>\n

Install VirtualBox.<\/p>\n

dpkg -i virtualbox-4.3_4.3.0-89960~Ubuntu~precise_amd64.deb<\/pre>\n

If all that went ok we should now be able to create the virtual machine, so let’s create it.<\/p>\n

VBoxManage createvm --name "YourVMNameHere" --register<\/pre>\n

This creates the initial vbox file that we will be using throughout. Change the YourVMNameHere to anything you like, make it something memorable and possible easy to type as we’ll be using it a fair bit.<\/p>\n

Next we need to create the virtual hard drive so we can install Windows Server and have some storage.<\/p>\n

VBoxManage createhd --filename "YourHDNameHere" --size 102400<\/pre>\n

Again, change the YourHDNameHere to whatever you like and remember it, I kept mine the same as the virtual machine’s name. The –size attribute is the size of the hard drive in megabytes, 102400 is 100GB. It won’t create the 100GB file straight away, but it will allow you to fill it over time up to that size.<\/p>\n

We have to set the OS type and add some RAM next.<\/p>\n

VBoxManage modifyvm "YourVMNameHere" --ostype Windows2012_64 --memory 2048 --acpi on --ioapic on --vram 128 --accelerate3d off --nic1 nat --nictype1 82545EM --cableconnected1 on --audio alsa --audiocontroller ac97<\/pre>\n

As you can see we used the modifyvm command to change the “ostype” to Windows2012_64, R2 isn’t shown as an option currently, and memory to 2048mb of RAM. We also need to enable ACPI and IOAPIC so that Windows Server will boot, if you miss either of these you’ll get stuck at the initial Windows boot screen where it will tell you something is corrupt. vram is video ram, you can add as little or as much as you like, it shouldn’t matter as we will be accessing the server via remote desktop connection. We need to disable accelerate3d as it may not be supported. nic1 creates the network connection, we want to use NAT as we only have one IP and no DHCP\/DNS set up to handle IPs for us, we don’t need to make any either, it just makes it more complicated. nictype is the network card, 82545EM is an Intel 1000mb\/s Server card which will suit us fine. Then we flag the cableconnected1 parameter so the VM knows it’s connected. Finally we add some audio support with the last two parameters.<\/p>\n

Now we need to create a storage controller so we can add the HDD and DVD drive.<\/p>\n

VBoxManage storagectl "YourVMNameHere" --name SATA --add sata --controller IntelAhci --bootable on<\/pre>\n
VBoxManage storagectl "YourVMNameHere" --name IDE --add ide --controller PIIX4 --bootable on<\/pre>\n

This creates the HDD and DVD drives but we still need to attach them, so we can do that with the following.<\/p>\n

VBoxManage storageattach "YourVMNameHere" --storagectl SATA --port 0 --device 0 --type hdd --medium "/location/of/YourHDNameHere.vdi"<\/pre>\n

The location will most likely be in your home directory e.g. \/home\/ed\/VirtualBox\\ VMs\/YourHDNameHere.vdi.<\/small><\/p>\n

VBoxManage storageattach "YourVMNameHere" --storagectl IDE --port 0 --device 0 --type dvddrive --medium "/location/of/your/WindowsServer2012R2.iso"<\/pre>\n

Before starting VirtualBox up we need to activate the Remote Desktop server that will start when the VM starts up. We need to activate the extension pack we downloaded earlier using the command below.<\/p>\n

VBoxManage extpack install /path/to/Oracle_VM_VirtualBox_Extension_Pack-4.3.0-89960.vbox-extpack<\/pre>\n

Now we need to modify the VM to accept the remote connections and forward through all connections on the RDP port we’re using later on.<\/p>\n

VBoxManage modifyvm "YourVMNameHere" --vrde on --vrdeport 3390 --vrdeaddress 0.0.0.0\nVBoxManage modifyvm "YourVMNameHere" --natpf1 "winrdp,tcp,,3389,,3389"<\/pre>\n

If you’re using iptables, which I hope you are, you will also need to allow the connection through.<\/p>\n

/sbin/iptables -A INPUT -p tcp -m tcp --dport 3390 -j ACCEPT<\/pre>\n

We can now start the VM.<\/p>\n

VBoxHeadless --startvm "YourVMNameHere" -e "TCP/Ports=3390" &<\/pre>\n

You can now use the Microsoft Remote Desktop Connection tool to connect to the VM at your host server’s IP and port 3390 e.g. running <\/p>\n

"mstsc 102.134.142.13:3390"<\/pre>\n

on Windows. There’s no username or password to connect.<\/p>\n

Setup Windows Server as you wish. Enable remote desktop connections in Server Manager and disable the firewall for all connections.<\/p>\n

Shutdown Windows Server and disable the vrde flag with the following.<\/p>\n

VBoxManage modifyvm "YourVMServerName" --vrde off<\/pre>\n

Enable port 3389 in iptables. You may also want to add the line to your \/etc\/rc.local so it will recreate the firewall rule on system startup.<\/p>\n

/sbin/iptables -A INPUT -p tcp -m tcp --dport 3389 -j ACCEPT<\/pre>\n

Create an init.d script so you can start and stop the VM at will. Edit all of the YourVMNameHere placeholders.<\/p>\n

#! /bin/sh\n# /etc/init.d/YourVMNameHere\n# Edit these variables!\n\nVMUSER=YourUsername\nVMNAME="YourVMNameHere"\n\ncase "$1" in\n  start)\n    echo "Starting VirtualBox VM..."\n    sudo -H -b -u $VMUSER VBoxHeadless --vrdp=off --startvm "$VMNAME"\n    ;;\n  stop)\n    echo "Saving state of Virtualbox VM..."\n    sudo -H -u  $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate\n    ;;\n  poweroff)\n    echo "Powering off Virtualbox VM..."\n    sudo -H -u  $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" poweroff\n    ;;\n  *)\n    echo "Usage: /etc/init.d/StartVM {start|stop|poweroff}"\n    exit 1\n    ;;\nesac\n\nexit 0<\/pre>\n

Add the init.d script to run at startup and stop before the rest of the server shuts down.<\/p>\n

update-rc.d YourVMNameHere defaults 99 01<\/pre>\n

You can now start\/stop\/poweroff the server using the following commands<\/p>\n

service YourVMNameHere start<\/pre>\n
service YourVMNameHere stop<\/pre>\n
service YourVMNameHere poweroff<\/pre>\n

Have fun, as always if anything isn’t working or I’ve made a mistake let me know in the comments or contact page.<\/p>\n","protected":false},"excerpt":{"rendered":"

My current day job is basically working in numerous schools looking after their networks of computers. I’ve tried to minimise the amount of running computers in my house due to space and rising electricity costs. I have the ed.gs dedicated server hosted by FastHosts, so I thought it would be good to create a constantly […]<\/p>\n","protected":false},"author":2,"featured_media":3438,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[41,68,70,71],"tags":[],"yoast_head":"\nInstalling Windows Server 2012 on Ubuntu 12.04 with VirtualBox 4.3 - E<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Installing Windows Server 2012 on Ubuntu 12.04 with VirtualBox 4.3 - E\" \/>\n<meta property=\"og:description\" content=\"My current day job is basically working in numerous schools looking after their networks of computers. I’ve tried to minimise the amount of running computers in my house due to space and rising electricity costs. I have the ed.gs dedicated server hosted by FastHosts, so I thought it would be good to create a constantly […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/\" \/>\n<meta property=\"og:site_name\" content=\"E\" \/>\n<meta property=\"article:published_time\" content=\"2013-10-21T19:18:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.ed.gs\/wp-content\/uploads\/2013\/10\/chamomile-829220_1280.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"847\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ed\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ed\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/\",\"url\":\"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/\",\"name\":\"Installing Windows Server 2012 on Ubuntu 12.04 with VirtualBox 4.3 - E\",\"isPartOf\":{\"@id\":\"https:\/\/ed.gs\/#website\"},\"datePublished\":\"2013-10-21T19:18:37+00:00\",\"dateModified\":\"2013-10-21T19:18:37+00:00\",\"author\":{\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ed.gs\/#website\",\"url\":\"https:\/\/ed.gs\/\",\"name\":\"E\",\"description\":\"automation, consultancy, project management, web\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ed.gs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\",\"name\":\"Ed\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"caption\":\"Ed\"},\"url\":\"https:\/\/ed.gs\/author\/ed\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Installing Windows Server 2012 on Ubuntu 12.04 with VirtualBox 4.3 - E","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/","og_locale":"en_GB","og_type":"article","og_title":"Installing Windows Server 2012 on Ubuntu 12.04 with VirtualBox 4.3 - E","og_description":"My current day job is basically working in numerous schools looking after their networks of computers. I’ve tried to minimise the amount of running computers in my house due to space and rising electricity costs. I have the ed.gs dedicated server hosted by FastHosts, so I thought it would be good to create a constantly […]","og_url":"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/","og_site_name":"E","article_published_time":"2013-10-21T19:18:37+00:00","og_image":[{"width":1280,"height":847,"url":"https:\/\/static.ed.gs\/wp-content\/uploads\/2013\/10\/chamomile-829220_1280.jpg","type":"image\/jpeg"}],"author":"Ed","twitter_misc":{"Written by":"Ed","Estimated reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/","url":"https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/","name":"Installing Windows Server 2012 on Ubuntu 12.04 with VirtualBox 4.3 - E","isPartOf":{"@id":"https:\/\/ed.gs\/#website"},"datePublished":"2013-10-21T19:18:37+00:00","dateModified":"2013-10-21T19:18:37+00:00","author":{"@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ed.gs\/2013\/10\/21\/installing-windows-server-2012-ubuntu-12-04-virtualbox-4-3\/"]}]},{"@type":"WebSite","@id":"https:\/\/ed.gs\/#website","url":"https:\/\/ed.gs\/","name":"E","description":"automation, consultancy, project management, web","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ed.gs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628","name":"Ed","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/ed.gs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","caption":"Ed"},"url":"https:\/\/ed.gs\/author\/ed\/"}]}},"_links":{"self":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/2936"}],"collection":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/comments?post=2936"}],"version-history":[{"count":0,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/2936\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media\/3438"}],"wp:attachment":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media?parent=2936"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/categories?post=2936"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/tags?post=2936"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}