Friday, January 28, 2011

Install Windows (XP or 7) inside Ubuntu using VirtualBox

You can run both Ubuntu and Windows simultaneously on the same PC. Isn't that cool. Thanks to the virtualization technologies.

Installing VirtualBox OSE

VirtualBox is the most commonly used Virtual Machine Server in Linux. It has got 2 editions. Open-source as well as a closed-source one. Closed-source has got some advantages over the open-source one i.e, it supports RDP and USB devices. Check out the edition differences here.

In this example, we'll be using open source edition of VirtualBox. It is available via the repositories. Make sure universe repositories are enabled. You can look under Software Center > Edit > Software Sources. If they were not enabled previously and you just enabled them, click the Reload button after you click close on the Software Sources window in order to refresh your repository index.

Now, go to Software Center and search for 'virtualbox'. Once you find it, click Install. It will be named VirtualBox OSE there.

Ubuntu Software Center

Creating a new Windows Machine

Once installed, VirtualBox will appear under Applications > Accessories >  VirtualBox OSE. Open it and you'll see a Windows similar to this.


Windows XP won't be listed there in your left column. It is being listed here because I have already installed Windows. So, click the new button near the left top.

Click "Next" on the Wizard page. On the next page, name your Machine e.g, Windows XP Professional or whatever name you want to give it. Under Operating System, Microsoft Windows is pre-selected. Under Version choose your desired Version either Windows XP or Windows 7 or if you are installing some other version, choose that.

VirtualBox, New OS

Click Next. On the next screen, choose Base Memory Size (the amount of RAM you want to assign to your Virtual Windows XP or Windows 7. Use the slider to increase or decrease the amount of RAM.

I would recommend at least 512MB RAM for a nice operation of Windows XP and 1GB RAM for Windows 7 (at least). You can increase that size if you have large amounts of RAM on the host. But make sure, you don't run out of Memory on the host or both of your Operating Systems will slow down.

VirtualBox, RAM Allocation

Click Next. Now you need to create a new HDD for your Virtual Machine. If the default location is selected, it would just appear as a file inside a hidden .VirtualBox directory in your /home directory i.e, ~/.VirtualBox/HardDisks/Windows XP.vdi.

Choose Create new hard disk and click Next.

VirtualBox, HDD Allocation

A new Window with Virtual Disk Creation Wizard will pop up. Click Next on the first page.

On the next page, you'll be presented with 2 choices.Dynamically expanding storage and Fixed-size storage.

Dynamically expanding storage initially creates a small file equal to the size of space required by the base OS. It would keep growing in size as you add software, data to that Operating System. It is a very handy option for users who cannot afford to assign and bind their available disk space to the guest OS. And it is also handy in cases when you don't have an exact clue of how much space you need for the Guest OS and how many software would you be installing.

Fixed-size storage doesn't grow when you add files or data to the Guest OS. It is stored in a file which is nearly equal in size to the amount you specify thus it is called fixed storage.

VirtualBox, HDD Allocation

In this example, we'll be choosing Dynamically expanding storage so choose it and click Next.

You'll be presented with a page with options for the name and location of your Virtual HDD. If you've got enough space on your /home partition, leave it untouched or if you are running out of space on your /home, choose another location.

Choose the maximum size for your Dynamically expanding storage Virtual HDD. It would be reported as the maximum size of the HDD to the guest OS. I would choose 30GB in this case. If you've less space on your /home, choose 10 GB or 20GB or whatever size you want. Click Next and click Finish.

VirtualBox HDD Allocation

Congratulations, you have just created a Virtual Machine.

Windows Installation

Now, it is time to install Windows in your Virtual Machine. On the main VirtualBox window, you'll see that a new machine labeled Windows XP Professional or whatever name you chose during the setup is being listed now. Highlight that name and then from the top menu, click Start.

VirtualBox Main Window

A new window will open and you'll be presented with a First Run Wizard which lets you choose the boot device which you intend to use as an Installation Media. You can choose either a host CD/DVD device or a Windows ISO image on your Host Hard Disk.

Click next and if you want to select any of your CD/DVD devices, choose CD/DVD Rom under Media Type and choose the appropriate device in the drop down menu.

VirtualBox Boot Device

If you want to choose an ISO image, click the folder icon besides the CD/DVD drop down menu. A new window will open. Click Add and give path to your ISO image.

VirtualBox Boot ISO Image

Choose you ISO and click Select.

You'll see that on the First Run Wizard window, your desired ISO image has been selected as the Media Source. Click Next and then Finish.

VirtualBox Boot Device

And once you click Finish, the machine would automatically boot your Media Source and will start the Windows installation process.

Tip: For capturing your mouse and keyboard inside the Virtual Machine, click any where in the Guest OS Window. For releasing it, press Host key. By default Host key is Right Ctrl.

VirtualBox, Windows Installation

Proceed with Windows installation. If you need instruction on how to install it, please refer to your Windows documentation. You can find online resources as well.

Installing Guest Additions

Once you've installed and configured Windows, you can install VirtualBox Guest Additions.

Guest Additions essentially carry device drivers and system applications which optimize the performance of your guest OS. It enables some cool features like auto mouse/keyboard capturing and you don't need to click the Guest Window for capturing your mouse and don't need to press the Right Control for releasing it.

Guest Additions also enable seamless-mode which is a very cool feature. See below for an example of Windows XP running in seam-less mode.

VirtualBox Seamless Mode

For enabling seamless mode, once you've installed Guest Additions, punch Host (Right Ctrl) + L from the Guest OS window.

Guest Additions also enable 3-d acceleration in Guest OS.

For the installation of Guest Additions, on the Window where your Guest OS is running, click Devices in the menu bar and then click, Install Guest Additions. It would download the Guest Addition ISO image and automatically start the installation process. More information here.

Saving the machine state

Another cool feature of VirtualBox is to save the current machine state. When you click the close icon from title bar on your guest window, you are presented with a menu with some choices.

VirtualBox Shutdown Options

If you choose Save the machine state, the state would be saved and when you start the machine again it would start in some super fast time. Test it yourself.

There is also an online manual for VirtualBox and is worth reading. Check it out.


Related Posts:

VirtualBox , Windows