5.2 Oracle VM VirtualBox Guest Platform
VirtualBox supports the execution of guest operating systems in fully virtualized machines—a capability that allows the guest to run without requiring any special software or device drivers. The guest operating system is presented with a virtual motherboard with the following features.
- 1 to 32 CPUs
- Up to 32 GB of memory
- A dual-channel IDE disk controller with up to four devices
- An optional Serial ATA (SATA) disk controller with up to 30 attached devices
- An optional SCSI controller with up to 16 attached devices
- Up to 8 PCI network host adapters
- Keyboard, video, and mouse (KVM) console
- Either a legacy BIOS or EFI firmware
The next several sections describe details of the VirtualBox guest platform.
5.2.1 Virtual CPUs
Unlike Oracle VM Server for SPARC (previously called Sun Logical Domains), VirtualBox does not directly assign CPU resources to the guest domain. Instead, virtual CPUs are presented to the guest and time-sliced on real CPUs using the host system's scheduling facilities. The number of CPUs allocated for each guest can be specified in the Processor tab of the guest machine's System settings, as shown in Figure 5.3.
Figure 5.3 Configuring Virtual Processors
If you try to specify more CPUs than are present on the system, the VirtualBox graphical interface will display a warning. The guest will run but the performance of the guest is likely to be significantly degraded.
The number of CPUs can also be specified using the VBoxManage modifyvm command. VBoxManage will not issue a warning if the number of CPUs exceeds the capacity of the host.
% VBoxManage showvminfo "Solaris 10" | grep CPU Number of CPUs: 1 CPUID overrides: None % VBoxManage modifyvm "Solaris 10" --cpus 8 % VBoxManage showvminfo "Solaris 10" | grep CPU Number of CPUs: 8 CPUID overrides: None
VirtualBox offers support for non-executable pages (NX). This feature enables guest operating systems to mark a page that is used for data so that it cannot be executed. This technique can help reduce the chance that a buffer overflow type of attack from a worm or virus against the guest will be successful. If the guest supports the NX feature, it is recommended that it be enabled in the CPU settings.
Although a guest does not require hardware virtualization assistance to perform well, if the host platform supports nested page tables, enabling this feature for a guest will provide a significant improvement in performance because most of the memory management functions can be carried out by the guest without requiring host intervention. Nested page tables can be enabled in the Acceleration tab of the system settings in the VirtualBox GUI.
Unlike Logical Domains, memory used by guests is under the control of the host platform. Although the guests can take advantage of hardware virtualization features such as nested page tables to reduce the overhead of memory management, it is still possible to request more memory for a guest than the host system has available. If a shortfall of memory occurs due to this type of oversubscription, the host operating system will start demand paging, which may drag down the performance of the guest machines and other applications and services running on the host. VirtualBox does not yet provide a memory ballooning feature that would enable the host to take pages back from a guest in the event of a memory shortfall. Figure 5.4 shows an example of a guest whose memory allocation exceeds the recommended maximum.
Figure 5.4 Setting Memory for an Oracle VM VirtualBox Guest
To help prevent overallocation of the host memory, the VirtualBox GUI will display a warning if it thinks that too much memory is being configured for a guest. In doing so, it considers only the total amount of memory on the system, not how much of that is actually free. It will display a warning if more than 50% of memory is allocated to a guest and a stronger warning if more than 80% is reserved for a guest.
If sufficient free memory is not available at the time, a guest machine may fail to start with an out-of-memory error, even if it will consume only a small amount of the memory allocated for its use.
Most guest systems run only a few applications or services. Because the host system performs most of the real operations on behalf of the guest, smaller memory allocations for the guest can still produce excellent results. Running a guest desktop with 512 MB or less may work well as long as enough memory is allocated for the guest system to boot.
5.2.3 Virtual Disk
Because a guest operating system needs persistent storage, VirtualBox can make several different types of host storage available to the guest in the form of virtual disks:
- A file that contains a disk image
- A real disk device
- An iSCSI target
- A CD-ROM/DVD or file containing an ISO image
- A file containing a floppy disk image
All of these storage options must be presented to the guest OS using a virtual disk. To facilitate this sharing, the VirtualBox virtual platform can have up to three disk controllers. Each of these controllers can have attached devices that provide access to the host storage.
Each virtual motherboard has a dual-channel IDE controller. Each of the two channels has two devices: a master and a slave. By convention, the master device on the first IDE channel is the boot disk and the master device on the second IDE channel is a CD-ROM/DVD. Many IDE chipsets are available, and VirtualBox can emulate an Intel PIIX3, PIIX4, or ICH6. There is no difference in the performance between these options, but if an operating system is expecting a particular IDE controller and sees a different one, it may not operate properly. This situation happens most often when importing a virtual machine from another virtualization product. To prevent this problem, set the IDE controller type to match that of the other virtualization product.
A virtual motherboard may also have a Serial ATA (SATA) controller. Such a controller can support up to 30 disk devices. By default, the first 4 devices operate in legacy IDE mode, meaning that the BIOS can use them just like any other IDE device. Once the guest operating system is up and running and has loaded the SATA drivers for these devices, they can then be accessed in SATA mode. In addition to supporting a larger number of devices, SATA is a more efficient interface both on the guest and in the emulation layer. SATA devices are preferred if the operating system supports them.
VirtualBox can also provide an LSI Logic or BusLogic SCSI controller, if necessary. Such a controller supports up to 16 devices. It is intended to facilitate use of legacy operating systems that do not support SATA and need more than the 4 devices provided by the IDE controller. This controller can also be used to attach more than the 30 disks supported by the SATA controller.
Guest hard disks are generally mapped to files on the host platform that contain a complete image of the guest disk, including the boot sector and partition table. The disk images have a fixed geometry based on their total size. Once the disk image is created, its size cannot be altered. When a guest reads from or writes to the disk, VirtualBox redirects the I/O to the native file system services on the host.
VirtualBox supports four disk image file formats.
- VDI, the native VirtualBox disk format. It is the default when you create a new virtual machine or disk image.
- VMDK, a popular disk format used by VMware.
- VHD, the format used by Microsoft.
- Parallels version 2 HDD format. VirtualBox does not support newer formats, but those can be converted to version 2 using tools supplied by Parallels.
With each of these formats, VirtualBox can create fixed-size or dynamically expanding disk images. Fixed-size image files are completely allocated at creation time. This type of image file will take longer to create, because it is dependent on the write performance of the host file system. Once in use, it will be more efficient, as the system does not need to get new blocks as the guest writes to new storage areas. In contrast, dynamically expanding disk images start off small and will grow as the guest writes to new blocks on the virtual disk. These are faster to create, but additional work is required by the host to find new blocks the first time a guest accesses a particular part of the disk. Host file system caching strategies can hide most of the difference in performance, especially on a host that is not heavily loaded. For performance-critical applications that perform many disk writes, fixed-size disk images are recommended. For all other uses, the convenience of dynamically allocated images makes this approach the preferred method.
VirtualBox maintains a library of disk, CD-ROM, and floppy disk images. Before a disk or CD-ROM image can be used by a guest, it must be registered in the Virtual Media Manager. This can be done in the VirtualBox GUI or via the VBoxManage openmedium command. Once an image is registered, it can be assigned to an open port on any guest. Although a disk image may be connected to more than one guest, it can be used by only one guest at a time. A guest will fail to start if one of its disk images is connected to another guest that is currently running.
Using the VBoxManage command line, the following example creates a 16 GB dynamically expanding disk image and attaches it to port 3 of the SATA controller in the guest named Windows 7.
% VBoxManage createhd --filename /vbox/HardDisks/Windows7-user.vdi \ --size 16000 --format VDI --variant Standard --remember 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Disk image created. UUID: 4a0ef971-13d1-428b-aded-5f8720155e0a % VBoxManage showhdinfo 4a0ef971-13d1-428b-aded-5f8720155e0a UUID: 4a0ef971-13d1-428b-aded-5f8720155e0a Accessible: yes Description: Logical size: 16000 MBytes Current size on disk: 0 MBytes Type: normal (base) Storage format: VDI Location: /vbox/HardDisks/Windows7-user.vdi % VBoxManage storageattach "Windows 7" --storagectl "SATA Controller" --port 3 --device 0 –type hdd \ --medium /vbox/HardDisks/Windows7-user.vdi
The results of this command can be seen in the Storage settings of this Windows 7 guest, as shown in Figure 5.5.
Figure 5.5 Selecting a Guest Disk Image
Note that the actual size of the disk image is only 63KB. To create a fixed-size image, add --variant Fixed to the createhd step in the preceding example.
CD-ROM images are treated in a similar fashion. The Virtual Media Manager maintains a list of registered images. Because CD-ROM images are not writable by the guest, they can be used by more than one guest at a time. One special image is VBoxGuestAdditions.iso, which can be found in the directory /opt/VirtualBox/additions. It contains all of the guest drivers and configuration tools that match the version of VirtualBox installed on the host. This image is automatically added by the installation program and is available to all guests.
In addition to a CD-ROM image, a guest can access real media in a CD-ROM or DVD drive on the host. By default, the guest is only allowed to read from the drive. To give the guest write access or to allow special I/O operations required by some multimedia players, enable the Passthrough setting on the CD-ROM device.
5.2.4 Virtual Network Devices
VirtualBox provides up to eight Ethernet PCI devices to each guest virtual machine. The user can select the type of virtual devices that are presented to the guest as well as what the host will do with the associated network I/O. The guest adapter does not need to be the same type as that on the host. For example, a Realtek Ethernet interface on the host can be virtualized as an Intel PRO/1000 on a guest. The first four virtual network adapters can be configured using the Network settings in the GUI. All eight of the devices can be configured using the VBoxManage command.
VirtualBox can present any of the following virtual devices to the guest operating system.
- AMD PCNet PCI II: A legacy host adapter for older guest operating systems.
- AMD PCNet FAST III: The default for most guests. This host adapter is well supported in most OS installation media, which makes it a good choice for most guests. It is also supported by the GNU GRUB bootloader, which allows network booting and installation of a guest operating system.
- Intel PRO/1000 MT Desktop: The default for newer guest operating systems such as Windows Vista and Windows Server 2008. Use this where the PCNet adapter is no longer supported or available on the installation media.
- Intel PRO/1000 T Server: Specifically for use with Windows XP guests.
- Intel PRO/1000 MT Server: A driver that allows guests to be imported from other virtualization products such as VMware. The PRO/1000 MT Server virtual device is commonly used on those platforms.
- Virt-io: A device used for guests that support a KVM paravirtualized (PV) network interface. Because this device is designed for virtualization, it may offer performance advantages over the other emulated devices. PV drivers are available in 2.6.25 or later Linux kernels. They can be downloaded for other operating systems at the KVM project page.
In addition to choosing the virtual device for the guest, the user must configure a host networking mode to use for each device. Five different modes are available, each of which offers some interesting benefits.
Not attached is a mode similar to a network adapter that doesn't have a network cable attached. The device is present in the guest machine but is not reporting a positive link status. Traffic will not flow through this device in this mode.
Network Address Translation (NAT) will hide the guest's interface behind a network tunnel. This mode is often used when the guest is a desktop system and primarily a consumer of network resources rather than a provider. To assist guests that automatically detect their network settings, VirtualBox provides a DHCP server, router, and DNS proxy to resolve network names and correctly route packets. NAT has a few limitations that may cause applications to behave differently than they would on a real system. For example, ping may not work across the NAT tunnel. Some VPN products use this method to determine if a network is reachable, so these products would not work with a virtual NIC in NAT mode. In addition, jumbo frames are not reliable when using NAT.
Because external systems cannot communicate directly with a guest using NAT mode, VirtualBox can provide port redirection using the host's IP address. External systems connect to the specified port on the host; VirtualBox then redirects all of the packets to the guest. There are a few restrictions on the use of port forwarding. For example, you cannot redirect a port that is already in use by the host. Ports with numbers less than 1024 require the requester to be running as root or with the net_privaddr privilege. Because neither of these is a recommended practice for otherwise unprivileged users, you should choose a port on the host with a number greater than 1024. The most common use of NAT mode is to forward guest port 22, which allows an external system to access the guest using SSH. The following example establishes an SSH port from the first network adapter (an Intel Pro/1000 MT Desktop) on the guest named Solaris 10 to port 2222 on the host:
% VBoxManage setextradata "Solaris 10" "VBoxInternal/Devices/e1000/0/LUN#0/Config/s10ssh/Protocol" TCP % VBoxManage setextradata "Solaris 10" "VBoxInternal/Devices/e1000/0/LUN#0/Config/s10ssh/GuestPort" 22 % VBoxManage setextradata "Solaris 10" "VBoxInternal/Devices/e1000/0/LUN#0/Config/s10ssh/HostPort" 2222
The guest can be accessed by using ssh -p 2222 user@host.
Bridged is a more advanced network mode. When working in this mode, VirtualBox installs a software network that allows the guest to share a specific host interface. A randomly generated MAC address is assigned to the guest adapter and its full network stack is visible to external systems. All of the network operations are available to the guest, including ping and jumbo frames. The bridged mode is the recommended setting for guests running server applications and desktops requiring a VPN connection into another network.
Internal mode is used to communicate between virtual machines on the same host. It is similar to bridged mode except that all communications stay internal to the host platform. Traffic over the internal mode software network is also invisible to the host. Internal mode is the fastest and most secure method of communication between guests. The most common use for this mode is to establish a private secure channel for guests to share that cannot be observed by any external system or other applications on the host system. Examples include an internal NFS server or a content provider for an externally facing web service.
Host only mode is similar to internal mode except that the host is able to communicate with the guests. All communications are internal to the host, but applications and users on the host can observe and use network services on the guests.
Basic network settings for the first four adapters, as shown in Figure 5.6, can be specified on the Network settings screen in the VirtualBox graphical interface.
Figure 5.6 Oracle VM VirtualBox Guest Network Configuration Settings
5.2.5 BIOS and EFI
VirtualBox provides a virtual standard BIOS firmware that is used by the guest virtual machine during the boot process. Through the user interface, the user can select options such as boot order and support for I/O APIC.
VirtualBox also provides an Extended Firmware Interface (EFI) for operating systems such as Mac OS X that use EFI instead of the legacy BIOS. Newer versions of Windows and some Linux distributions can use either the legacy BIOS or EFI. The type of firmware is selected in the Motherboard part of the System settings. Figure 5.7 shows the BIOS and boot order settings for a guest machine.
Figure 5.7 Selecting the Guest BIOS Type and Boot Order
You can also set the type of BIOS firmware by using the VBoxManage modifyvm command:
# VBoxManage modifyvm "Solaris 10" –-firmware bios
These are just the basic features of the VirtualBox guest platform. For a complete list of all configuration options, see the VirtualBox User Manual, which is available in PDF format in the installation directory /opt/VirtualBox/UserManual.pdf. This document can be found at http://www.virtualbox.org/wiki/Downloads.
5.2.6 Guest Additions
Although guest operating systems do not need any special software or drivers to operate correctly, the host platform includes many features that a guest can utilize if they are available. Specifically, VirtualBox provides a special set of drivers and utilities that can be used by the guest once the operating system has been installed. These "Guest Additions" are provided in a CD-ROM disk image that is always available to the guest.
You can use one of two methods to install the Guest Additions. The first method is to attach the disk image file VBoxGuestAdditions.iso to one of the available virtual CD-ROM devices. The second method is to use the VirtualBox graphical console and choose Devices Install Guest Additions from the guest console window. If the guest operating system does not automatically mount the media, this step can be done manually from the guest.
Once the virtual media has been mounted, run the appropriate installer for your guest platform. A reboot of the guest is required only if you are upgrading an older version of the guest additions that are already installed. For a new installation, all that is required is to log out of the guest and log back in again to use the Guest Additions.
Once installed, the Guest Additions provide several new features:
- Integrated keyboard and mouse. The guest no longer requires a captive keyboard and mouse. When the guest window receives focus, the keyboard and mouse are automatically attached. When the window loses focus, they are automatically released by the guest.
- Shared clipboard. This feature allows a user to copy an object from an application in one guest and paste it into another application on a totally different guest, or even on the host system.
- Resize guest display. This feature enables the user to resize the guest display. VirtualBox will notify the guest of the resolution changes, and the drivers inside the guest will handle the changes.
- Seamless mode. VirtualBox can hide the guest display background, only displaying application windows on the host. When used with the shared clipboard, this feature will hide the fact that applications are being run in virtual machines. Instead, all applications appear to be running together in a single environment—a uniquely integrated desktop experience.
- Time synchronization. This feature keeps the guest clock synchronized with that of the host, thereby avoiding the type of clock skewing that is common in virtualized environments.
- High-performance graphics. If this feature is enabled in the Display settings of the guest machine, VirtualBox will allow the guest operating system to pass OpenGL and Direct3D graphics commands directly to the host's graphics adapter. The guest can then perform 3D graphics operations at nearly the same speed as if they were running on the host. For Windows guests, 2D graphics acceleration is also available.
- Shared folders. Shared folders allow the guest to access the host file systems as if they were local file systems. For Windows guests, these appear as network shares. For all other guests, a special file system driver is used to access the shared folders.