Tuesday, July 29, 2008

HOWTO: Install MS Windows in Ubuntu with VirtualBox

Step 1:Step Install and Configure VirtualBox

VirtualBox is one of the best virtualization apps I have ever seen. I put it right up there against VMWare Workstation, and it tends to perform better in my opinion.
In Edgy, you can download and install VirtualBox by either using Automatix (http://www.getautomatix.com) or by installing the .deb from http://www.virtualbox.org
I personally installed it through Automatix and find that the easiest route as it makes sure you have everything else you need for it. You can find VirtualBox under the Virtualization section of Automatix.

Ok, once you have VirtualBox installed we are going to make a new virtual machine.


Step 1a: Setting Up a Virtual Machine


Open up the VirtualBox app by selecting it from Applications->System Tools->InnoTek VirtualBox.
Click the “New” button at the top to bring up the New Virtual Machine Wizard.
Click Next
Type in a name for your Windows installation. I labeled mine: Windows XP Professional, but you can name yours whatever you feel like.
Choose your Os Type from the dropdown. (Important note: this seamless setup will only work with a version of Windows that can act as a Terminal Server that means XP Pro NOT Home, and Vista Business or Ultimate, Windows Server 2003, and/or Windows 2000 Professional)
Next adjust your base memory size. VirtualBox recommends 192MB for Windows XP, but I personally find that XP runs a bit slow at this level. I have 2GB of RAM on my machine so I gave XP 600 MB. Choose whatever amount you are comfortable with, and this can always be adjusted later.
Next we will choose our “hard disk” to boot into. Click the “New” button unless you already have a VirtualBox image ready, then click the “Existing” button.
After clicking New, you will be greeted by the Virtual Disk Wizard, click Next
Choose whether or not you want a Dynamically expanding image. I personally like using it because I am not entirely sure how much space I will use, but that it is up to you. After choosing, click Next.
Pick a name for your image file and adjust the size to the amount of space you would like to offer for your drive. Then click Next.
To finish the new drive creation click Finish
Your new disk you just created should be selected, click Next.
Click Finish to complete setting up your new Virtual Machine


Step 1b: Configuring Your Virtual Machine


Select your new machine from the list of machines on the left and click the Settings button at the top of VirtualBox.
Select CD/DVD-ROM and click Mount CD/DVD Drive, then choose whether or not you would like to mount your physical CD drive or an iso file. ( I personally ripped my XP Install CD to an ISO file because I think the install goes faster than off the physical CD)
Now, select Network and from the “Attached to” dropdown box select Host Interface. In the Interface Name field type in: tap0
(This will make more sense later)
Now, select Remote Display and check Enable VRDP Server.
Finally, click the OK button to save all of these settings.

Ok, we now have our VirtualBox Machine ready to boot up and install windows, however we are going to configure a few things on the Ubuntu side first.

Step 2: Setup Ubuntu Networking

Before I go down this road with you there are a few things I need to make known. First, I have only tested this setup on a desktop with a physical, wired network connection. It may work wirelessly, but I have not tested it. Also if you make use of Network Manager, you will need to make sure it doesn't run anymore. You can do that easily, without uninstalling it, by simply creating two files with the word: exit as the only thing in them. Use your favorite editor, mine is pico, and create these files like this:
(Quick pico reference: to exit a file and choose whether or not to save it use: Ctrl+x)


Code:
sudo pico /etc/default/NetworkManager
sudo pico /etc/default/NetworkManagerDispatcherIf you had to add those two files then you can reboot to see that Network Manager will not start up anymore. To turn it back on simply remove those files. If you are sitting there and are thinking “But I HAVE to use Network Manager, my is only supported by it!” Then my friend, I apologize but you may be SOL. Start digging through the forums to see if there is an alternative way to run your connection. My guess is there probably is.

Ok, now that that's out of the way let's move on.
We first need to install some important packages:

Code:
sudo apt-get install bridge-utils uml-utilitiesNext we are going to setup our /etc/rc.local file.

Code:
sudo pico /etc/rc.localAppend the following information directly above the line that says “exit 0”


Code:
tunctl -t tap0 -u
chmod 0666 /dev/net/tun
/usr/sbin/brctl addbr br0
/sbin/ifconfig eth0 0.0.0.0 promisc
/usr/sbin/brctl addif br0 eth0
/sbin/dhclient br0
/usr/sbin/brctl addif br0 tap0
ifconfig tap0 up
bash -c 'echo 1 > /proc/sys/net/ipv4/conf/tap0/proxy_arp'
route add -host dev tap0
arp -Ds eth0 pub


Ok, there are some EXTREMELY important things to note here.

First off replace with the username you use to login to your Ubuntu desktop. (Mine is ranjan).

Next, you need to replace with an IP that is within your subnet. It doesn't matter what it is, I use 192.168.1.161 simply because it was open. The only requirement is that there isn't another device on your network with this IP. This IP will come in handy when your Windows install is not accessible over the network. Confusing I know, but it will make more sense later.

Next, you need to replace with the IP of your Ubuntu installation on your network. If you use DHCP be careful. I do, but I setup my router to always give me the IP of 192.168.1.160. Static or DHCP, you need to put your IP here.

Lastly, take a look at all the places where I have eth0. For many installations this will probably be your main network device, but it could be something else like ath0,eth1,etc. Make sure you change eth0 to whatever your primary network interface is. (The device that you access the network with)

Ok, if you feel up to it you can parse out all the lines we just put in the /etc/rc.local file and run them one by one. Or you can easily activate these settings by simply rebooting.

Step 3: Configure your Windows Virtual Machine

Ok, now we are going to boot up our Windows Virtual Machine. Go ahead and boot up your VM by opening up Applications->System Tools->InnoTek VirtualBox and then selecting your virtual machine and clicking the “Start” button.

I am not going to walk you through installing Windows, because it is mind numbingly boring and I am betting, that if you are reading this guide, chances are you have wasted many hours of your life reinstalling Windows. When you are done installing it come back to this guide to continue.

Welcome back! I hope you had a fun time. Now there are several Windows settings we will need to do. (Note: These settings worked for me in Windows XP Pro, if you are using another edition of Windows they may be the same, i.e. registry keys and such, or not. However I can personally confirm that they work flawlessly in Windows XP Pro.)

First thing you have to do in Windows is enable Remote Connections and set a password for your user.
Go to Start -> Control Panel -> Sytem and click the Remote tab.
Check the box that says “Allow users to connect remotely to this computer” and click OK
In the Control Panel click “User Accounts”
Click the user that you would like to login as and then click “Create a password”
Type your password in the boxes provided and then click the “Create Password” button.

Now we are going to adjust a couple registry keys that drove me up the wall. By default XP Pro comes configured to only allow remote access at 16 bit color. Well, frankly this looks like butt on your desktop especially when you have a slick Beryl interface. So we are going to change that.

Go to Start and select Run, in the box type regedit and hit OK
In the registry editor navigate to the following key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Terminal Server\WinStations\RDP-Tcp
In the right hand pane, highlight the ColorDepth key and right-click. Select Modify and change the “Value Data” field to 4

Next, we need to set it up so that your Windows install only displays the Task bar and not the desktop on login.
In the registry editor navigate to the following key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre nt Version\Policies\Explorer
Create a new DWORD value that you'll call NoDesktop and set its value to 1

Now, we need to set our Windows install up so that it logs in your specified user in automatically.
Go to Start -> Run. type control userpasswords2 into the box and click OK
Uncheck “Users must enter a user name and password to use this computer” and click Apply
A box will come up asking what user name and password you would like to have logged in automatically. Fill this out with whatever user/pass info you have setup.

Now we need to install VirtualBox's Guest Additions for seamless mouse movements (thanks merovius for pointing this out)
Click the VM dropdown list at the top of your Virtual Machine window
Click Install Guest Additions
Follow the onscreen installer to install the additions

Our last step is to read the network IP that Windows is using
Go to Start -> Control Panel -> Network Connections
Right click Local Area Connection and click Status
Click the Support tab and record the IP Address, it will become important later

Note: This IP address has to be DIFFERENT than the Virtual Box IP that you put in the /etc/rc.local file. If it is not different then configure windows to use a different IP or configure your router to give your Windows install a different IP.

No comments: