Sharing a folder with VMs

I am sure this used to be easier. Oh yes, I used to use a Mac with Parallels for virtualisation, it was easier.

I have my Fedora 38 host using virt-manager to run a Windows 10 guest in a QEmu container. It’s pretty slick, but I can’t yet transfer files between the guest and host.

Looking in the virt-manager devices I see that I can add ‘virtiofs’ for sharing a host folder. Perfect, let’s try that. It needs shared memory, OK I can switch that on. Still not working, oh, it doesn’t work with Windows at all.

Next I read about Spice WebDAV. So, I add the new spice channel ‘org.spice-space.webdav.0’ and install the guest tools for spice webdav. I have read that it shares the folder ‘Public’ by default, which is fine by me. But still nothing in Windows.

With frustration starting to creep in I go old school and decide to setup a Samba share on the internal virtual network. Does it work? Does it heck!… I have lost a lot of hair over this, so let’s just accept that there is a magic incantation that works. I read so many posts, and so many rants, and each one had a piece of the puzzle. Frankly this post will be a piece of somebody else’s puzzle because every deployment is different.

Before I do the grand reveal, the key bits of information that finally unblocked it for me where:

  1. You cannot use ‘guest ok = yes’ with ‘valid users’ (note ‘guest ok’ and ‘public’ mean the same)
  2. For SELinux to work, you need to give extra permission to the folder like so ‘chcon -t samba_share_t Shared’.
  3. Restrict Samba to use the internal VM network, which in my case is virbr0.
  4. Punch a hole through the firewall so that Samba can be connected to via the internal VM network like so:
    firewall-cmd –get-active-zones
    sudo firewall-cmd –permanent –zone=libvirt –add-service=samba
    sudo firewall-cmd –reload

And now with no further ado, here is the magic incantation I finally used in ‘/etc/samba/smb.conf’.

        workgroup = SAMBA
        map to guest = bad user
        bind interfaces only = yes
        interfaces = lo virbr0
        guest account = myuser

        comment = Shared
        path = /home/myuser/Shared
        security = share
        read only = no
        browseable = yes
        writable = yes
        map to guest = bad user

        public = yes
        guest ok = yes
        guest only = yes
        force user = myuser
        force group = myuser
        force create mode = 0644
        force directory mode = 0755

Linux is an education.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s