Getting your Windows 7 fix in Linux with VirtualBox

Jack Wallen takes you through the steps of installing Windows 7 on VirtualBox so that you can poke around the new Microsoft OS in Linux.

With Windows 7 coming out soon it's an excellent reminder that, when new releases of operating systems come out, it's always nice to have the ability to test them. This makes perfect sense if you are considering rolling out that operating system, or you need to train your staff. In some situations you can just throw that operating system at some hardware and be done with it. But what if you either don't have the spare hardware around or you want more than one user to be able to test that operating system

A virtual environment, created by a piece of software, such as VirtualBox, is an encapsulated environment in which the operating system thinks it is being installed natively. The major benefit is that the operating system reacts as if it is installed natively, so you get full function from your operating system and the subsequent applications you will install.

I'll show you how to install VirtualBox on an Ubuntu 9.04 host followed by a Windows 7 guest installation. Once the Windows 7 installation is complete, I'll go over some configuration tweaks that will make Windows 7 run in a proper resolution and allow you to run the virtual machine remotely.

Installing VirtualBox

I am going to walk you through installing the closed source edition of VirtualBox. There is an open source edition (OSE), but it does not have a few of the features that might be a necessity for business environments such as VRDB (for remote connections) and USB support.

To install VirtualBox on Ubuntu you will first have to add the proper repositories for apt. To do this, open up a terminal window and enter the following command:

sudo nano /etc/apt/sources.list

After you enter your sudo password your sources.list file will be open and you will need to add the following line at the bottom of the file:

deb http://download.virtualbox.org/virtualbox/debian jaunty non-free
Save the file with the [Ctrl]X combination. Before you can update apt you have to add the VirtualBox repository key. First download the key from the VirtualBox site. Save this key to your ~/ directory. Now it's time to add the key with the command:
sudo apt-key add ~/sun_vbox.asc

Once you get the OK from the apt-key command it is time to update apt with the command:

sudo apt-get update

Depending upon the speed of your connection, downloading the headers for the repository shouldn't take too long. Once this has completed, you are ready to issue the command to install VirtualBox. Since the goal is to install the closed source version of VirtualBox, the command to install will be:

sudo apt-get install virtualbox-2.2
During this installation you will have to OK the installation of the kernel module for your current running kernel. If you do not do this, VirtualBox will not run. Once the installation is complete you will need to then add your user to the vboxusers group. To do this, issue the command:
sudo gpasswd -a USERNAME vboxusers

Where USERNAME is the actual name of the user you want to add.

Before you fire up VirtualBox, you will need to take care of one more configuration. In order to enable USB support you have to add the ID of the vboxusers group to a new line in the /etc/fstab file. The first step for this is to find out the ID number of vboxusers, which is done with the following command:

grep vboxusers /etc/group

The above command will report something like:


Where XXX is the ID of your vboxusers group. Now you need to add a new line to the /etc/fstab file. This line will look like:

none /proc/bus/usb usbfs devgid=XXX,devmode=664 0 0

Where XXX is the ID number of your vboxusers group.

Because you installed a new kernel module, as well as added a line to /etc/fstab you may as well, for simplicity's sake, reboot your machine. NOTE: You can have your /etc/fstab take effect without a reboot by issuing the command:
sudo mount -a

But because the kernel module was added, go ahead and reboot. After the reboot is complete, you are ready to fire up VirtualBox.

Running VirtualBox

You will find this version of VirtualBox in GNOME's System Tools submenu of the Application menu. When you first open VirtualBox you will not have any virtual machines listed (as you see in Figure A below). So the first thing you have to do is create a Virtual Machine.

Figure A

Click to enlarge.

Not only can you create new Virtual Machines from this window, you can gather all details and change the settings of your virtual machines.
To create a new Virtual Machine click on the New button to start the Virtual Machine Wizard. From the greeting screen, click Next. The first screen which will require any action is the "VM Name and OS Type" screen (see Figure B). For Windows 7 you are going to fill out the following information:
  • Name: Give this a name indicating the OS version you are using.
  • Operating System: Microsoft Windows
  • Version: Windows 7
