VirtualBox 3.1: Beginner's Guide

By Alfonso V. Romero
    What do you get with a Packt Subscription?

  • Instant access to this title and 7,500+ eBooks & Videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Getting to Work with VirtualBox

About this book

The furore around virtualization is taking the technology world by storm and is a must for efficient utilization of network server capacity, storage administration, energy, and capital. VirtualBox is free and this brings down your upfront costs for an agile data center. VirtualBox will transform your IT infrastructure into a lean Data Center on a Windows XP/7 or Ubuntu Linux platform. Although VirtualBox has grown by leaps and bounds, there is not enough documentation to guide you through its features and implementation.

This hands-on guide gives you a thorough introduction to this award-winning virtualization product. It will help you to implement the right virtual environment for you. Additionally, this book will help you set up an environment that will work for your system. You will learn to architect and deploy your first virtual machine without being overwhelmed by technical details.

This practical book unveils the robust capabilities and easy-to-use graphical interface of VirtualBox to help you to effectively administer and use virtual machines in a home/office environment. You begin by creating your first virtual machine on a Windows/Linux guest operating system and installing guest additions. The book then goes on to discuss the various formats that VirtualBox supports and how it interacts with other formats. The comprehensive instructions will help you to work with all the networking modes offered by VirtualBox. Virtual appliances will be explained in detail—how they help to reduce installation time for virtual machines and run them from VirtualBox.

By the end of this book you will be able to run your own headless VirtualBox server, to create, manage, and run virtual machines in that server from a remote PC.

Publication date:
April 2010


Chapter 1. Getting to Work with VirtualBox

Hi, and welcome to this book about VirtualBox, the best virtualization software I've ever used! Instead of boring you with a chapter full of theory to explain all the "knicks and knacks" about VirtualBox, I'm going to give you a tiny introduction to virtualization and then jump straight ahead into the installation process, ok?

In this chapter you will:

  • Learn about virtualization and how you can take advantage of this technology

  • Learn to install VirtualBox on Windows XP

  • Learn to install VirtualBox on Ubuntu Linux

And now, let the show begin...


Running multiple virtual machines

The first time I heard about VirtualBox was when I was looking for something to help me make tutorials for Windows users trying to learn to use Linux. I needed something to help me run Ubuntu Linux inside my main Windows XP PC to write my tutorials in MS Word, capture all the Linux screenshots, and paste them directly into the MS Word document. I've worked with this excellent and powerful virtualization software since version 2.0, and I definitely give two thumbs up to the guys in the development team because version 3 has come a really long way, as we'll see throughout the exercises in this book, especially in areas related to the 3D Acceleration and USB support features.

For those of you new to virtualization, let me put it this way: With VirtualBox, you can use a Windows, Linux, Mac OS X, or Solaris PC to run one or more 'virtual' PCs inside it. Each virtual machine is called a guest, and your main PC is called a host. The bottom line is that you can run one 'host' operating system and several 'guest' operating systems inside that 'host'!

For example, if you have a Windows PC with 4 GB of RAM and a 320 GB hard disk, you can use VirtualBox to run three virtual machines side by side on the same computer running Windows. The following table shows how you can distribute your physical resources among the three virtual machines and your Windows PC:




Windows XP (host)


Hard Disk: 80 GB

This is your physical machine.

Linux Virtual Machine (guest 1)


Hard Disk: 80 GB

This is the first virtual machine. You can use practically any Linux distro available!

Open Solaris Virtual Machine (guest 2)


Hard Disk: 80 GB

This is the free, open source version of the Solaris operating system.

Windows 7 Virtual Machine (guest 3)


This is a new Windows release.

Naturally, you don't need to use all your VMs at the same time! Most of the time, you'll end up having a lot of virtual machines on your host PC and running only one or two of them in parallel. And don't worry about your computer's resources. Having an 80 GB virtual hard disk doesn't mean that your virtual machine is going to take up all that storage space immediately. Thanks to VirtualBox, you can have dynamically expanding storage, which means the initial size of your virtual machine's hard disk will be very small, and it will increase its size to take up more space as needed.

That means you can have more than four virtual machines with 80 GB hard drives on the Windows XP host computer, in the above example, because their virtual hard drives won't take up their full size immediately. However, it's better to keep in mind your physical hard disk space limitations when creating your virtual machines in order to avoid the typical problems that arise when your hard disk is full!

But that's enough chatter for now! You'll learn more about virtualization and VirtualBox with all the exercises I've prepared throughout the book, so let's get going!


Installing VirtualBox on Windows

