Chapter 9. Configuring Virtual Machines

Contents

9.1. Enabling Seamless and Synchronized Cursor Movement
9.2. Adding a CD/DVD-ROM Device with Virtual Machine Manager
9.3. Adding a Floppy Device with Virtual Machine Manager
9.4. Ejecting and Changing Floppy or CD/DVD-ROM Media with Virtual Machine Manager
9.5. Adding a PCI Device with Virtual Machine Manager
9.6. Adding a PCI Device with virsh
9.7. Clock Settings

Abstract

Virtual Machine Manager's Details view offers in-depth information about the VM Guest's complete configuration and hardware equipment. Using this view, you can also change the guest configuration or add and modify virtual hardware. To access this view, open the guests console in Virtual Machine Manager and either choose View+Details from the menu, or click on the blue information icon in the toolbar.

Figure 9.1. Details View of a VM Guest

Details View of a VM Guest

9.1. Enabling Seamless and Synchronized Cursor Movement

When you click within a VM Guest's console with the mouse, the cursor is captured by the console window and cannot be used outside the console unless it is explicitly released (by pressing Alt+Ctrl ). To prevent the console from grabbing the key and to enable seamless cursor movement between host and guest instead, add a tablet to the VM Guest.

Adding a tablet has the additional advantage of synchronizing the cursor movement between VM Host Server and VM Guest when using a graphical environment on the guest. With no tablet configured on the guest, you will often see two cursor symbols with one dragging behind the other.

  1. Double-click a VM Guest entry in the Virtual Machine Manager to open its console and switch to the Details view with View+Details.

  2. Click Add Hardware and choose Input and then EvTouch USB Graphics Tablet in the pop-up window. Proceed with Finish.

  3. In case you tried to add the tablet while the guest was still running, you will be asked whether to enable the tablet after the next reboot. Confirm with Yes.

  4. Once you (re)start the VM Guest the tablet is available in the VM Guest.

9.2. Adding a CD/DVD-ROM Device with Virtual Machine Manager

KVM supports CD or DVD-ROMs in VM Guest either by directly accessing a physical drive on the VM Host Server or by accessing ISO images. To create an ISO image from an existing CD or DVD, use dd:

dd if=/dev/cd_dvd_device of=my_distro.iso bs=2048

To add a CD/DVD-ROM device to your VM Guest proceed as follows:

  1. Double-click a VM Guest entry in the Virtual Machine Manager to open its console and switch to the Details view with View+Details.

  2. Click Add Hardware and choose Storage in the pop-up window. Proceed with Forward.

  3. Change the Device Type to IDE CDROM.

  4. Select Select Managed or Other Existing Storage.

    1. To assign the device to a physical medium, enter the path to the VM Host Server's CD/DVD-ROM device (for example, /dev/cdrom) next to the Browse button. Alternatively you may use the Browse button to open a file browser and then click Browse Local to select the device. Assigning the device to a physical medium is only possible, when the Virtual Machine Manager was started on the VM Host Server.

    2. To assign the device to an existing image, click Browse to choose an image from a storage pool. If the Virtual Machine Manager was started on the VM Host Server, you may alternatively choose an image from another location on the file system by clicking Browse Local. Select an image and close the file browser with Choose Volume.

  5. Proceed with Forward to review the settings. Apply them with Finish, Yes, and Apply.

  6. Reboot the VM Guest to make the new device available. For further information also see Section 9.4, “Ejecting and Changing Floppy or CD/DVD-ROM Media with Virtual Machine Manager”.

9.3. Adding a Floppy Device with Virtual Machine Manager

Currently KVM only supports the use of floppy disk images—using a physical floppy drive is not supported. Create a floppy disk image from an existing floppy using dd:

dd if=/dev/fd0 of=/var/lib/libvirt/images/floppy.img

To create an empty floppy disk image use one of the following commands:

# raw image
dd if=/dev/zero of=/var/lib/libvirt/images/floppy.img bs=512 count=2880

# FAT formatted image
mkfs.msdos -C /var/lib/libvirt/images/floppy.img 1440

