1.9. Running Your Virtual Machine

To start a virtual machine, you have several options:

  • Double-click on the VM's entry in the list in the VirtualBox Manager window.

  • Select the VM's entry in the list in the VirtualBox Manager window, and click Start at the top of the window.

  • Go to the VirtualBox VMs folder in your system user's home directory. Find the subdirectory of the machine you want to start and double-click on the machine settings file. This file has a .vbox file extension.

Starting a virtual machine displays a new window, and the virtual machine which you selected will boot up. Everything which would normally be seen on the virtual system's monitor is shown in the window. See the screenshot image in Chapter 1, First Steps.

In general, you can use the virtual machine as you would use a real computer. There are couple of points worth mentioning however.

1.9.1. Starting a New VM for the First Time

When a VM is started for the first time, the First Start Wizard, is displayed. This wizard helps you to select an installation medium. Since the VM is created empty, it would otherwise behave just like a real computer with no OS installed. It will do nothing and display an error message that no bootable OS was found.

For this reason, the wizard helps you to select a medium to install an OS from.

  • If you have physical CD or DVD media from which you want to install your guest OS, such as a Windows installation CD or DVD, put the media into your host's CD or DVD drive.

    In the wizard's drop-down list of installation media, select Host Drive with the correct drive letter. In the case of a Linux host, choose a device file. This will allow your VM to access the media in your host drive, and you can proceed to install from there.

  • If you have downloaded installation media from the Internet in the form of an ISO image file such as with a Linux distribution, you would normally burn this file to an empty CD or DVD and proceed as described above. With Oracle VM VirtualBox however, you can skip this step and mount the ISO file directly. Oracle VM VirtualBox will then present this file as a CD or DVD-ROM drive to the virtual machine, much like it does with virtual hard disk images.

    In this case, the wizard's drop-down list contains a list of installation media that were previously used with Oracle VM VirtualBox.

    If your medium is not in the list, especially if you are using Oracle VM VirtualBox for the first time, click the small folder icon next to the drop-down list to display a standard file dialog. Here you can pick an image file on your host disks.

After completing the choices in the wizard, you will be able to install your OS.

1.9.2. Capturing and Releasing Keyboard and Mouse

Oracle VM VirtualBox provides a virtual USB tablet device to new virtual machines through which mouse events are communicated to the guest OS. If you are running a modern guest OS that can handle such devices, mouse support may work out of the box without the mouse being captured as described below. See Section 3.5.1, “Motherboard Tab”.

Otherwise, if the virtual machine only sees standard PS/2 mouse and keyboard devices, since the OS in the virtual machine does not know that it is not running on a real computer, it expects to have exclusive control over your keyboard and mouse. But unless you are running the VM in full screen mode, your VM needs to share keyboard and mouse with other applications and possibly other VMs on your host.

After installing a guest OS and before you install the Guest Additions, described later, either your VM or the rest of your computer can "own" the keyboard and the mouse. Both cannot own the keyboard and mouse at the same time. You will see a second mouse pointer which is always confined to the limits of the VM window. You activate the VM by clicking inside it.

To return ownership of keyboard and mouse to your host OS, Oracle VM VirtualBox reserves a special key on your keyboard: the Host key. By default, this is the right Ctrl key on your keyboard. On a Mac host, the default Host key is the left Command key. You can change this default in the Oracle VM VirtualBox Global Settings. See Section 1.16, “Global Settings”. The current setting for the Host key is always displayed at the bottom right of your VM window.

Figure 1.7 Host Key Setting on the Virtual Machine Task Bar

Host Key Setting on the Virtual Machine Task Bar

This means the following:

  • Your keyboard is owned by the VM if the VM window on your host desktop has the keyboard focus. If you have many windows open in your guest OS, the window that has the focus in your VM is used. This means that if you want to enter text within your VM, click on the title bar of your VM window first.

    To release keyboard ownership, press the Host key. As explained above, this is typically the right Ctrl key.

    Note that while the VM owns the keyboard, some key sequences, such as Alt-Tab, will no longer be seen by the host, but will go to the guest instead. After you press the Host key to reenable the host keyboard, all key presses will go through the host again, so that sequences such as Alt-Tab will no longer reach the guest. For technical reasons it may not be possible for the VM to get all keyboard input even when it does own the keyboard. Examples of this are the Ctrl-Alt-Del sequence on Windows hosts or single keys grabbed by other applications on X11 hosts like the GNOME desktop's "Control key highlights mouse pointer" functionality.

  • Your mouse is owned by the VM only after you have clicked in the VM window. The host mouse pointer will disappear, and your mouse will drive the guest's pointer instead of your normal mouse pointer.

    Note that mouse ownership is independent of that of the keyboard. Even after you have clicked on a titlebar to be able to enter text into the VM window, your mouse is not necessarily owned by the VM yet.

    To release ownership of your mouse by the VM, press the Host key.

As this behavior can be inconvenient, Oracle VM VirtualBox provides a set of tools and device drivers for guest systems called the Oracle VM VirtualBox Guest Additions which make VM keyboard and mouse operation a lot more seamless. Most importantly, the Additions will get rid of the second "guest" mouse pointer and make your host mouse pointer work directly in the guest. See Chapter 4, Guest Additions.

1.9.3. Typing Special Characters