Now let's get our hands dirty with the first exercise in this chapter! If you're going to install VirtualBox on Linux, feel free to skip this section. I'm going to use Windows XP in this exercise because it's currently the most widely used version of Windows. But the procedure is similar in Windows Vista or Windows 7, so you can use whichever one suits your needs the best.


Time for action – downloading and installing VirtualBox on Windows

In this exercise, you'll see how easy it is to download VirtualBox and install it in a Windows XP system.

  1. Open your Web browser, and type in the address bar. The VirtualBox main page will appear:

  2. Click on the Downloads link located in the left sidebar. The Download VirtualBox page will show up:

  3. Now click on the x86/amd64 link at the right of the VirtualBox 3.1.X for Windows hosts line. A dialog box will pop up, asking if you want to open or save the VirtualBox installation file. Click on Save to start downloading this file.

  4. Once the downloading process ends, double-click on the downloaded file (it should be something like VirtualBox-3.X.X-X-Win.exe), and wait for the Do you want to open this file? warning dialog box to appear. Click on Run, and the Sun xVM VirtualBox Setup dialog will appear:

  5. Click on the Next button to start installing VirtualBox on your PC. The next dialog will ask you to read the VirtualBox Personal Use and Evaluation License (PUEL). If you agree with it, select the I accept the terms in the License Agreement radio button, and click on Next to continue.

  6. The next dialog, Custom Setup, will show you the VirtualBox features that will be installed as well as the installation directory. Leave the default options, and click on Next to continue:

  7. On the next dialog, you need to choose if you want to create a shortcut to run VirtualBox from the desktop and/or from the Quick Task Bar. You can leave both options selected, and click on Next to continue.

  8. The next dialog will warn you about temporarily disconnecting you from the local area network because the setup program will install the Sun xVM VirtualBox Networking feature:

  9. Click on Yes, and then on Install to start installing VirtualBox on your computer:

  10. Once the installation process finishes, you'll see the following dialog:

  11. Click on Finish to exit the setup wizard and open the VirtualBox main window. The VirtualBox Registration Dialog will appear next:

  12. If you already have a Sun account, just fill in your email and password, and click on the Register button to register your copy of VirtualBox. If this is the first time you're using a Sun product, select the I would like to register creating a new Sun Online account radio button, and fill in the required fields. Then click on Register. Once you register with Sun, you'll see the following success dialog:

  13. Now click on the OK button to go to the VirtualBox main screen:

  14. You can close VirtualBox now.

What just happened?

See how easy it was to download and install VirtualBox on Windows? And wait until you start using it! You'll start wondering why someone didn't come up with VirtualBox ten years ago! Seriously speaking, however, you can use VirtualBox on the following Windows platforms:

  • Windows XP, all service packs (32-bit)

  • Windows Server 2003 (32-bit)

  • Windows Vista (32-bit and 64-bit).

  • Windows Server 2008 (32-bit and 64-bit)

  • Windows 7 (32-bit and 64-bit)

And the installation process is very similar, if not identical, on most Windows versions. Just be sure to have enough RAM for your physical 'host' PC and one or more 'guest' virtual machines. Oh, and you have to be careful with hard disk space also! But you don't need to worry about that right now; we'll cover all those things throughout the exercises in this book.

Have a go hero – experiment with VirtualBox on Windows

If you have the ability to do so, it would be a great idea to try VirtualBox on other Windows versions, especially on Windows 7, the most recent Windows release. You can also start browsing around VirtualBox's user interface and see if you can create a virtual machine by yourself!


Installing VirtualBox on Linux

If you read the previous section about installing VirtualBox on Windows, then this will be your second hands-on exercise, but if you skipped the Windows section, let's go and get our hands dirty with VirtualBox and Ubuntu Linux!


Time for action – downloading and Installing VirtualBox on Linux

Ok, for this exercise you'll need a copy of Ubuntu Linux already installed on your PC. I chose Ubuntu because it's one of the friendliest Linux distributions available, as you will see in a moment.

  1. Before installing VirtualBox, you'll need to install two additional packages on your Ubuntu system. Open a terminal window (Applications | Accessories | Terminal), and type sudo apt-get update, followed by Enter. If Ubuntu asks for your administrative password, type it, and hit Enter to continue.

  2. Once the package list is updated, type sudo apt-get install dkms, and hit Enter; then type Y and hit Enter to install the DKMS package.

  3. The other package needed before you can install VirtualBox is build-essential. This package contains all the compiling tools VirtualBox needs to build the kernel module. Type sudo apt-get install build-essential, and hit Enter. Then type Y, and hit Enter again to continue. Wait for the $ prompt to show up again, type exit, and hit Enter to close the terminal window. Now you can proceed to install VirtualBox.

  4. Open the Synaptic Package Manager (System | Administration | Synaptic Package Manager), and select the Settings | Repositories option in the menu bar (if Ubuntu asks for your administrative password, type it, and press Enter to continue):

  5. The Software Sources dialog will appear. Click on the Other (on earlier Ubuntu versions the name of this tab is Third-Party Software)and then on the Add+ button:

  6. Another dialog box will show up. Now type deb karmic non-free on the APT line field, and click on the Add Source button:


    If you're not using Ubuntu 9.10 Karmic Koala, then you'll need to change the APT line in the previous step. For example, if you're using Ubuntu 9.04 Jaunty Jackalope, replace the karmic part with jaunty. On the webpage, you'll find more information about installing VirtualBox on several Linux distributions and the APT line required for each Ubuntu distribution available.

  7. The third-party software source for VirtualBox will now show up on the list:

  8. Now open a terminal window (Applications | Accessories | Terminal), and type wget -q to download the Sun public key:

  9. Go back to the Synaptic Manager, select the Authentication tab, and click on the Import Key File button:

  10. The Import Key dialog will appear next. Select the sun_vbox.asc file you just downloaded, and click on the OK button to continue:

  11. The Sun public key for VirtualBox should now appear on the list:

  12. You can now delete the Sun public key file you downloaded earlier. Click on the Close button to return to the Synaptic Package Manager. If the Repositories Changed dialog shows up, select the Never show this message again checkbox, and click on Close to continue.

  13. Now click on the Synaptic Package Manager's Reload button to update your package sources with the most recent VirtualBox version:

  14. Once the Synaptic Package Manager finishes updating the package sources list, click on the Origin button located at the lower-left part of the window and select the repository from the window above this button:

  15. Click on the most recent virtualbox-3.X package checkbox in the right window, and select the Mark for Installation option:


    When upgrading to a newer VirtualBox version, you must first completely remove the older version. Then you'll be able to install the newest version without any hassles.

  16. The Mark additional required changes? dialog box will appear next. Click on the Mark button to mark all the additional packages required to install VirtualBox:

  17. Now click on the Apply button in the Synaptic Package Manager:

  18. The Apply the following changes? dialog box will appear next. Make sure the Download package files only option is deselected, and click on the Apply button to start installing the required packages, along with VirtualBox:

  19. The Synaptic Package Manager will start downloading the required packages and, when finished, it will install them along with VirtualBox.

  20. Eventually, the Configuring virtualbox-3.X dialog will appear:

  21. Click on Forward to continue configuring VirtualBox. The configuration wizard will ask if you want to compile the vboxdrv kernel module. Make sure that option is selected, and click on Forward to continue:

  22. Wait until Debconf compiles the kernel module and finishes all the configuration procedure for VirtualBox. After that, the following dialog will appear:

  23. This means VirtualBox installed successfully. Click on the Close button to continue and close the Synaptic Package Manager.

  24. Open a terminal window, type sudo usermod -a -G vboxusers yourusername, and hit Enter to add your username to the vboxusers group. Don't forget to replace yourusername with your own username. Then type exit, and hit Enter again to close the terminal window.

  25. Logout from Ubuntu, and then log back in. Now you can access VirtualBox through the Ubuntu menu bar (Applications | System Tools | Sun VirtualBox):

  26. After opening VirtualBox for the first time, you'll see the VirtualBox License dialog. Scroll down to the end of the agreement, and then click on the I Agree button to continue.

  27. Next you'll see the VirtualBox Registration Dialog:

  28. If you already have a Sun account, just fill in your email and password, and click on the Register button to register your copy of VirtualBox. If this is the first time you're using a Sun product, select the I would like to register creating a new Sun Online account radio button, and fill in the required fields. Then click on Register. Once you register with Sun, you'll see a success dialog:

  29. Now click on the OK button to go to the VirtualBox main screen:

  30. You can close VirtualBox now.

What just happened?

Ok, ok… Installing VirtualBox on Linux is a little more elaborated process, but hey, I was behind you all the time, right? On Linux there are some additional things to consider when you're installing a software application like VirtualBox. I decided to show you how to use the Synaptic Package Manager because this wonderful piece of open source software takes care of all the complicated things that always come up when installing something in Linux.

On the first three steps of the previous exercise, you upgraded the Ubuntu packages list and then installed a couple of packages required by VirtualBox on a Linux installation. These packages prepare your system for building the external modules VirtualBox needs to operate virtual machines. The DKMS (Dynamic Kernel Module Support) package allows your system to build these modules dynamically, so you don't have to worry in case you upgrade your Ubuntu system. The build-essential package contains the gcc compiler and some other tools required to compile and build the kernel modules. The Synaptic Package Manager uses repositories scattered throughout Internet. To install VirtualBox, we had to add a specific repository called because the standard Ubuntu installation only includes the virtualbox-ose package, the OSE (Open Source) version of VirtualBox. In this book we're going to work with the PUEL (Personal Use and Evaluation License) version of VirtualBox because it's free for personal/academic use or for product evaluation.

Basically, the PUEL version of VirtualBox has some features that aren't included in the OSE version:

  • USB support: You can insert USB devices on your host PC and use them in your virtual machines.

  • RDP (Remote Display Protocol) server: The PUEL version of VirtualBox includes a complete RDP server, so you can connect to remote virtual machines from any RDP compatible client.

  • USB over RDP: This means a virtual machine can access the USB devices connected to the remote computer on which the RDP client is running.

Finally, we also have to add the Sun public key because Synaptic won't be able to access the VirtualBox PUEL repository otherwise. After that, you just need to select the desired VirtualBox version, and Synaptic will take care of the rest for you.

Once you've installed VirtualBox on Linux, the process for creating and using virtual machines will be the same on any platform.

Have a go hero – experimenting with VirtualBox on Linux

If you have the ability and resources, would be a great idea to try VirtualBox on other Linux distros, but you need to make an extra effort because not every distribution uses the Synaptic Package Manager. But the VirtualBox website has some basic information on how to install VirtualBox on several Linux distros such as Debian, Fedora, Red Hat, or SuSE. The website provides several specific packages for some of the most popular Linux distributions and one general package for the rest of the Linux distros available. And remember you can always send me an email in case you get stuck!

Oh, and you can also start to browse around VirtualBox's user interface. Go on and experiment all you can and try to create a virtual machine by yourself!


Testing VirtualBox

Ok, you have VirtualBox installed and ready to go. Are we going to wait until Chapter 2 to start using this wonderful piece of software? Naah! Let's take it for a little test drive...


Time for action – creating and testing a Damn Small Linux virtual machine

