2. Using Spice

Note

I’ll use qemu-kvm as a name for the executable. If you’re using a manually built qemu or a qemu without kvm then just replace qemu-kvm with your own binary. I’ll use host$, client$ and guest$ shell prompt notations to distinguish where the command should be the command. See section Glossary to be sure that you know difference between the host, client and guest. You can ignore the difference between guest, client and host if they are all running on the same machine.

2.1. Running qemu manually

The first thing to do is to create a guest image. You can use any raw device such as a clean logical volume, or an iSCSI lun. You may also use a file as the disk image for the guest. I’ll use a file created by qemu-img as a demonstration.

The following command will allocate a 10GB file. See qemu-img man page for further information.

host$ qemu-img create /path/to/xp.img 10G

Now that we created an image, we can now start with image population. I assume that you have a locally stored ISO of your favourite operating system so you can use it for installation.

host$ qemu-kvm -machine vmport=off \
        -boot order=dc -vga qxl \
        -spice port=3001,disable-ticketing -soundhw hda \
        -device virtio-serial -chardev spicevmc,id=vdagent,debug=0,name=vdagent \
        -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
        -cdrom /path/to/your.iso /path/to/your.img

Let’s take a brief look at the qemu options that were used. The option -machine vmport=off disables VMWare IO port emulation, which is necessary for server mode mouse to work properly with spice. The option -boot order=dc specifies that the guest system should try to boot from the first cdrom and then fallback to the first disk, -vga qxl specifies that qemu uses a qxl graphics device.

The Spice port option defines what port will be used for communication with the client. The Spice option disable-ticketing is specifying that ticketing (simple authentication method) is not used. The virtio and chardev devices are required by the guest agent.

The -soundhw hda option provides an audio device for the guest to use for audio playback and recording. In order for spice audio to work properly, qemu must use the spice audio driver. Depending on how qemu was built, however, this might not be the default audio driver. To ensure qemu uses the spice audio driver, you can set the environment variable QEMU_AUDIO_DRV=spice.

2.2. Basic configuration

This section will assume that you already have a running QEMU virtual machine, and that you are running it either through virt-manager, libvirt or through direct QEMU use, and that you want to enable Spice support for this virtual machine.

Using virt-manager. Double-click on the virtual machine you are interested in, go to "View/Details". If the left pane has a "Display Spice" entry, then the virtual machine already has Spice support, and you can check the connection details (port number) by clicking on it. If it has no Spice entry, click on "Add Hardware", and add a "Graphics" element of type "Spice server". If the host and the client are not the same machine, you should check the "Listen on all public network interfaces" checkbox, otherwise you don’t need to make any changes.

You should also add a QXL video device. It can be done by double-clicking on a virtual machine, then by going to View/Details, and by clicking on "Add Hardware" if the virtual machine does not have a "Video QXL" item in its left pane. From the "Add hardware" dialog, you should then create a "Video" device whose model is "QXL".

After stopping and restarting the virtual machine, it should be accessible with a Spice client.

You can remove non-Spice display entries and non-QXL video entries from the virtual machine configuration.

If you go to "Edit/Preferences/VM Details" in the main virt-manager window, you can set Spice graphics type as the default setting for new virtual machines.

Using libvirt. All libvirt examples will assume that the virtual machine to modify is $vmname and that virsh is using the correct libvirt connection by default.

To add Spice support to an existing virtual machine managed by libvirt, you need to edit it:

host$ virsh edit $vmname

and then add a Spice graphics element:

<graphics type='spice'/>

You should also add a QXL video device

<video>
    <model type='qxl'/>
</video>

After stopping and restarting the virtual machine $vmname, it should be accessible through Spice. You can check the connection parameters with:

host$ virsh domdisplay $vmname

Using QEMU. To enable Spice support to your virtual machine, you only need to append the following to your QEMU command line:

-spice port=3001,disable-ticketing

This will setup a Spice session listening on port 3001 exporting your virtual machine display.

You can also add a QXL device by appending -vga qxl to the command line.

2.3. Connecting to the guest

The following section will show you basic usage of the Spice client. The example connection will be related to the qemu instance started in the previous sections.

Be aware that the port used for spice communication (port 3001 in our case) should not be blocked by firewall. Host myhost is referring to the machine which is running our qemu instance.

client$ remote-viewer spice://myhost:3001