OSes expect certain key combinations to initiate certain procedures. Some of these key combinations may be difficult to enter into a virtual machine, as there are three candidates as to who receives keyboard input: the host OS, Oracle VM VirtualBox, or the guest OS. Which of these three receives keypresses depends on a number of factors, including the key itself.

  • Host OSes reserve certain key combinations for themselves. For example, it is impossible to enter the Ctrl+Alt+Delete combination if you want to reboot the guest OS in your virtual machine, because this key combination is usually hard-wired into the host OS, both Windows and Linux intercept this, and pressing this key combination will therefore reboot your host.

    On Linux and Oracle Solaris hosts, which use the X Window System, the key combination Ctrl+Alt+Backspace normally resets the X server and restarts the entire graphical user interface. As the X server intercepts this combination, pressing it will usually restart your host graphical user interface and kill all running programs, including Oracle VM VirtualBox, in the process.

    On Linux hosts supporting virtual terminals, the key combination Ctrl+Alt+Fx, where Fx is one of the function keys from F1 to F12, normally enables you to switch between virtual terminals. As with Ctrl+Alt+Delete, these combinations are intercepted by the host OS and therefore always switch terminals on the host.

    If, instead, you want to send these key combinations to the guest OS in the virtual machine, you will need to use one of the following methods:

    • Use the items in the Input, Keyboard menu of the virtual machine window. This menu includes the settings Insert Ctrl+Alt+Delete and Ctrl+Alt+Backspace. The latter will only have an effect with Linux or Oracle Solaris guests, however.

      This menu also includes an option for inserting the Host key combination.

    • Use special key combinations with the Host key, normally the right Control key. Oracle VM VirtualBox will then translate these key combinations for the virtual machine:

      • Host key + Del to send Ctrl+Alt+Del to reboot the guest.

      • Host key + Backspace to send Ctrl+Alt+Backspace to restart the graphical user interface of a Linux or Oracle Solaris guest.

      • Host key + Function key. For example, to simulate Ctrl+Alt+Fx to switch between virtual terminals in a Linux guest.

  • For some other keyboard combinations such as Alt-Tab to switch between open windows, Oracle VM VirtualBox enables you to configure whether these combinations will affect the host or the guest, if a virtual machine currently has the focus. This is a global setting for all virtual machines and can be found under File, Preferences, Input.

1.9.4. Changing Removable Media

While a virtual machine is running, you can change removable media in the Devices menu of the VM's window. Here you can select in detail what Oracle VM VirtualBox presents to your VM as a CD, DVD, or floppy drive.

The settings are the same as those available for the VM in the Settings dialog of the Oracle VM VirtualBox main window. But as the Settings dialog is disabled while the VM is in the Running or Saved state, the Devices menu saves you from having to shut down and restart the VM every time you want to change media.

Using the Devices menu, you can attach the host drive to the guest or select a floppy or DVD image, as described in Section 3.7, “Storage Settings”.

The Devices menu also includes an option for creating a virtual ISO (VISO) from selected files on the host.

1.9.5. Resizing the Machine's Window

You can resize the virtual machine's window when it is running. In that case, one of the following things will happen:

  1. If you have scaled mode enabled, then the virtual machine's screen will be scaled to the size of the window. This can be useful if you have many machines running and want to have a look at one of them while it is running in the background. Alternatively, it might be useful to enlarge a window if the VM's output screen is very small, for example because you are running an old OS in it.

    To enable scaled mode, press Host key + C, or select Scaled Mode from the View menu in the VM window. To leave scaled mode, press Host key + C again.

    The aspect ratio of the guest screen is preserved when resizing the window. To ignore the aspect ratio, press Shift during the resize operation.

    See Known Limitations for additional remarks.

  2. If you have the Guest Additions installed and they support automatic resizing, the Guest Additions will automatically adjust the screen resolution of the guest OS. For example, if you are running a Windows guest with a resolution of 1024x768 pixels and you then resize the VM window to make it 100 pixels wider, the Guest Additions will change the Windows display resolution to 1124x768.

    See Chapter 4, Guest Additions.

  3. Otherwise, if the window is bigger than the VM's screen, the screen will be centered. If it is smaller, then scroll bars will be added to the machine window.

1.9.6. Saving the State of the Machine

When you click on the Close button of your virtual machine window, at the top right of the window, just like you would close any other window on your system, Oracle VM VirtualBox asks you whether you want to save or power off the VM. As a shortcut, you can also press Host key + Q.

Figure 1.8 Closing Down a Virtual Machine

Closing Down a Virtual Machine

The difference between the three options is crucial. They mean the following:

  • Save the machine state: With this option, Oracle VM VirtualBox freezes the virtual machine by completely saving its state to your local disk.

    When you start the VM again later, you will find that the VM continues exactly where it was left off. All your programs will still be open, and your computer resumes operation. Saving the state of a virtual machine is thus in some ways similar to suspending a laptop computer by closing its lid.

  • Send the shutdown signal. This will send an ACPI shutdown signal to the virtual machine, which has the same effect as if you had pressed the power button on a real computer. So long as the VM is running a fairly modern OS, this should trigger a proper shutdown mechanism from within the VM.

  • Power off the machine: With this option, Oracle VM VirtualBox also stops running the virtual machine, but without saving its state.

    Warning

    This is equivalent to pulling the power plug on a real computer without shutting it down properly. If you start the machine again after powering it off, your OS will have to reboot completely and may begin a lengthy check of its virtual system disks. As a result, this should not normally be done, since it can potentially cause data loss or an inconsistent state of the guest system on disk.

    As an exception, if your virtual machine has any snapshots, see Section 1.11, “Snapshots”, you can use this option to quickly restore the current snapshot of the virtual machine. In that case, powering off the machine will not disrupt its state, but any changes made since that snapshot was taken will be lost.

The Discard button in the VirtualBox Manager window discards a virtual machine's saved state. This has the same effect as powering it off, and the same warnings apply.