[How to] Setting up Shared folders, Auto resize VM and Clipboard share with virt-manger

How to setup QEMU/KVM with virt-manager

Shared Clipboard:

  • Linux: install spice-vdagent on the guest machine:
# Arch
sudo pacman -S spice-vdagent
# Debian
sudo apt install spice-vdagent
# Fedora
sudo yum install spice-vdagent

Auto resize VM resolution with window resize:

  • First make sure that the spice-guest-tools/spice-vdagent is installed on the host from the previous step.
  • And then navigate to View > Scale Display and check the “Auto resize VM with window” option:

A NOTE FOR LINUX GUESTS RUNNING XFCE

On Linux guests running XFCE, it does not work automatically, you have to run the following command every time you resize the window:

xrandr --output Virtual-1 --auto

Read more here.

You can add a launcher to the XFCE panel that executes this command.

But even better than that, I wrote the following quick and dirty script and added it to autostart, it makes it behave like the Windows VM:

#!/bin/bash
while true; do
    while read -r output; do
        xrandr --output $output --auto
    done < <(xrandr | grep "Virtual" | awk '{print $1;}')
    sleep 1
done

Another way that may be suggested is crontab, but crontab can’t run a command at less than 1 minute intervals. You can use watch by running the following command:

watch -n 1 xrandr --output Virtual-1 --auto

But I found it difficult to background the process, so I just stuck with my script, especially since it takes up hardly any extra resources.

ezgif-5-4fcf78ba80

ezgif-3-a0d4af0436

Shared Folders:

On your host machine (Manjaro/Linux):

  1. Create a folder to share with.

  2. Open virt-manger, select the virtual machine you want to share a folder with and click open:

    image

  3. Click on the info tab, and then click on add hardware:



  4. Select filesystem, and fill in the fields.

    • Driver: Keep this as virtiofs
    • Source Path: This is the path to the folder you want to share on your host.
    • Target path: Now this is misleading. It’s not a path, rather it’s the name the share will be given on the guest machine.

  5. After you have filled the fields, click on the finish button.
    This is all you have to do on your host.

On the guest:

  • Linux:
  1. Create a folder to have the share mapped to.
  2. Open the terminal in the guest machine, and type:
sudo mount -t virtiofs sharename path/on/guest
  1. To make it permanent add the following entry to the /etc/fstab:
sharename           path/on/guest    virtiofs    defaults        0       0
  1. That’s it! Good old Linux!!

example

  • Windows:

I know, I know, this is the Manjaro Linux forum. However, most people use virtual machines to run Windows so I thought I should add this to the guide, especially since it’s not that straight forward.

  1. Install the virtio-win package from the AUR on your Host (yay -S virtio-win).

    • Navigate to the info tab again and click on “Add Hardware”

    • Select the storage option, click on “Select or create custom storage”,

    • Change “Device type:” and then click on “Manage”.

    • Click on “Browse Local” and select /var/lib/ibvirt/images/virtio-win.iso

    • Select “virtio-win.iso” and click on “Choose Volume”.


      Good old flameshot :grin:

    • Or, if you prefer the manual way, download the virtio driver on the Windows machine and mount it there.

  2. Download WinFSP and install it (on the guest).

  3. Open the device manager:

    image
    Image credit goes to this blog.

  4. Right click on the “Mass Storage Controller” and select “Update driver”, Choose “Browse my computer for drivers” and select the mounted ISO.

  5. After the drivers are installed, navigate to the viofs folder in the mounted ISO and copy the correct folder according to your Windows version (“w10” for Windows 10):

  6. Copy it to a location on the C: drive such as C:\virtiofs\w10.

  7. Open a command line and type:

sc.exe create VirtioFsSvc binpath="path\to\virtiofs.exe" DisplayName="Virtio FS Service"
sc.exe start VirtioFsSvc
  1. Now the shared folders should show up as mounted drives in the file explorer.

NOTE: An issue that I can’t seem to solve is that only the first share is shown, i.e if I create more than one share, only the first defined one shows up.


Sources:

7 Likes

Might want to link to the AUR package instead maybe?
https://aur.archlinux.org/packages/virtio-win

1 Like

But that’s on the guest… I mean you mount the driver ISO on the windows machine…
How would I install an AUR package on the guest?
Unless installing it on the host gets it to work on the guest?

See the sticky comment on that AUR:

jetm commented on 2021-07-02 17:04 (UTC)

After the virtio-win 0.1.196 update, note these two changes:

  • ISO image is copied at /var/lib/libvirt/images
  • The Windows XP floppies are not distributed anymore as upstream remove the support

So you can mount the iso afterwards from /var/lib/libvirt/images :wink:

Using the AUR package will keep the ISO(s) up-to-date over time :wink:

1 Like

As soon as the package finishes installing, I’ll update the post.

In my case, since I used the setup in the iso, the service was already present and the driver already installed

plus i would add
sc config virtiofssvc start=auto
so that the service starts at windows startup

In my case it started automatically without specifying start=auto.

Have you tried to add more than one shared folder to your VM?
If so, do both shares show up in the file manager (on Windows)?

yes I tried and only one works while the others are simply ignored