As VMWare Workstation used to be expensive even for personal license (which is now free to use but still requires an account), I usually go with Oracle VirtualBox. When I started the switch to QEMU/KVM and virt-manager (libvirt), the first thing I do is checking its features, or more specifically, vbox features in the libvirt way.
Talk is cheap, let me just show you how to do it.
Extension
Clipboard sharing & drag and drop:
# Debian/Ubuntu
sudo apt install -y spice-vdagent
# Rocky/AlmaLinux
sudo dnf install -y spice-vdagent
# Arch/Manjaro
pamac install --needed spice-vdagent
# Void
sudo xbps-intall -Sy spice-vdagent
# Gentoo
emerge app-emulation/spice-vdagent
For Windows, install latest spice-guest-tools, or simply use virtio-win-guest-tools installer mentioned (later) in #File Sharing which comes with Spice agent bundled.
File Sharing
- File Sharing with Qemu and Virt-Manager
- Do I need both the QEMU Agent and SPICE Agent installed in Windows 10 guest?
Two options:
I’ll go VirtIO-FS route:
- In host OS, install virtiofsd (virtio-fs device daemon)
- Head to virt-manager, enable
shared memory
- Add a
Filesystem
hardware in quest VM hardware details page (e.g. mount host~/Public
as questshare
) - Boot
Linux Quest
For GNU/Linux quest:
mkdir ~/shared
sudo mount -t virtiofs share ~/shared
# If quest username is different from host
sudo chown $(whoami):$(whoami) ~/shared
A silly thing is when VM is booted, you can’t edit files in HOST as they are now owned by a random UID instead of you temporarily… Windows quest works fine though.
I think file sharing in BSD works in a similar way.
Windows Quest
For Windows quest, simply use Chocolatey (vertio-drivers
package is very outdated and NOT usable in latest Windows 10, let alone Windows 11):
gsudo choco install winfsp
# gsudo choco install virtio-drivers
Or if you prefer to install it the hard way:
- WinFsp, stable or prerelease, it does not matter
Installing VirtIO drivers can be a bit complicated:
- Tutorials
- Windows VirtIO Drivers - Proxmox XE: follow this
- Download guide from virtio-win/virtio-win-pkg-scripts: skip this
- How to install virtiofs drivers on Windows: install service, or use
services.msc
and set VirtIO-FS service to autostart - How do I set-up file sharing between my host(arch) & guest(windows)?: file sharing tip for Windows quest
- 21.2.1.2. 在主机中准备 virtio 驱动程序安装介质 - RHEL9
- Downloads: Stable, Latest (both are quite stable, just use
latest
asstable
cannot be used in Windows 10 1809+) - Install: simply run
virtio-win-gt-x64.msi
, you can also runvirtio-win-guest-tools.exe
to install QEMU Guest Agent & SPICE agent for better remote desktop experience
3D Acceleration
GNU/Linux:
- Display Spice -> Listen type ->
None
,tickOpenGL
- Video Virtio -> 3D acceleration
Windows:
- Windows VM uses
QXL
by default - You can install virtio drivers following instruction in #File Sharing
- When you are done, change video model to
virtio
, then just enable 3D acceleration as Linux guest
TBH I think QXL and Virtio are all terrible. Even VBoxVGA w/o 3D acceleration would outperform these two, let alone VBoxSVGA. However, VirtualBox 7.0 is fairly buggy and you just can’t enable 3D acceleration on Linux host. This was reported in their forum last year and still remains unsolved ¬_¬
Snapshot
QEMU has native support for that. It just won’t show up if I use live CD and do not give a qcow2 disk.
As F37 kvm/qemu : How to create snapshots and manage them is confusing, read 19.7. Managing Snapshots - RHEL7 instead. You’ll get the idea within a minute.
My narration:
- It works in a significantly different way than VirtualBox.
- A QEMU snapshot means the full OS backup. If you restore the snapshot, you’ll have the exact system status just like before. When you play a retro game, save the whole game state using the quick save/load function provided by the simulator so that you can restore that later. (And my analogy implies that when you load a state, you’ll lose your save in-between.)
- A VirtualBox snapshot works more like linear game checkpoints/saves (but far more tricky). The checkpoint size is much smaller than game state, but when you revisit the checkpoint, weird enough, Virtualbox does not delete the data in the middle, instead, it merges the used checkpoint into a system save (which would make it larger).
In case you still don’t understand how VirtualBox snapshot works, the closest example I can think up is the A.D.M.S. mechanism in YU-NO (この世の果てで恋を唄う少女 YU-NO). When you do a save operation, it records your current space, time, and (warning: minimal game spoiler) location of alternative universe.
In contrast, a QEMU snapshot just creates a new universe in the same state. A bit crazy, but much more effective as snapshots won’t interface with each other. They are parallel universes you can travel between.
Port Forwarding
This is for user session only. In system session (aka. qemu:///system
), you should have no problem connecting to the quest since they are literally in the same network. Should you encounter any, use bridge network instead.
Before you mess something up, let me make it clear: you do NOT need to setup obscure iptables/nftables rules (as in my first test of Rocky Linux 9, it uses firewalld instead, which is a completely different story) at all for this to work.
Following the last answer that got only one upvote in How to port forward SSH in virt-manager? (and under the hood libvirt domain XML format regarding passt connection), just one command and four lines of change would do the trick.
Install passt
backend for libvirt usage:
xi passt
In virt-manager page, shut down your VM, then Edit -> Preferences -> General -> Enable XML editing
.
Now open hardware details page of your VM (do NOT turn on VM yet, that’s why I did not write open VM hardware details page
), head to your network card (for me, it’s something like NIC :12:34:5f
), switch to XML
tab and add these (continuous port like 23333-23456
or udp port are supported as well) between <interfece>
:
<backend type='passt'/>
<portForward proto='tcp'>
<range start='23333' to='22'/>
</portForward>
Apply, done.
Now you can start your VM with guest port 22
forwarded to host port 23333
.
No nftables curd, no service restart chore.
Install a package, edit the XML, apply, and it just works™.
Postscript
In Libvirt Chap3 I mentioned optimizing MS-DOS 6.22 parameters, and in #3D Acceleration I dissed Windows VM performance in QEMU/KVM. In Chapter 5, I’m going to discuss the optimization of Windows VM in virt-manager.