Figure B

Click to enlarge

The icon will be selected automatically, based on the operating system.
Once you have filled out this information click the Next button. In the next step (Figure C) you must configure the base memory that will allocated to this virtual machine. Now since we are going to install Windows 7 for this VM, it will require at least 1 GB of RAM to function properly. This will require that your host machine have enough RAM to also function well. Figure C

Even though VirtualBox recommends 512 MB of memory, it will not be enough for Windows 7.
Configure your RAM and click Next. In this new window (Figure D), a hard disk will have to be created. If you have not yet created a hard disk, the hard disk wizard will automatically pop up. If you have an existing hard disk created, you will have to either select "Create new hard disk" (recommended) or "Use existing hard disk." If you choose the latter, you will erase whatever is on your VM hard disk.

Figure D

Make sure Boot Hard Disk is selected.

Click Next and the Create New Virtual Disk Wizard will open. After the Welcome screen, the next window only asks if you want a Dyamic or a Fixed-sized disk. Select Dynamic. A Dynamic disk will expand as needed. So if you create a 10 GB dynamic disk, it will not start out as 10 GB, but will expand to 10 GB as needed. If you create a Fixed-sized disk it will start out and remain as 10 GB. Click Next to continue.

In the next screen (Figure E) you have to configure the location and size of the disk. Most likely the location will already be chosen for you (it should be the name of your Virtual Machine). The size is configured by sliding the the slider to the right or the left depending upon how large or small you want your disk. Select the size and click Next.

Figure E

The final window will allow you to review your choices and complete the disk creation by clicking Finish. When you finish the creation of the disk, you will be taken back to the final window of the VM creation wizard. All that is left is to click the Finish button. Now you'll see the VirtualBox Main Window where your new Virtual Machine is listed (Figure F). Figure F

As you can see, there are two instances of Windows 7 here. This can be helpful for testing releases or just different setups.

Installing Windows 7

The beauty of installing Windows 7 within a Virtual Machine is that the installation will be identical to a standard installation. At this point you just insert the CD into your CD/DVD drive, select your new Virtual Machine, and click the Start button on the VirtualBox main window. The installation will go on as you would expect it to.

The only hitch you will notice will be in the end when you find the Virtual Machine unable to set the proper resolution for the installation. You must install the Guest Additions for VirtualBox. This is simple. While the Virtual Machine is running, go to the Devices menu and select Install Guest Additions (Figure G).

Figure G

The Virtual Machine must be running to install Guest Additions.

Now, you will be warned that the Guest Additions CD can not be found. At the same time, the installation will ask if you want to download the Guest Additions image. Click Yes to okay this, and then Download to download the file. When the download is complete you will have to confirm the mounting of the Guest Additions image. Do this and the installation of Guest Additions will begin. The installation of this tool will be a typical Windows application installation. Once the install is complete, you will need to reboot the Virtual Machine (do this by rebooting Windows 7). When Windows 7 has rebooted you will now enjoy:

  • Better resolution.
  • No need to grab the mouse or release it by clicking the right Ctrl button.
  • Running Windows in seamless mode (not inside of an isolated window).
  • Copying and pasting between guest and host.

Set up Windows 7 to run remotely

A very nice feature of VirtualBox is the ability to run the Virtual Machine remotely. Normally, all that needs to be done is to set the Virtual Machine for remote access within VirtualBox itself. Windows 7 (and Vista as well) is a different case. You also have to set up the operating system to allow remote access. But first let's configure the VirtualBox options.

You first have to close the Virtual Machine. Do not just save the VM state because you will not be able to make any configuration changes. Instead close the VM down. When the VM is powered down, go to the VirtualBox main window, select your Virtual Machine, and click the Settings button. Within the settings window, click on the Remote Display tab and then click the checkbox for "Enable the VRDP Server" (Figure H).