To add a floppy device to your VM Guest proceed as follows:

  1. Double-click a VM Guest entry in the Virtual Machine Manager to open its console and switch to the Details view with View+Details.

  2. Click Add Hardware and choose Storage in the pop-up window. Proceed with Forward.

  3. Change the Device Type to Floppy Disk.

  4. Choose Select Managed or Other Existing Storage and click Browse to choose an existing image from a storage pool. If Virtual Machine Manager was started on the VM Host Server, you may alternatively choose an image from another location on the file system by clicking Browse Local. Select an image and close the file browser with Choose Volume.

  5. Proceed with Forward to review the settings. Apply them with Finish, Yes, and Apply.

  6. Reboot the VM Guest to make the new device available. For further information also see Section 9.4, “Ejecting and Changing Floppy or CD/DVD-ROM Media with Virtual Machine Manager”.

9.4. Ejecting and Changing Floppy or CD/DVD-ROM Media with Virtual Machine Manager

Regardless whether you are using the VM Host Server's physical CD/DVD-ROM device or an ISO/Floppy image: before you can change the media or image of an existing device in the VM Guest, you first need to disconnect the media from the guest.

  1. Double-click a VM Guest entry in the Virtual Machine Manager to open its console and switch to the Details view with View+Details.

  2. Choose the Floppy or CD/DVD-ROM device and eject the media by clicking Disconnect.

  3. To insert a new media, click Connect.

    1. If using the VM Host Server's physical CD/DVD-ROM device, first change the media in the device (this may require to unmount it on the VM Host Server before it can be ejected). Then choose CD-ROM or DVD and select the device from the drop-down list.

    2. If using an ISO image, choose ISO image Location and select an image by clicking Browse. When connecting from a remote host, you may only choose images from existing storage pools.

  4. Click OK to finish. The new media can now be accessed in the VM Guest.

9.5. Adding a PCI Device with Virtual Machine Manager

You can add PCI devices to guests using the graphical virt-manager tool. Once the PCI device is assigned to one VM Guest, it cannot be used by another one unless re-assigned. The following procedure adds a USB controller to a virtualized guest.

  1. Double-click a VM Guest entry in the Virtual Machine Manager to open its console and switch to the Details view with View+Details.

  2. Click Add Hardware and choose the PCI Host Device category in the left pane. A list of host PCI devices appears in the right part of the window.

  3. From the list of available PCI devices, choose the USB controller to assign to the VM Guest. It may read for example USB2 Enhanced Host Controller. Confirm with Finish.

    [Tip]

    You cannot assign a PCI device live to a running VM Guest. If you are trying to add a PCI device to a running machine, the Virtual Machine Manager will ask if you want to assign the PCI device after the next VM Guest shutdown. Confirm with Yes, and after you reboot the VM Guest, the device assignment will be finished.

9.6. Adding a PCI Device with virsh

