Hans de Goede (hansdegoede) wrote,
Hans de Goede

Using spice from the qemu cmdline

Various people have been asking how to run qemu with spice when launching qemu directly, rather then through libvirt + virt-manager. So here is a quick howto.

*** The basics *** 

Besides adding the usual qemu cmdline options to make it find the harddisk to boot from, have a NIC, soundcard, etc. in order to add spice add the following to the cmdline:
-vga qxl -spice port=5932,disable-ticketing

After launching qemu with this, you can connect to it with spicy (new gtk based client) or spicec (old libX11 client), like this
(their cmdline syntax is compatible):
spicy -h localhost -p 5932

*** Enabling the agent channel ***

To really enjoy spice, with all its features like copy paste between client and guest, and client mouse mode (mouse cursor drawn by client, so 0 mouse lag), you need to install the qxl graphics driver and spice-agent in the guest, *and* enable the agent channel between the guest and the client, to do this add the following options to the qemu cmdline:
-device virtio-serial \
-chardev spicevmc,id=vdagent,name=vdagent \
-device virtserialport,chardev=vdagent,name=com.redhat.spice.0

*** Enabling support for usb redirection ***

If you're running qemu under Fedora-16 (or newer), or have build it from source with usbredirection support as explained in my previous blog post, then you can also let spice redirect usb devices from your client to the vm, to enable this you will first need to enable usb2 emulation in qemu, download this file, and drop it in /etc/qemu. And at the following to the qemu cmdline:
-readconfig /etc/qemu/ich9-ehci-uhci.cfg

Then to create 3 usbredir ports into which the client can then "plug" redirected devices add the following:
-chardev spicevmc,name=usbredir,id=usbredirchardev1 \
-device usb-redir,chardev=usbredirchardev1,id=usbredirdev1,debug=3 \
-chardev spicevmc,name=usbredir,id=usbredirchardev2 \
-device usb-redir,chardev=usbredirchardev2,id=usbredirdev2,debug=3 \
-chardev spicevmc,name=usbredir,id=usbredirchardev3 \
-device usb-redir,chardev=usbredirchardev3,id=usbredirdev3,debug=3 \

The debug=3 is not strictly necessary, but it gives some useful messages without flooding the qemu console with messages. Note that you can also create more / less then 3 usbredirection usb "ports", how to do this is left as an
excercise to the reader :)

To use the usb redirection  connect to the vm with spicy running as root, so that it can access the device nodes under /dev/bus/usb.

Select the options menu entry and make sure that the "auto redirect newly plugged in USB devices" option is checked. After this make sure the vm has keyboard focus (so close the options menu), plug in a new USB device and watch it show up in your vm :) Feel free to yank it out again at any time :)

If you plug in a device while the vm does not have keyboard focus, it will not get redirected, so you can use usb devices
normally as long as you don't have the vm focussed when you plug them in.

Enjoy, and be sure to send any feedback you may have my way!
Tags: fedora, qemu, spice
  • Post a new comment


    Comments allowed for friends only

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened