Using VirtualBox: the new era User-Friendly x86 PC Virtualizer

Alexey Eremenko "Technologov"

$Revision: 214 $

$Date: 2007-03-07 23:25:51 +0200 (Wed, 07 Mar 2007) $

From original website: “InnoTek VirtualBox is a general-purpose full virtualizer for x86 hardware. Targeted at server, desktop and embedded use, it is now the only professional-quality virtualization solution that is also Open Source Software.

VirtualBox is a full virtualization solution, that virtualizes the CPU and emulates the rest of PC hardware.

It is similar to other emulators and virtualizers such as Qemu/VMware Workstation/VirtualPC, but it is the only Open-Source software, that has a nice Qt3-based GUI. Unfortunately, all other Open-Source solutions (Bochs/Qemu/Xen) lacking a good GUI and are not User-Friendly. So this is a huge advantage for VirtualBox.

So let's summarize some of it's current features: (as of version 1.3.6)

The future release features will include:

This software requires that both Host and Guest be x86 compatible systems.

I consider this a new era, because until now, Open-Source virtualizers lagged far behind the commercial ones in the ease-of-use and GUI areas. This is revolutionary, because it is the world's first user-frendly Open-Source virtualizer.

This is our community's chance to build a high-quality, user-frendly x86 virtualizer to counter VMware and Microsoft's VirtualPC. I call for community help (see “community” at the More Info section).

Scenarios

  • You want to run some Operating System in guest mode.

  • You want to test new software under different OSes for compatibility.

  • You want to build virtual networks.

  • Server Consolidation: You want to remove old physical servers, and move their functions on new hardware. It will improve server uptime, reduce power consumption, and will enable easier managing of virtual machines. Most important of all: It will save physical space -- real estate.

  • It is not useful for gaming, as it does not support 3D Graphics acceleration.

Understand what are you doing

You are going to emulate a full PC box, all standard hardware, including: normal video card (not 3D accelerator), sound card, network card, RAM, hard disk, CD-ROM, motherboard, BIOS, and virtualize CPU.

On top of it, you will want to run a real Operating System, so make sure you host system has enough CPU power, hard disk space and RAM to handle the load. Main problem here is RAM. I do not recommend systems with less than 512 MB of RAM to even try this. 2 Gigs of RAM is more appropriate for serious use.

VirtualBox is optimized for running heavy guest OSes such as Windows 2000/XP and openSUSE. For running older Windows 95/98, qemu might be a better solution.

Terminology

Host

Your real computer, on which the emulator/virtualizer software runs.

Guest (also known as VM=Virtual Machine)

Your emulated computer, virtual machine, or VM for short, this is what you are trying to emulate. Your target. It can be the same, or very different from your real system.

For example, your host can be a Pentium III PC, while your guest can be a Sony Playstation. Of course, VirtualBox cannot emulate Playstations, so look at different software. It's just important that you understand those two basic concepts.

Emulation

This technique allow conversion of commands, or instructions, one by one, by using software.

There are more optimized algorithms exists, that have different names, such as “Dynamic Recompilation”, “Virtualization”, whatever...

Those are software-optimized or hardware-optimized version of the above. As long as everything works as expected, there are no big difference to the end-user.

Note that VirtualBox is considered to be a virtualizer. However most of the system hardware is emulated, just the CPU is being virtualized. The USB and CD-ROM can be virtualized as well.

For more technical explanation, look: http://www.virtualbox.org/wiki/Virtualization.

Basic Installation Procedure

  1. Download VirtualBox from http://virtualbox.org/wiki/Downloads. Choose “VirtualBox for Linux Hosts” and the “openSUSE RPM” version. This will download a precompiled freeware (proprietary version, free for Personal Usage). I have decided to use this version as it has support from InnoTek, and it is feature-full.

    To install from RPM, just double-click it in konqueror, select “Install Package with Yast”, it will ask for root password, and then it will automatically install the package.

    Alternatively you can download the OSS version. See at “More info” at bottom of this article.

    If this worked fine, please skip the next section.

  2. If installing from RPM doesn't works for some reason, please install from multi-distro installer: Download VirtualBox from http://virtualbox.org/wiki/Downloads. Choose “VirtualBox for Linux Hosts” and the “All distributions” version. This will download a precompiled freeware (proprietary version, free for Personal Usage).

    When installing from “multi-distro”, you also need to install kernel-source and gcc from Yast to compile distro-specific host-side drivers. This will be done automatically.

    To actually install from “multi-distro” use:

    # sh ./VirtualBox_1.3.6_Linux_x86.run install

  3. Setup your user(s) to be part of “vboxusers” group. Yast -> Security and Users -> Group Management -> vboxusers (group) -> Edit -> check tux (user) -> Accept -> Finish

    Warning

    This step is critical, one mistake and VirtualBox will not work !

  4. Restart your system. While this is bad Linux practise, this is important, to get user/group priviledges described earlier to function.

Basic Configuration Procedure

  1. I recommend, that you create a virtual machines directory: (for example ~/vm in your home directory)

    tux@localhost:~> md ~/vm

    This is not a strict requirement, but helps organizing once you get several dozens of VMs.

  2. Start VirtualBox (it apeears on your SUSE/KDE menu, you can search for it, or go directly to: Applications -> System -> Emulator -> VirtualBox )

  3. Configure VirtualBox to respect your ~/vm settings: “File->Global settings”, configure both VDI files and virtual machines to go to ~/vm

  4. Create a new VM named “openSUSE

  5. Set OS type to “Linux 2.6” (as far as I know it doesn't really affects anything, except default RAM and Disk size)

  6. Set Memory to 256 MB (this is how much RAM our VM will have)

  7. Now you got to the Virtual Hard Disk creation step. Do New -> Next -> Dynamically Expanding Image -> Next -> Finish

  8. Great, now we almost completed basic settings for our VM.

  9. To use a real CD-ROM drive do: Select your newly created VM: VM -> Settings -> CD-ROM -> Mount CD-ROM Drive -> Host CD-ROM Drive -> /dev/cdrom -> OK

    Alternatively, you can use an ISO CD-ROM image (virtual CD-ROM) with: VM -> Settings -> CD-ROM -> Mount CD-ROM Drive -> ISO Image File -> (select an ISO image)

  10. If you have chose to install from a real DVD-ROM, then insert your openSUSE DVD now.

  11. If you want Audio on your VM, enable it now with: VM -> Settings -> Audio -> Enable Audio -> Host Audio Driver -> ALSA -> OK

  12. Simple Networking is enabled by default, so don't touch this setting.

  13. Start The VM ! The install should go smoothly, so Enjoy !

Setting up Guest VM Additions

After your VM has been started, you must do: "Devices->Install Guest Additions...".

 Warning

Those are difficult to uninstall, so prior to installing, I recommend you to backup your virtual Hard Disk !

If your guest OS is Windows 2000 or XP, then no problems should arise.

If your guest OS is openSUSE, then your X-Server resolution may go huge due to bug in LinuxAdditions, and your system may become unmanageble. Workaround: set your video RAM to 1 MB.

In any case, a virtual CD-ROM will appear in your VM, so you can setup either VBoxGuestAdditions.exe on Windows Guest or on Linux guest do:

# sh ./VBoxLinuxAdditions.run

 NOTE:

That linux-sources and gcc are required for successful install on Linux guest.

Intermediate Topic: Networking via Host Bridging

In previous section, I said that simple networking is already pre-configured. While true, this so-called simple networking allows for client-side connections only, but disallows me to use complex configurations for servers and virtual networks. VirtualBox has option to use Host netwroking, via TAP interfaces. Both TAP interfaces and bridging is meant to be provided by the host OS.

The required components, which your Host OS is required to have, are:

  • TAP kernel module: check for /dev/net/tun. (exists in openSUSE, pre-installed by default)

  • Userspace app to manage Bridges. bridge-utils. (exists in openSUSE, but must be installed). Please install it via Yast.

  • Userspace app to manage TAP interfaces priviledges. tunctl. (not in openSUSE, must be downloaded).

  1. As we said earlier, tunctl not included with openSUSE. It is part of User-Mode Linux, or UML for short, and can be downloaded from: http://prdownloads.sourceforge.net/user-mode-linux/uml_utilities_20040406.tar.bz2 The setup procedure is standard: (make sure you have gcc)

    # tar xvf uml_utilities_20040406.tar.bz2
    # cd tools/
    # make
    # make install
    

    Now you have tunctl, which is a necessary utility to manage TAP interface priviledges.

  2. Create TAP interface. Set priviledges to user tux.

    # tunctl -t tap0 -u tux
    # ifconfig tap0 0.0.0.0 up
    

  3. Create a bridge, and add interfaces to it:

    # brctl addbr br0
    # brctl addif br0 eth0 tap0
    

  4. Start a DHCP client on your bridged interface. This will copy the MAC address from your physical eth0 interface, and will probably receive the same IP address from DHCP server. This setting is suitable for most Home Settings.

    # dhcpcd br0
    # ifconfig br0 up
    

    Alternatively, you can give static IP address to your bridge interface.

  5. Last, but not least, make sure that all interfaces (eth+tap), that are members of bridge have their IPs removed. Only the bridge interface must have an IP address.

    # ifconfig eth0 0.0.0.0
    

  6. Now, go to VBox GUI, VM -> Settings -> Network -> Attached to: Host Interface -> Interface name=tap0 -> OK

  7. Congratulations ! You should have ping now, both to external world, your Host machine and your Guest machine.

Advanced Topic: How-To USB + openSUSE 10.2

NOTE: This is an advanced topic, because openSUSE 10.2 lacks the needed kernel modules, which means that you have to rebuild your kernel to make USB work.

According to Pablo Sanchez:

I was able to get USB working with openSUSE 10.2 - to be precise, someone else figured it out for VMWare and it applies for VirtualBox.

Many thanks to Alexey Eremenko for the hint on the kernel parameter which needed to be compiled.

The basic upshot is there's a security hole by doing the following so only do this on a secured machine - see https://bugzilla.novell.com/show_bug.cgi?id=210899

Slower bootup of VM:

I've noticed the VM (W2K) takes longer to boot up after this addition. On my Dell Insprion 8200 with a P4/1.6GHz chip, about an extra eight seconds. I didn't collect hard numbers and it doesn't concern me as it's only during boot up of the VM.

Preconditions:

VirtualBox must not be installed; uninstall it in order for it to 'see' the changes. You can install it before the kernel re-compilation or after.

# rpm -e VirtualBox

How to re-add USB support:

  1. Install the following kernel packages:

    - kernel-source
    - kernel-syms
    

  2. Recompile and install the openSUSE 10.2 stock kernel with:

    CONFIG_USB_DEVICEFS=y

  3. Comment out the old 'usbfs' entry in /etc/fstab and replace it with:

    /dev/bus/usb   /proc/bus/usb   usbfs    defaults,devmode=666   0 0

    Note: devmode=666 will allow _anyone_ on your machine to access /dev/bus/usb; this is a security hole

Postconditions:

Re-install VirtualBox.

NOTE: you must use Proprietary version of VirtualBox, as the OSS-version lacks USB support.

Backup, Restore and Porting of VMs Between Physical Machines

First of all, if you installed all your VMs to ~/vm, according to my recommendation, then the job is easier. If not, then your configuration can be found at ~/.VirtualBox/

Your VMs are combined of 3 things: The software - VirtualBox - no major need to backup this usually, as this can be downloaded from the Internet, your virtual hard disk - this is the most important thing to backup, and your VM configuration - which virtual hardware is used. Also, since the versions of VirtualBox are a bit different between Windows and Linux, I have doubt that configuration files will work anyways. This is especially true due to the fact that different machines might have different Host-Network TAP configurations.

I recommend you to save virtual Hard Disks only. I see no need to save VM configurations. This is due to my preference for a rule: 1 file = 1 VM.

  1. Before you back-up them, you can customize according to your needs, install basic utilities, patches, optionally install Guest Additions.

  2. Make sure you shutdown the VM normally, throught Guest OS commands (start->shutdown, or init 0), without pull-virtual-power-plug (do not just close VirtualBox, as this can damage your filesystem on virtual hard disk) and without saved states.

  3. Search for *.vdi to find all Virtual Hard Disks. Now save all your *.vdi files somewhere, perhaps on DVDs. Optionally compress them first with zip, so the archives will be cross-platform.

  4. When you restore your *.vdi files on some other machine, the Host OS can be different. Windows or Linux, doesn't matter.

  5. Create new VMs, and use existing Virtual Hard Disks, from the just restored DVDs.

Interoperability Tip: This method can work for Dual-Boot systems very well. You must have all your .vdi files on NTFS partition, and access it with NTFS-3G driver. Before you restart to a different Host OS, please shutdown GuestOS properly, as described earlier. FAT32 partitions won't work, because they are limited to 4GiB per .vdi file.

Troubleshooting and Tips

  • To release your mouse or keyboard (to use on host computer), simply press right control key.

  • Generally, I would not recommend installing GuestAdditions for Linux inside VM, as they are buggy.

    BUT if you are brave enough, and really want integration to work smoothly then: a) make sure you backup your virtual HDD, as there is no way to uninstall and going back. b) set Video RAM to 1MB as this will allow you to workaround the ultra-hi-resolution in X-Window - a known VirtualBox bug.

  • For USB support, you must use proprietary version (available as freeware).

    According to Dmitriy (coldego at gmail dot com) from VirtualBox users group: in openSuSE 10.2 as host USB support will not work, because CONFIG_USB_DEVICEFS is no longer enabled, not even as a module. Perhaps you will need to upgrade your kernel (by manually compiling it).

  • After changing user/groups permissions, restart your system.

  • If you are stuck in Fullscreen mode, press Right “Ctrl+F”. Left control won't work, and this is done by design.

  • If you encounter bugs, check the latest version. Fortunately, this product improves stability very quickly.

  • Before you upgrade to any new version, it is recommended to uninstall the old one manually, by doing

    # sh ./VirtualBox_1.3.6_Linux_x86.run uninstall

    or for RPM version:

    # rpm -e VirtualBox

    Additionally, unload the driver:

    # rmmod vboxdrv

  • Under some circumstances (usually after experimenting with Host-Networking), your default gateway might be gone from your Host routing table. To restore it manually, do:

    # route  add -net 0.0.0.0 gw 192.168.0.1 dev br0

  • If you still have trouble connecting via Host-Networking, make sure you're Firewall settings are not too restrictive. Check both Host and Guest configuration.

  • When backuping your VMs, small problems may arise:

    a) You might have a problem of changed MAC address, so some guest OSes will install a new NIC driver for you.

    b) Make sure you don't install software that requires specific CPU instructions, such as SSE. (because this will render the VM as non-portable, as not all CPUs support SSE). Fortunately, 99.9% of software don't have this issue.

    c) saved state will get lost, so I recommend you to shutdown the VM properly.