To dedicate and assign a PCI device to VM Guest with virsh, follow these steps:

  1. Identify the PCI device.

    Use the virsh nodedev-list or lspci -n commands to identify the PCI device designated for pass-through to VM Guest.

    The following command lists available PCI devices only:

    virsh nodedev-list | grep pci

    Note that PCI devices are identified by a string in the following format (8086 is a variable that represents Intel architecture, and **** stands for a four digit hexadecimal code specific to each device):

    pci_8086_****

    Remember the PCI device number, you will need it in future steps.

  2. Gather the information about the domain, bus, and function:

    # virsh nodedev-dumpxml pci_8086_1d26
    <device>
      <name>pci_8086_1d26</name>
      <parent>computer</parent>
      <driver>
        <name>ehci_hcd</name>
      </driver>
      <capability type='pci'>
        <domain>0</domain>
        <bus>0</bus>
        <slot>29</slot>
        <function>0</function>
        <product id='0x1d26'>Patsburg USB2 Enhanced Host Controller #1</product>
        <vendor id='0x8086'>Intel Corporation</vendor>
        <capability type='virt_functions'>
        </capability>
      </capability>
    </device>
  3. Detach the device from the host system prior to attaching it to VM Guest.

    # virsh nodedev-detach pci_8086_1d26 
      Device pci_8086_1d26 detached
  4. Convert the bus, slot, and function value from decimal to hexadecimal, and prepend '0x' to tell the system that the value is hexadecimal. In our example, bus = 0, slot = 29, and function = 0. Their hexadecimal values are:

    # printf %x 0
    0
    # printf %x 29
    1d

    Bus and function hexadecimal numbers are '0x00', while slot number is '0x1d'.

  5. Run virsh edit on your domain, and add the following device entry in the <devices> section.

    <hostdev mode='subsystem' type='pci' managed='no'>
      <source>
        <address domain='0x0000' bus='0x00' slot='0x1d' function='0x00'/>
      </source>
    </hostdev>
    [Tip]'managed' vs. 'unmanaged'

    libvirt recognizes two modes to handle PCI devices: they can be either 'managed' or 'unmanaged'. In the managed case, libvirt will handle all the details of unbinding the device from the existing driver if needed, resetting the device, binding it to pci-stub before starting the domain, etc. When the domain is terminated or the device is removed from the domain, libvirt will unbind from pci-stub and rebind to the original driver in the case of a managed device. If the device is unmanaged, the user must take care to ensure all of these management aspects of the device are done before assigning it to a domain, and after the device is no longer used by the domain.

    In our example, the managed='no' option means that the device is 'unmanaged', and we need to take care of the related driver with the virsh nodedev-detach and virsh nodedev-attach commands. To switch the device mode to 'managed', replace the snippet with managed='yes', and skip the remaining steps (apart from starting the guest).

  6. Once the VM Guest system is ready to use the PCI device, tell the host to stop using it. First check what driver the host system is using for the PCI device.

    # readlink /sys/bus/pci/devices/0000\:00\:1d.0/driver
    ../../../bus/pci/drivers/pci-stub
  7. In our case, the pci-stub driver is loaded, so you can start the virtual machine. It will be able to use the PCI device automatically.

    # virsh start sles11
    [Tip]

    When using a multi-function PCI device that does not support FLR (function level reset) or PM (power management) reset, you need to detach all its functions from the VM Host Server. The device must be reset for security reasons, and without FLR or PM reset, you must reset the whole device. libvirt will refuse to do this if a function of the device is still in use by the VM Host Server or another VM Guest.

    You can safely detach a device function from the VM Guest with the virsh nodedev-detach command.

    [Tip]

    If your PCI device is not 'managed', and the driver controlling the PCI device is not pci-stub, you have to detach it from the device first:

    virsh nodedev-detach pci_8086_1d26
    [Tip]

    If you are running SE-Linux on your host, you need to disable it for now with

    # setsebool -P virt_use_sysfs 1

    and then start the virtual machine.

9.7. Clock Settings

Keeping the correct time in a VM Guest is one of the more difficult aspects of virtualization. Keeping the correct time is especially important for network applications and is also a prerequisite to do a live migration of a VM Guest.

[Tip]Time Keeping on the VM Host Server

It is strongly recommended to ensure the VM Host Server keeps the correct time as well, for example, by utilizing NTP (see Chapter 23, Time Synchronization with NTP (↑Administration Guide) for more information).

9.7.1. Using kvm_clock

KVM provides a paravirtualized clock which is currently supported by SUSE Linux Enterprise Server 10 SP3 and newer and RedHat Enterprise Linux 5.4 and newer via the kvm_clock driver. It is strongly recommended to use kvm_clock when available.

Use the following command inside a VM Guest running Linux to check whether the driver kvm_clock has been loaded:

~ # dmesg | grep kvm-clock
[    0.000000] kvm-clock: cpu 0, msr 0:7d3a81, boot clock
[    0.000000] kvm-clock: cpu 0, msr 0:1206a81, primary cpu clock
[    0.012000] kvm-clock: cpu 1, msr 0:1306a81, secondary cpu clock
[    0.160082] Switching to clocksource kvm-clock

To check which clock source is currently used, run the following command in the VM Guest. It should output kvm-clock:

cat /sys/devices/system/clocksource/clocksource0/current_clocksource
[Important]kvm-clock and NTP

When using kvm-clock, it is not recommended to use NTP in the VM Guest, as well. Using NTP on the VM Host Server, however, is still recommended.

9.7.2. Other Time Keeping Methods

The paravirtualized kvm-clock is currently not available for SUSE Linux Enterprise Server 9 and Windows operating systems. For Windows, use the Windows Time Service Tools for time synchronization (see http://technet.microsoft.com/en-us/library/cc773263%28WS.10%29.aspx for more information).

Correct time keeping in SUSE Linux Enterprise Server 9 SP4 can be achieved by using special boot parameters:

32-bit Kernel:clock=pmtmr
64-bit Kernel:ignore_lost_ticks

SUSE Linux Enterprise Server Virtualization with KVM for IBM System z 11 SP3