Clipboard with VNC, libvirt and Qemu
One real PITA when using virtual machines is getting things like clipboard, graphics acceleration etc. up and running. This is a common issue I’ve encountered with several virtualization products I used in the past (e.g., VirtualBox, VMWare, Qemu).
Recently, RedHat dropped Spice support in RHEL 9 for virt-manager and Qemu. I decided to switch to VNC instead of compiling my own Qemu with built-in Spice support. Since I don’t require USB passthrough, sound, or other Spice-exclusive features, I thought it was worth (again) a try. After configuring VNC, everything worked except for the clipboard integration. However, after some research, I successfully resolved this by adding the following XML snippet to my machine’s definition (I am using libvirt on Rocky Linux 9):
<channel type='qemu-vdagent'>
<source>
<clipboard copypaste='yes'/>
</source>
<target type='virtio' name='com.redhat.spice.0'/>
<address type='virtio-serial' controller='0' bus='0' port='2'/>
</channel>
To check if the setting is active, have a look at the running qemu process, it
should be started with -chardev qemu-vdagent,id=charchannel0,name=vdagent,clipboard=on
.
Finally, in the VNC viewer (I used tigervnc), the clipboard options must be activated:
After that, the clipboard worked bidirectionally and was finally usable.
Update (2024-01-06)
For performance reasons, I decided to switch back to spice. I installed a spice-enabled Qemu version from Fedora Copr:
# dnf -y copr enable ligenix/enterprise-qemu-spice ; dnf update
# dnf install virt-manager
And configured my VM to use spice:
<graphics type='spice' port='6677' autoport='no' listen='127.0.0.1'>
<listen type='address' address='127.0.0.1'/>
</graphics>
<video>
<model type='qxl' ram='65536' vram='65536' vgamem='65536' heads='1' primary='yes'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</video>