Licensing

This is a bit tricky. This product is dual-licensed under both Open-Source GPL license and a proprietary one. The proprietary version allows for free Personal Use/Educational Use (freeware version) and a commercial version with support for Enterprises.

Basically this means that you can choose which license to use.

The proprietary version has some extra features, notably:

  • USB Support

  • RDP Support

  • USB-over-RDP Support

  • iSCSI Technology

  • Shared folders (available only via command-line)

Thanks

Thanks goes to Thomas Schraitle (thomas.schraitle at suse.de) from Novell for giving me recommendations and tips for improving my writing style and teaching me Docbook XML.

Thanks to Dmitriy (coldego at gmail.com) from VirtualBox user community for explaining the USB problem.

Thanks goes to Pablo Sanchez (pablo from http://www.blueoakdb.com) from VirtualBox user community who contributed USB how-to section to this article on 02.Mar.2007. Thanks him for his agreement to participate in LfL.

For More Information

VirtualBox Home Page: http://www.virtualbox.org

More complete technical information about emulation, virtualization and paravirtualization: http://www.virtualbox.org/wiki/Virtualization

VirtualBox Community Portal: http://virtualbox.org/wiki/Community

VirtualBox Supported Guest OSes: http://www.virtualbox.org/wiki/Guest_OSes

VirtualBox Online documentation: http://www.virtualbox.org/wiki/Documentation

Toubleshooting User FAQ: http://www.virtualbox.org/wiki/User_FAQ

Another setup guide: http://www.howtoforge.com/virtualbox_fedora_centos_opensuse

Benchmark VirtualBox vs Qemu+KQemu vs VMware: http://www.linux-gamers.net/modules/smartsection/item.php?itemid=56

VirtualBox User Guide: /opt/VirtualBox-v1.?.?/UserManual.pdf or simply do: Help->Contents from VirtualBox main app.

VirtualBox OSS: Alternatively, there are new community OSS RPMs available: http://software.opensuse.org/download/virtualization/ or the source code can be downloaded at: http://virtualbox.org/wiki/Downloads. Installing from sources is more headache.

The following link provides the crux of the USB solution: http://www.suseforums.net/index.php?showtopic=27788

VirtualBox direct download: (including GuestAdditions ISO) http://www.virtualbox.org/download/1.3.6/

Other useful links, that discuss UML utilities and tunctl: http://user-mode-linux.sourceforge.net/dl-sf.html and http://user-mode-linux.sourceforge.net/networking.html#daemons

About

Article first released on 12.Feb.2007 by me, Alexey Eremenko. This is version 12, updated on 08.Mar.2007.