When working with KVM virtualization through virt-manager, many users encounter a frustrating behavior where the guest OS permanently captures mouse focus, requiring the Ctrl_L+Alt_L combination to release control. This occurs across multiple Linux distributions:
OS virt-manager libvirt Focus Capture
-----------------------------------------------
Fedora 14 0.8.7-2 0.8.3-10 Yes
CentOS 5 0.6.1-16 0.8.2-25 Yes
CentOS 6 0.9.0-14 0.9.10-21 Yes
The issue stems from virt-manager's default input device configuration. The standard mouse emulation lacks proper focus release capabilities, particularly noticeable with Windows guests (though not exclusive to them).
Adding a virtual tablet device provides proper absolute pointer positioning and seamless focus transition:
<input type='tablet' bus='usb'/>
To implement this:
- Shut down the guest VM
- Edit the VM's XML configuration:
virsh edit vm_name
Add this section within the <devices>
tag:
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
For users who prefer scripted solutions:
#!/bin/bash
# Add tablet device to all running VMs
for vm in $(virsh list --name --state-running); do
virsh attach-device $vm <(cat <<EOF
<input type='tablet' bus='usb'>
<address type='usb' bus='0' port='1'/>
</input>
EOF
) --config --live
done
After implementation, verify the input devices:
virsh dumpxml vm_name | grep -A5 '<input'
For enhanced functionality, consider combining with these QEMU options:
<graphics type='spice'>
<clipboard copypaste='yes'/>
<mouse mode='client'/>
</graphics>
The tablet input method adds minimal overhead (typically <1% CPU usage on modern systems). For environments with many simultaneous users, batch configuration is recommended:
for vm in $(virsh list --all --name); do
virsh attach-device $vm tablet.xml --config
done
Where tablet.xml
contains the input device configuration.
Working with Windows Server 2008 R2 (or other OSes) as KVM guests through virt-manager presents a common pain point: the forced mouse capture requiring Ctrl_L+Alt_L to release. This behavior persists across multiple distros:
OS virt-manager libvirt
Fedora 14 0.8.7-2 0.8.3-10
CentOS 5 0.6.1-16 0.8.2-25
CentOS 6 0.9.0-14 0.9.10-21
The core issue stems from the default PS/2 mouse emulation in QEMU/KVM. When virt-manager initializes a VM, it typically creates input devices like:
<input type='mouse' bus='ps2'/>
<input type='keyboard' bus='ps2'/>
PS/2 devices require explicit focus capture/release because they can't handle absolute pointer positioning.
The most effective workaround involves adding a virtual tablet device to your VM configuration. This provides absolute pointer positioning similar to physical tablets.
For existing VMs, edit the XML configuration:
virsh edit vm_name
<!-- Add this under devices -->
<input type='tablet' bus='usb'/>
For new VMs using virt-manager GUI:
- Open VM hardware details
- Click "Add Hardware"
- Select "Input" → "EvTouch USB Graphics Tablet"
If tablet devices aren't viable, consider these methods:
# 1. SPICE protocol with agent
<graphics type='spice'>
<clipboard copypaste='yes'/>
</graphics>
<channel type='spicevmc'>
<target type='virtio' name='com.redhat.spice.0'/>
</channel>
# 2. Xorg configuration tweak (host side)
Section "ServerFlags"
Option "AutoAddDevices" "false"
Option "AllowEmptyInput" "false"
EndSection
After implementing changes, verify with:
# Check active input devices
virsh dumpxml vm_name | grep -A5 "input device"
# Monitor input events
evtest /dev/input/eventX
Performance impact is typically negligible (<1% CPU overhead for tablet devices).
This behavior originates from early virtualization implementations where complete input device emulation was resource-prohibitive. Modern solutions leverage:
- VirtIO-input (kernel 3.8+)
- Multi-touch protocol extensions
- SPICE/QXL drivers