Figure H

If you have need, you can change the port number for the VRDP server.

Click OK and then power your Windows 7 VM back on. You now have to configure Windows 7 to allow remote connections.

When Windows 7 is up and running, click the Start Menu and enter "remote" in the search field. A number of entries will appear (Figure I).

Figure I

From these entries, click on the "Allow remote access to your computer" entry to open up the System Properties Window in the Remote window (Figure J). Make sure "Allow remote assistance connections to this computer" and "Allow connections from computers running any version of Remote Desktop" are checked.

Figure J

Click OK and you are ready to run your Virtual Machine remotely using the tool you prefer to access remote desktops.

Final thoughts

VirtualBox is an amazing tool that will allow you to stretch your budget farther, test your software more securely, train your users more safely, and more. The benefits of employing Virtual Machines are seamingly limitless and VirtualBox makes this not only possible, but simple.


Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website getjackd.net.


Umm two parts in the article that should be addressed. Figure A shows more than zero VMs. The second is that you have not "attached" the CD drive to your VM. The first item is picky, the second makes the installation fail.


Please note that if you run the VM in another host, Windows 7 will reset the activation (probably by detection of different CPU). So if you need to run the same VM of Windows 7 frequently on different host, it becomes a major hassle.


You don't need to set up both virtualbox's remote feature and windows 7's. They are totally separate things. VB's feature will let you see everything from the bios screen to to the finished os but you don't need to change any remote settings in any os to use this. That being said sin 7's rdp implementation is much faster so you would be better off using it for day to day stuff. Aslo I've set up several Ubuntu machines and have never had to touch fstab to get virtualbox working.

Ken Wolf
Ken Wolf

I've been running virtual Win7 machine using VirtualBox. Works great except you do not get to experience the new desktop graphics and special effects. There is currently no support for the WDDM driver support in VirtualBox. Otherwise, it works great in VirtualBox.


Here's a script that will completely setup Virtualbox and allow you to keep it updated as new patches are released. The script will automatically setup the system to get and install Virtualbox, add the current user to the necessary group, and setup the fstab entry. 1. Update the values for your distribution name and the version of Virtualbox you want to install. 2. Save the script into a file (i.e. scriptName.sh). 3. Execute: chmod +x scriptName.sh 4. Execute: ./scriptName.sh Downloading the .deb file is easy, but it requires you to manually update it each time. ########################## Start Script # Set your distribution and Virtualbox values distroCode=jaunty vboxVersion=virtualbox-3.0 # Add the authentication key to APT wget -q http://download.virtualbox.org/virtualbox/debian/sun_vbox.asc -O- | sudo apt-key add - # Create a .list file to add the repository echo "deb http://download.virtualbox.org/virtualbox/debian ${distroCode} non-free" | sudo tee -a /etc/apt/sources.list.d/virtualbox.list # Install packages sudo apt-get update && sudo apt-get install dkms ${vboxVersion} # Add yourself to the new vboxusers group sudo adduser ${USER} vboxusers # Identify the groupid for the vboxusers group and a line to the fstab file. s=`grep vboxusers /etc/group` echo "## usbfs is the USB group in fstab file: none /proc/bus/usb usbfs devgid=${s//[!0-9]/},devmode=664 0 0" | sudo tee -a /etc/fstab ########################## End Script


Normally I abhor writing in all caps but this part is so important that I'll make an exception here: MAKE SURE YOU HAVE THE KERNEL HEADERS INSTALLED FOR YOUR OS, ELSE YOU WILL *NOT* BE ABLE TO START THE VM!!! This can be problematic for anyone using the latest stable kernel (2.6.31 stable) because, even though the kernel has been updated, the kernel headers for 2.6.31 are nowhere to be found as of this post. I'm sure they're coming but, for right now, anyone wanting to run Virtualbox while using this kernel may want to temporarily downgrade to 2.6.30 until the newest kernel headers are out.


