Background reading
To get started one probably only needs to install virt-manager on their Linux system. If one is interested in the details the following topics can be explored. When virtualizing computers on an x86 Linux host the system will most likely use KVM as the hypervisor and QEMU as the emulator. virt-manager can be used to graphically run and connect to VMs on graphical Linux desktop systems. virt-manager runs the VMs, SPICE is used to make the remote desktop connection to the VMs. Background reading: virt-manager homepage, the Linux-KVM page with SPICE instructions and the SPICE homepage. The Debian project's KVM page also contains instructions on how to run and configure VMs on Linux without a GUI like virt-manager.
Sharing a directory between host and guest (VM)
Using the virt-manager GUI
Open the VM. Go to the details screen, the big "i" button, on my system it is round and white on blue. Go to memory and make sure "Enable shared memory" is on. Go to "Add Hardware", select "Filesystem", use driver "virtiofs", for source path click "Browse", then in the new screen click "Browse Local" to select a directroy on the host. "Target path" is the name we will use later to mount it from.
Mounting it on the guest should then work as follows:
$ sudo mount -t virtiofs target-path /path/to/my/dir
Add it to /etc/fstab to mount it automatically. The following works for me:
target-path /path/to/my/dir virtiofs defaults,noatime 0 1
The resulting XML
I personally only use the GUI but maybe the underlying XML is useful to you:
<filesystem type="mount" accessmode="passthrough">
<driver type="virtiofs"/>
<binary path="/usr/lib/qemu/virtiofsd"/>
<source dir="/dir/on/host/system"/>
<target dir="target-path"/>
<alias name="fs0"/>
<address type="pci" domain="0x0000" bus="0x07" slot="0x00" function="0x0"/>
</filesystem>
Adding clipboard support between host and guest
As of 2024 I didn't need to install any additional software. spice-vdagent was already installed on the guest without me taking action. I'll be giving the instructions for the virt-manager GUI here, but changing the XML directly should work too. First we shut down the VM. Then we go to the "Details" section in virt-manager (the big "i" button), then go to "Video" and make sure it is set "Model" to QXL. Finally we go to "Display Spice" and make sure it is set to "Spice". I didn't need to change the defaults, such as "listen type = Address", "Address = Hypervisor default", "Port = Auto". After starting the VM it was possible to copy and paste between host and guest, both ways.