In this next exercise, you'll download Damn Small Linux, one of the smallest Linux distros currently available, and then I'll show you how to create a quick virtual machine on your brand new VirtualBox software in order to test it!

  1. Open your web browser, and type The What is DSL? page will show up:

  2. Scroll down the page until you locate the Download link, or go to the page directly, and scroll down to the Current Full Mirror List section:

  3. Click on an HTTP link (in this case, I chose the second link, and then on the current link of the next page:

  4. On the next page, scroll down until you locate the dsl-4.4.10.iso, and click on it to start downloading the DSL ISO file:

  5. A dialog box will pop up, asking if you want to open or save the DSL ISO file. Click on Save to start downloading this file:

  6. Once the downloading process ends, open VirtualBox, and click on the New button to create a new virtual machine:

  7. The Welcome to the New Virtual Machine Wizard dialog will show up. Click on Next to continue:

  8. The VM Name and OS Type dialog will appear next. Type DSLTest in the Name field, select Linux as the Operating System and Debian as the Version, then click on Next to continue:

  9. Leave the default 256 MB value as the Base Memory Size in the Memory dialog, and click on Next to continue:

  10. Leave the default Create new hard disk option on the Virtual Hard Disk dialog. Make sure the Boot Hard Disk (Primary Master) option is selected, and click on Next to continue:

  11. Now the Welcome to the Create New Virtual Disk Wizard! dialog box will appear. Click on Next to continue, and leave the Dynamically expanding storage option selected as the Storage Type in the Hard Disk Storage Type dialog:

  12. In the next dialog (Virtual Disk Location and Size), leave the DSLTest and 8.00 GB default options for Location and Size, respectively, and click on Next to continue:

  13. Now the wizard will show you a Summary of all the parameters for the virtual disk of your virtual machine. Click on Finish to continue:

  14. The last dialog will show you a Summary of all the parameters selected for your new virtual machine. Click on Finish to continue:

  15. After creating the virtual machine, it will show up in VirtualBox's main screen:

  16. Now click on the Settings button to open the DSLTest - Settings dialog box. Select the CD/DVD-ROM category from the list on the left side, click on the Mount CD/DVD Drive checkbox, and then select the ISO Image File option:

  17. Next, click on the Invoke Virtual Media Manager button:

  18. The Virtual Media Manager dialog will appear. Click on the Add button to continue:

  19. The Select a CD/DVD-ROM disk image file dialog box will show up next. Navigate to the directory where you downloaded the dsl*.iso image, and click on the Open button to continue:

  20. Now the DSL ISO image will appear in the CD/DVD Images list of the Virtual Media Manager:

  21. Click on Select to return to the DSLTest – Settings dialog box, and then click on OK to return to VirtualBox's main screen.

  22. Click on the Start button to start your virtual machine. The VirtualBox – Information dialog box will show up to inform you that you need to use the Right-Ctrl key to alternate between using the keyboard in your virtual machine and your host PC. Select the Do not show this message again checkbox, and click on OK to continue:

  23. The DSL virtual machine will start to boot. Wait until a VirtualBox – Information dialog box appears to tell you that the virtual machine is using 16 bit color instead of 32 bit. Select the Do not show this message again checkbox, and click on OK to continue.

  24. Click inside the virtual machine's screen with your mouse, and another VirtualBox – Information dialog will show up to inform you that you need to use the Right-Ctrl key to alternate between using the mouse in your virtual machine and your host PC. Select the Do not show this message again checkbox, and click on Capture to continue.

  25. Wait for a few minutes for DSL to start booting up. When it is finished, the following screen will show up:

  26. Now you have created your first virtual machine!

What just happened?

Whew! I must admit that this was a lengthy exercise! Thanks to VirtualBox's user-friendly interface, you've just learned how to create this test virtual machine with one of Linux's smallest distros available: Damn Small Linux (DSL for short). In fact, it's so small, it doesn't even need a hard disk to work properly! I hope you had fun with this exercise, and don't worry about all the settings involved in creating a virtual machine; we'll have enough exercises to deal with them throughout the rest of the book!

For now, just concentrate on the virtual machine creation process as a whole: Click on the New button, select the operating system you want to use, assign a chunk of memory and hard disk space to your new virtual machine, and tell it where to boot an ISO image with the operating system of your choice, as if it were just another ordinary PC in your desk!

Have a go hero – creating more virtual machines

Now that you've created a test virtual machine, go on and download other Linux distributions, and try to create other virtual machines; experiment with different settings for RAM and hard disk space.


Just remember to never assign more than half of your physical RAM to a virtual machine because your main PC could collapse!

We'll talk more about this later. For now, just keep experimenting with all the VirtualBox features you can! And if you have any questions, feel free to email the Packt team at !

Pop quiz – doing the thing

  1. What would be the best definition of a virtual machine?

    1. A physical PC connected to a LAN.

    2. A 'guest' machine running inside another 'host' machine.

    3. A computer with lots of RAM and hard disk space.

  2. You need to use MS Word to write a document, but the only available PC at the moment is running Linux. The best thing you can do is:

    1. Cry and pull your hair out in despair.

    2. Install VirtualBox on your Linux PC, create a Windows XP virtual machine, and install MS Word.

    3. Go out and buy a new Windows Vista PC with MS Word installed.

  3. Virtualization means…

    1. Sharing one physical PC between two or more virtual machines to maximize resource usage.

    2. To surf the web looking for new applications.

    3. Running two or more operating systems in one PC.



This chapter was a hands-on introduction to VirtualBox, the best virtualization software out there!

Specifically, we covered:

  • What virtualization is, and how we can use VirtualBox to run several virtual machines inside a physical host

  • How to install VirtualBox on Windows environments

  • How to install VirtualBox on Linux environments

  • How to create, configure, and run a test virtual machine

Now that you have VirtualBox installed and running, you're ready to delve into the VirtualBox world! In the following chapter, I'll show you how to create, configure, and run your own Ubuntu Linux virtual machine in any host operating system supported by VirtualBox!

About the Author

  • Alfonso V. Romero

    Alfonso Romero is a freelance computer consultant and translator from Mexico. He's been working with Linux and open source software since 1999. He started operating his first web server (Apache) from a PC at home, offering free hosting services to experiment with Postfix, Squirrel Mail, MySQL, Apache, Tomcat, and Virtual Hosting. Since then, he's been working as a computer consultant for several clients in Mexico – writing Java, C++, and Web applications. Since 2000, he has worked for Pearson Education in Mexico as a computer books freelance translator and consultant. His latest book translations are the Spanish versions of Java How to Program, Seventh Edition, from Deitel & Deitel, and C++ How to Program, Sixth Edition, also from Deitel & Deitel. Al enjoys writing tutorials and teaching about Java, C++, PHP, the Apache Web server, Tomcat, MySQL, Web applications like Apache Roller, and all of the wonderful open source applications used today, and when he's not experimenting with new trends in Open Source applications, he enjoys playing his electric guitar.

    Browse publications by this author
VirtualBox 3.1: Beginner's Guide
Unlock this book and the full library FREE for 7 days
Start now