- 5.1 How Oracle VM VirtualBox Works
- 5.2 Oracle VM VirtualBox Guest Platform
- 5.3 Oracle Solaris as an Oracle VM VirtualBox Host
- 5.4 Oracle Solaris as an Oracle VM VirtualBox Guest
- 5.5 Creating and Managing Oracle VM VirtualBox Guests
- 5.6 Summary
5.5 Creating and Managing Oracle VM VirtualBox Guests
After you have installed VirtualBox, you can create guests. While this can be accomplished using command-line tools, the first example given here uses the VirtualBox GUI installation wizard.
5.5.1 Creating the Guest Machine
You can start to install a guest machine by launching the VirtualBox tool:
% VirtualBox &
Figure 5.9 shows the initial VirtualBox screen.
Figure 5.9 VirtualBox Main Window
To begin creating the first virtual machine, click the New button. This will launch the New Virtual Machine Wizard.
The first step is to name the new virtual machine and choose the operating system of the guest. The name of the guest is unrelated to its actual host name or network identity; those identities will be set later, once the guest is running. The guest name is only used by VirtualBox to identify the guest being managed. The operating system type determines how VirtualBox will emulate devices and which code scanning techniques to use when running the guest kernel code. The name of the guest can be changed later, but the OS type should be correct before creating the guest.
For this example, the guest will be named Windows XP and will run the Windows XP operating system, as shown in Figure 5.10.
Figure 5.10 Choosing the Guest Operating System Type
The next step is to assign the amount of memory to be allocated for the guest. The amount needed is usually less than needed for a physical system. Many operating systems manage a file cache to improve performance of disk reads. If the host OS has a file cache, the guests will not need much of a file cache to maintain reasonable performance, so you can allocate less memory to guests. The installation wizard will suggest a minimum memory size based on the operating system type chosen in the previous step. Figure 5.11 shows the allocation of 512 MB for the Windows XP guest—more than enough for typical virtual desktop needs.
Figure 5.11 Setting the Amount of Guest Memory
Every guest needs a boot disk. For simplicity, the New Virtual Machine Wizard allows you to create only a single boot disk image. It will always assign this disk as the master device on the first IDE controller. If you need a different configuration, use the VBoxManage command. At this point in the guest installation, you can choose whether to create a new disk image or use one that is already registered in the Virtual Media Manager. There aren't any virtual disks on this system yet, so select Create new hard disk as shown in Figure 5.12. Note that VirtualBox suggests a size for the disk based on the operating system that was chosen in the previous step.
Figure 5.12 Virtual Hard Disk Wizard
This disk must either be a fixed size or dynamically expanding disk image. A dynamically expanding disk is typically used, as shown in Figure 5.13, because it doesn't waste real disk space.
Figure 5.13 Choosing the Disk Image Type
The next screen allows you to name the disk image and specify its size. By default, this disk image is stored in your home directory in a hidden directory named .VirtualBox. If not enough space is available there, you can click the icon to the right of the image name and tell VirtualBox where to place the image. You will need read and write access to the directory holding the disk images.
In this example, the disk image is named Windows 7.vdi and has a size of 10 GB, which is the default. In practice, the name of the disk image should indicate not only which virtual machine is using it, but also how that disk is used. Figure 5.14 shows the name and size of the guest boot disk.
Figure 5.14 Choosing the Name and Size of the Guest Disk Image (top)
Figure 5.15 shows the final disk configuration. After reviewing the settings, click Finish. At this point, the disk image will be created and registered in the Virtual Media Manager.
Figure 5.15 Reviewing the Guest Disk Settings (center)
The final step in the installation wizard is to review the final guest configuration, as shown in Figure 5.16. Verify that the settings are what you desired and click Finish to create the guest.
Figure 5.16 Final Review of the Guest Configuration (bottom)
You have successfully created your first guest machine. You can click the Settings button and familiarize yourself with some of the other configuration options, such as audio, video memory size, additional networks, processor accelerations, and shared folders.
5.5.2 Installing the Guest Operating System
Once you are satisfied that the guest machine configuration is suitable for your needs, you can install the operating system on the guest boot disk. The most common method of doing so is to attach a CD-ROM disk image to one of the available virtual CD-ROM devices so that the guest will boot from that device. To attach the CD-ROM image, select the guest machine and click Settings. Then select Storage and a window similar to Figure 5.17 will be displayed.
Figure 5.17 Guest Storage Configuration Before Attaching the Installation Media
When you click the CD-ROM device, you will see that it is the master device on the secondary IDE channel. This device also happens to be second device in the BIOS boot order, right behind the floppy disk, which is rarely used. Also note that the device is currently empty, meaning that no virtual or real media has been inserted.
To attach the installation media, you must first register it with the Virtual Media Manager. In this example, the media is found in the file /export/iso/windows/winxp_sp3_x86.iso. Click the folder icon to the right of the CD/DVD Device pull-down menu, which will launch the Virtual Media Manager, as shown in Figure 5.18.
Figure 5.18 Virtual Media Manager
Because this is the first guest in a new VirtualBox installation, the only CD-ROM disk image present is VBoxGuestAdditions.iso, which contains the Guest Additions. To add the Windows installation media, click the Add button, navigate to the directory where the CD-ROM image is stored, and select it, as shown in Figure 5.19. Then you can highlight the appropriate disk image and click the Select button to insert it into the virtual CD-ROM device. Once registered, you can select this media in any guest from the CD/DVD Device pull-down menu on the guest Storage settings without having to start the Virtual Media Manager.
Figure 5.19 Virtual Media Manager After Adding the Windows Installation Media
After the CD-ROM disk image is registered with the Virtual Media Manager, it should be available as a CD-ROM device selection on the guest storage settings, as shown in Figure 5.20. Alternatively, if you start the guest with a new boot disk and fail to assign a CD-ROM, VirtualBox will launch the Virtual Media Manager so that you can select an existing image or register a new one. When this process is complete, the image will automatically be attached to the CD-ROM device and the guest will continue the booting process.
Figure 5.20 Selecting the Installation Media for the Guest
All that is left to do is start the guest machine. However, first we will show the creation of a guest using the VBoxManage command line.
5.5.3 Creating a Guest Machine Using the Command Line
The command-line interface (CLI) for VirtualBox is more complicated to use than the GUI, but it offers several advantages:
- The CLI is more flexible than the GUI.
- The CLI offers features not available from the GUI.
- The CLI can be used to script guest creation.
- Scripts using the CLI can be used to build an automated guest creation system.
As in the previous example, the first step is to create and register the guest virtual machine. If you don't know which OS type to select when creating your virtual machine, giving the command VBoxManage list ostypes will produce a list of supported options. For this example, WindowsXP_64 is the correct choice.
% VBoxManage createvm --name "Windows XP" \ --ostype WindowsXP_64 --register Virtual machine 'Windows XP' is created and registered. UUID: 4ec5efdc-fa76-49bb-8562-7c2a0bac8282 Settings file: '/vbox/Machines/Windows XP/Windows XP.xml' % VBoxManage showvminfo "Windows XP" Name: Windows XP Guest OS: Windows XP (64 bit) UUID: 4ec5efdc-fa76-49bb-8562-7c2a0bac8282 Config file: /vbox/Machines/Windows XP/Windows XP.xml Hardware UUID: 4ec5efdc-fa76-49bb-8562-7c2a0bac8282 Memory size: 128MB VRAM size: 8MB Number of CPUs: 1 Synthetic Cpu: off CPUID overrides: None Boot menu mode: message and menu Boot Device (1): Floppy Boot Device (2): DVD Boot Device (3): HardDisk Boot Device (4): Not Assigned ACPI: on IOAPIC: on PAE: on Time offset: 0 ms Hardw. virt.ext: on Hardw. virt.ext exclusive: on Nested Paging: on VT-x VPID: on State: powered off (since 2010-02-14T23:05:30.798000000) Monitor count: 1 3D Acceleration: off Teleporter Enabled: off Teleporter Port: 0 Teleporter Address: <NULL> Teleporter Password: <NULL> NIC 1: MAC: 0800270213D4, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: 82540EM, Reported speed: 0 Mbps NIC 2: disabled NIC 3: disabled NIC 4: disabled NIC 5: disabled NIC 6: disabled NIC 7: disabled NIC 8: disabled UART 1: disabled UART 2: disabled Audio: disabled Clipboard Mode: Bidirectional VRDP: disabled USB: disabled USB Device Filters: <none> Shared folders: <none> Guest: Statistics update: disabled
This guest should need about 512 MB of memory, and you may want to use the audio device. Also, 8 MB is not enough video RAM, and 3D acceleration is supported with the Guest Additions.
% VBoxManage modifyvm "Windows XP" --memory 512 --vram 32 \ --accelerate3d on --audio oss
Storage configuration requires a few commands to complete. First you must create the IDE controller and the boot disk image, and attach them together. Then you must register and attach the CD-ROM image of the boot media. Finally, the BIOS boot order must be set to boot from CD-ROM before the disk. Note that because the image file name is specified as a relative path name, it is relative to the VirtualBox settings, not your current working directory.
% VBoxManage storagectl "Windows XP" --name "IDE Controller" \ --add ide --controller ICH6 % VBoxManage createhd --filename "Windows XP.vdi" --size 10240 \ --format VDI --remember 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Disk image created. UUID: 388311ed-b303-4405-8689-3dee5abc8f68 % VBoxManage storageattach "Windows XP" \ --storagectl "IDE Controller" --port 0 --device 0 \ --type hdd --medium "Windows XP.vdi" % VBoxManage openmedium dvd /export/iso/windows/winxp_sp3_x86.iso % VBoxManage storageattach "Windows XP" \ --storagectl "IDE Controller" --port 1 --device 0 \ --medium "/export/iso/windows/winxp_sp3_x86.iso" \ --type dvddrive % VBoxManage modifyvm "Windows XP" --boot1 dvd --boot2 disk
At this point, the virtual machine is configured and ready to boot.
5.5.4 Starting a Virtual Machine
Oracle VM VirtualBox provides three different methods for starting a virtual machine. The most common method is from inside the VirtualBox graphical tool itself. Select the guest and click the Start button. When the guest machine starts, a fully featured console window is opened on the host. Until the Guest Additions are installed, keyboard and mouse operations are captive. In other words, once you click inside the guest window, it will restrict your cursor to its window and will continue to receive all keyboard input until told to release the focus, usually achieved by clicking the Host key. The current Host key is displayed at the lower-right corner of the guest console window. Once the Guest Additions are installed, however, the keyboard and mouse will be seamlessly attached and detached as your mouse moves over the window.
Using this method, the user on the host can control many of the operations of the guest, such as changing the size of the window, attaching CD-ROM media, or turning seamless mode on or off.
If a less complicated console is desired, a simple window with no menu decorations can be used to start a guest. Give the command /usr/bin/VBoxSDL to start the guest. Instead of a fully featured window, a simple window is displayed. This approach is primarily used for debugging purposes but can be used if a simple console is required.
A more interesting start method is a headless system. In this case, the guest machine is started by the /usr/bin/VBoxHeadless command. This command starts the guest machine but does not display the console on the host system. Instead, the built-in Virtual Remote Desktop Protocol (VRDP) server starts. A remote system can then access the guest console using any RDP client program. For Oracle Solaris, one such program is rdesktop, which can be found on the Solaris Companion Software CD.
The following example demonstrates starting a guest machine in headless mode on a host system. This is just the type of operation that the Solaris Service Manage Facility (SMF) could easily automate.
% VBoxHeadless --startvm "Windows XP" Sun VirtualBox Headless Interface 3.1.4 (C) 2008-2010 Sun Microsystems, Inc. All rights reserved. Listening on port 3389.
To connect to this guest from a remote system, we will use an RDP client. This example shows the use of rdesktop on an Oracle Solaris system to connect to the newly created Windows XP guest machine, which is running on a host named pandora.
% rdesktop pandora:3389
On the remote system, a new window is opened showing the guest desktop that is running on pandora. Figure 5.21 shows the guest desktop running the Windows XP installation program.
Figure 5.21 Displaying the Remote Desktop
5.5.5 Stopping a Virtual Machine
A guest is typically shut down by using its native method. Nevertheless, other options for stopping a virtual machine are available. Regardless of the method used to create the guest, it can be stopped from the host either through the command line or via the VirtualBox GUI. Both of these methods provide several mechanisms that can stop a guest.
- An ACPI shutdown signal. This is the recommended method. A shutdown signal is sent to the guest and, if that signal is supported, the guest will begin a normal shutdown. This process includes tasks such as flushing disk caches and unmounting file systems. An ACPI signal is the safest of the external shutdown methods.
- Snapshot. The guest machine's current state will be saved and can be restarted from this point in the future. The snapshot approach is similar to a hibernation feature found on modern laptops, but you can save many snapshots and roll them back as desired. This flexibility enables you to test the effects of various operations, starting with a consistent state each time.
- Reset. This "hard stop" will cause a machine reset; it is recommended only when the ACPI shutdown does not work. In this case, the guest disk buffers are not flushed, and some of the uncommitted disk data may be corrupted. Most modern operating systems feature some form of recovery in the event of a power loss, so the chances of corruption are small, but this approach is recommended only when no other method works.
- Pause. This option causes a virtual machine to stop execution. The guest remains in memory, however, and its operation can be resumed. The state is not saved by a pause operation.
Here is an example of a safe external host-initiated shutdown for the guest named Windows XP:
% VBoxManage controlvm "Windows XP" acpipowerbutton
This command sends an ACPI shutdown signal to the guest, which will start an orderly shutdown process.
5.5.6 Cloning a Virtual Machine
Although VirtualBox does not currently feature complete cloning of a virtual machine, it does provide a host-agnostic method of cloning disk images. This is done via the VBoxManage clonehd command. The source disk image is copied in its entirety and a new UUID is assigned. The disk can be registered in the user's Media Manager or copied to another system to be used elsewhere. All that is required to complete the cloning of the virtual machine is to create the new guest configuration, using either the command line or the GUI as shown before.
If the host system is running Oracle Solaris, ZFS data set cloning can be used instead of cloning the virtual disk device with VBoxManage. The result is much faster cloning time. Because ZFS needs to allocate space only for the additional blocks that are changed in the clone, this approach also results in a smaller total storage requirement for the new guest.
To use ZFS cloning, two steps must be completed. The first step is the creation of the ZFS clone, which requires two commands. Because ZFS cloning occurs on a data set level, you should place the guest disk images in separate ZFS file systems. If a guest machine has several disks and they will always be used together, place them all in the same ZFS file system so that one ZFS operation can manage all of them.
The second step is the creation of a new UUID for the cloned virtual disk. Without this step, the cloned disk image would have the same UUID as a disk that is already registered. VirtualBox provides a method of creating a new UUID that must be used after completing the ZFS cloning operation.
The following example compares the time and space required to clone a disk image. The source is a 5 GB Solaris 10 boot disk. To simplify management of virtual disk devices, the source disk image is placed in a ZFS file system named pandora/HardDisks/s10guest1, which is mounted on the host as /vbox/HardDisks/s10guest1.
We first clone the disk image into the directory /vbox/HardDisks/s10guest2-trad using the VirtualBox clonehd method. For a consistent comparison of used space, the target directory is also a ZFS file system.
# time VBoxManage clonehd \ "/vbox/HardDisks/s10guest1/Solaris 10 boot disk.vdi" \ "/vbox/HardDisks/s10guest2-trad/Solaris 10 boot disk.vdi" \ --remember 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100% Clone hard disk created in format 'VDI'. UUID: 19fb45a2-3773-4580-9e85-bb54af784d9a real 9m40.680s user 0m2.233s sys 0m2.352s
Now we can clone the disk image using ZFS. The specific steps to do so are shown below. To record the total time of this operation, these commands were run from a script. The resulting time is indicated after the commands.
# zfs snapshot pandora/vbox/HardDisks/s10guest1@s10guest2-zfs # zfs clone pandora/vbox/HardDisks/s10guest1@s10guest2-zfs \ pandora/vbox/HardDisks/s10guest2-zfs # VBoxManage internalcommands sethduuid \ "/vbox/HardDisks/s10guest2-zfs/Solaris 10 boot disk.vdi" UUID changed to: f06b5f4e-805e-4e74-8345-de9a22e39e81 # VBoxManage openmedium disk \ "/vbox/HardDisks/s10guest2-zfs/Solaris 10 boot disk.vdi" real 0m1.288s user 0m0.087s sys 0m0.132s
Using VBoxManage, virtual disk cloning took nearly 10 minutes, and the ZFS method just slightly more than 1 second. Although all directories indicate that they are 5 GB in size, the ZFS space listing shows how much space is actually consumed.
# du -h /vbox/HardDisks 5.0G /vbox/HardDisks/s10guest2-zfs 5.0G /vbox/HardDisks/s10guest1 5.0G /vbox/HardDisks/s10guest2-trad 15 G /vbox/HardDisks # zfs list -r -o space pandora/vbox/HardDisks NAME AVAIL USED USEDSNAP pandora/vbox/HardDisks 57.0G 10.0G 0 pandora/vbox/HardDisks/s10guest1 57.0G 5.00G 0 pandora/vbox/HardDisks/s10guest2-trad 57.0G 4.99G 0 pandora/vbox/HardDisks/s10guest2-zfs 57.0G 164K 0
The traditional method of using the VirtualBox copy method consumed an additional 5 GB of disk space, which was expected. However, the ZFS clone consumed only 164KB of space. Of course, as the cloned guest machine starts writing to the disk, additional space will be required for storage of its data. For the parts of the disk that are not written, only one copy of the data will be kept across all of the cloned images, which represents a significant storage savings opportunity achieved by using ZFS for guest disk images.
5.5.7 Live Migration of a Guest
Beginning with version 3.1, VirtualBox includes a feature called teleportation that allows a guest machine to move from one host to another while the guest machine is running. Except for some rare cases, the source and destination hosts need not run the same operating system or even the same type of hardware. In other words, you can migrate a guest running on an Oracle Solaris host to a Linux or Windows host.
The following steps are required to migrate a guest machine:
- Ensure there is a TCP/IP network connection between the source and target hosts. The migration will occur over a TCP connection.
- Configure the original guest to use some sort of shared storage (NFS, SMB, CIFS, or iSCSI) for all of its disk, CD-ROM, and floppy images.
- On the target system, create a guest configuration that exactly matches the hardware settings (e.g., processor, memory, network) of the guest that is currently running on the source host.
- On the target host, the guest machine must start listening for a teleportation connection request instead of actually starting. The VBoxManage modifyvm --teleporter command will perform this task.
- Start the guest machine on the target host. Instead of starting, it will display a progress bar while waiting for the teleportation request from the source.
- Initiate the live migration by issuing a VBoxManage controlvm teleport command on the source host system.
In this example, a guest machine named Solaris10 migrates from a host named source to one named target. The Solaris10 guest configurations on both hosts meet the guidelines listed above. On the target, place Solaris10 in teleportation mode and start it. Because it is not currently in use, port 6000 will be used for the teleportation connection.
target% VBoxManage modifyvm Solaris 10 –-teleporter on \ –-teleporter 6000 target% VBoxManage startvm Solaris10
On the host source where the guest Solaris10 is currently running, initiate the live migration with the following command:
source% VBoxManage controlvm Solaris10 teleport --host source \ --port 6000
The state of the guest Solaris10 will be transferred to the host target and the guest will resume execution on the new host. For more information on guest teleportation, see the VirtualBox User Manual.