Configuring, Installing and Running VirtualBox 3.04 on Ubuntu 9.04

This article explains how to install and configure VirtualBox 3.04 on Ubuntu 9.04. It also shows how to connect hard drives and USB devices to a virtual machine (VM) running under VirtualBox. It then explains how to create a virtual machine after VirtualBox is installed and how to connect the hard drives to a virtual machine.

Installing Required Software

We will not be using the VirtualBox version contained in the normal Ubuntu repositories. Instead, we will set up the package manager to get the latest version of VirtualBox from the VirtualBox repository.

Much of the installation action will take place using the command line, so you must start up a terminal from the Ubuntu Applicatons | Accessories menu. The first thing we will do from the terminal is to edit the package manager's repository list so we can access the latest version of VirtualBox. Enter the following command:

     sudo gedit /etc/apt/sources.list

This will start up the GUI text editor in superuser mode so we can edit the sources.list system file. In the text editor, at the bottom of the file, add the following line:

     deb jaunty non-free

Note that this is the line for Jaunty Jackalope (Ubuntu 9.04) only. There are other lines for other versions of Linux that can be used.

Save the sources.list file and close the text editor. Now we need to add the VirtualBox repository's public key to the system so we can access the repository. Enter the following on the command line:

     wget -q -O- |
        sudo apt-key add -

The first part of this gets the public key and the second part adds it to our keys.

The package manager's file database can now be updated with the new repository information. To do that, enter the following command line:

     sudo aptitude update

That takes care of the preliminaries. We are now ready to install VirtualBox.

At the same time, we will also install two other packages. The first is called 'dkms' and it ensures that VirtualBox is correctly updated when that becomes necessary. The second package is a program called 'pysdm', which assists us in setting up hard drives so they are always available when we boot our Ubuntu machine. Enter the following command line to install these three packages:

     sudo aptitude install virtualbox-3.0 dkms pysdm

The three packages will be downloaded and installed. While VirtualBox is being installed, you will see the following dialog in the terminal program:

Installation dialog

This is a reminder to us that we will have to add a new group to our user. That will be done in another step later in this article.

There might also be a couple of dialogs displayed that indicate that another module needs to be compiled. If you see the dialogs, let the compilation proceed.

When this step is completed, the VirtualBox, dkms and pysdm programs have been installed on your system.

Joining Groups and Configuring Hard Drives

Now that the VirtualBox package is installed, we need to configure to use it. The first thing we will do is add ourselves as a member of the VirtualBox group, so we can actually use the program. From Ubuntu's System | Administration menu, click on Users and Groups. You will see a dialog that allows you to look at the users for your Ubuntu system. We need to unlock this dialog so we can change it, so click on the Unlock button:

Unlock Users and Groups Dialog

You will then be asked for your password:

Enter password

Enter your password and then click on Authenticate. This will unlock all the buttons on the Users and Groups dialog. Highlight your own username, then click on Manage Groups:

Select Manage Groups

This will bring up the Group Settings dialog. Scroll down to the bottom of the display and highlight the entry called 'vboxusers', then click on the Properties button:

Select Properties

The Properties dialog will show a list of all the users on your system. The ones with a check mark next to them belong to the vboxusers group. Check the box next to your name, then click on the Ok button:

Add User to Group

You have now finished adding yourself as a user to the VirtualBox group.

Before we go on to actually use VirtualBox, we need to set up any hard drives that need to be automatically mounted so a VirtualBox VM will always see them. If you have no hard drives like that, you can skip the rest of this section.

To set up the hard drives, we will use the pysdm helper program to create entries in our fstab file. On the command line, enter the following:

     sudo pysdm

We must run this program as superuser since the program is owned by the superuser. It will never show up in our user's menu system. The program will display something like the following:

Storage Device Manager

Pick one of the hard drives that you wish to mount automatically. Note that in the example, I have picked a drive that uses an NTFS file system (Windows drive). When you have chosen a drive, click on the Assistant button. You will then be presented with the Select Options dialog:

Select Options

In the example, we have checked the first three options and unchecked any others. Note that the second option sets the hard drive up so it will automatically be mounted when you boot Linux. When you finish configuring the drive, click the Ok button. Back at the Storage Device manager, click the Mount button to actually mount the hard disk. This will be the only time you will have to do that manually.

Repeat this process for all the hard disks you wish to automatically mount on startup. When you finish, click the Apply button, then the Close button to exit from pysdm.

Create a VirtualBox VM

Before we proceed, we need to log out of Ubuntu, then back in. We do this so VirtualBox will show up in the Application Menu (Under System Tools). Select the menu item and VirtualBox will start. You will want to create a virtual machine. Click on the Machine | New menu item:

This will start up the Virtual Machine Wizard:

Clicking the Next button will take you to the VM Name and OS Type screen. Enter a descriptive name for the VM and choose the approximate category of operating system you will install into the VM. The VM we will create will host Windows 2000, so that is what I picked. Click the Next button when you have finished with this page. You will then be presented with the Memory requirements page:

This is where you tell VirtualBox how much memory the VM thinks it has. That depends on how much memory your Ubuntu machine has in it. You should probably never go beyond about half of the amount of memory in your native machine. You can use the slider to select the amount, or you can enter it directly into the edit box. Click on the Next button when you have finished with this page. You will then be presented with the Virtual Hard Disk page:

You can select an existing virtual hard drive if you have one, or you can create a new one. We will select Create new hard disk, then click on the Next button to get the Virtual Disk Wizard:

Click on the Next button to get to the Hard Disk Storage Type page:

You should read this page carefully and decide which type of storage you want. I chose Dynamically expanding storage for our example. When you have decided, click the Next button to get to the Virtual Disk Location and Size page:

You can put the virtual hard disk files anywhere, but I usually chose the default, which puts the file in the same directory as the VM. As for size, you should pick something that will comfortably meet your storage needs. Keep in mind that this creates a file in your Ubuntu home directory, which will eventually be the size you have selected. You must have enough room in your Home partition to hold the file. When you have finished with these selections, click the Next button to get to the Summary page:

Review your selections and if they are all right, click on Finish to close the Virtual Disk Wizard and to create the virtual disk. You will then be back in the Virtual Machine Wizard dialog at its Summary page:

When you click the Finish button, the new VM will be created and it will be added to the list of VMs on your system:

At this point, you should put the setup disk for the operating system you will be installing into your CD drive, then select the VM we just created and click on the Start button to start up the VM. Inside the VM, the boot order allows the Cd drive to be accessed first, so you can start installing the operating system into the VM. We will leave that as an exercise for the user, but note that the pseudo-hardware that a VirtualBox VM presents to the OS install program is generic and there are drivers available for all the pieces. You should be able to easily install the OS.

Connecting Hard Drives to the VM

After the OS is installed and running in the VM, you can then connect the hard drives to your VM. Click on the Devices | Shared Folders menu item in the running VM window:

The Add Share dialog will pop up. Pull down the Folder Path item and select Other:

The Shared Folders dialog will pop up. This is where you can permanently add Ubuntu system resources (including USB devices) as drives for the VM. We will be making a permanent addition, so we will select the Machine Folders item and click on the Add button:

A standard Select Folder dialog will appear:

You can select a mounted drive from here as I have done, or you can select any directory and mount it like a hard drive. That includes any USB devices you should find in the /media directory. When you have made your selection, click on the Open button to add the selection as a 'hard drive' to the VM. You will end up back in the Add Share dialog:

I have check the Make permanent box so this drive will always be mounted when I start up the VM. Click the Ok button and you are off and running in a brand new operating system running inside of your Ubuntu installation.