Thanks good article, I`ve made Windows 7 on virtualbox and I set up memory to 512MB, tested, works ok, I am happy with the speed.


A good article, but it reminded my why Linux still faces such an uphill battle for the desktop. Approximately a third of the article is devoted to nitty-gritty details about how to get VirtualBox. Although it is great info for True Believers, this is stuff few newbies or would-be converts are likely to want to contend with. Contrast what it takes to get VirtualBox with what it takes to get VirtualPC: For VirtualPC, you browse to its homepage at Microsoft, click the download link, save the file, and then click again to install it. It surely seems easier to install Ubuntu into VirtualPC on Windows7 than to install Windows7 into VirtualBox on Ubuntu.


I would recommend $ sudo apt-get install VirtualBox-3.0, it supports 64bit guests and more than one processor.


Sure you can install Windows 7 with only 512MB RAM, but you won't be able to do much with it before you will be relegated to paging hell. In my experience when you start paging on a VM, it's always a bigger performance hit than if the operating system was running natively. These days RAM is cheap, if you want to test operating systems with VMs, you need to install at least 4GB of RAM on the server, and at least 1GB for Windows guest VMs, more if you are running a lot of applications.


I downloaded the latest VirtualBox .deb file for Ubuntu 9.0.4 from Sun's website. Double-clicked the downloaded file and VirtualBox installed successfully without any further actions from me. What could be easier! I added my name to the vboxusers group by System > Administration > Users and Groups > Unlock > my password > Authenticate > select my user name from the list of users > Manage Groups > select vboxusers from the list of groups > Add Group. No terminal command needed although that would be easier. Guest Additions installed without issues. You only need to add the line to fstab for USB support.


You may know this already, but there is a Windows version for Virtual Box that works just as good as the Linux version. I use both, the Linux version at home and the Windows(XP)version at work. Both are easy to use to set up a virtual machine. With regards to the Linux installation...most distributions include VB OSE and Non-OSE. True the Linux version does require some additional steps that may seem daunting to a new user, especially if you are wanting to use the virtual machine in a bridged adapter mode. The distro I use has available a script that makes the installation even easier. But hey, weren't we all "newbies" at one time? It took a desire to learn how to accomplish the things we wanted to do. We all went through a learning curve with Windows. Linux has it's learning curve as well. Yes, it's different but then Linux does not claim to be Windows and personally, that is just fine with me. It's not perfect, neither is Windows.


Almost all of those steps is more about setting up virtualbox ON UBUNTU. noone ever said you had to use Linux. Nowhere in the post. If you think that those steps are too complicated, then don't use linux. I know it is shocking to actually think that you shouldn't comment on something you don't know anything about.


In both cases either Win7 as a guest on an Ubuntu machine, or viceversa you will definitely need more than 2 GB of ram. Even though Win7 is more adaptable than Vista.


Don't you need to have Windows 7 installed somewhere to use VirtualPC (at least the download link I checked did)? The point is testing prior to deployment. You can do that very well with VirtualBox, which also runs on Windows XP or Vista. It is also a simple download and click to install for the Windows platforms, and doesn't require a CPU with Intel Virtualization Technology or AMD-V enabled in the BIOS. And, it is free and simply works.


In Kubuntu (at least in Kubuntu 8), you could go into the package management software, go in and find the update you wanted to add, mark it, click a button to install it from the Linux "universe", and you were set. You can do that for any Linux repositoried app in the "universe". And, it's not difficult at all. In fact, I would say it's probably easy as finding anything on MS's website. I know KnowledgeBase has become a nightmare.


Thank you for reinforcing my main point. When Linux appears too complicated, people will use something else. Just as you suggest. As an aside, thanks to the other posters who provided insights on easier ways to install VirtualBox.

Editor's Picks