Unable to share folder with virt-manager/qemu

Make sure you have marked the checkbox to search for drivers recursively.
Also in some cases you have to cancel the automatic search and select the driver file manually.

@alciregi I was missing that, but that was only part of the problem. It looks like there’s a lot to configure in the Samba configuration file. I’ve got it to where I can at least see the Samba share from the guest, but I can’t get access to it. Since it’s a local share and I’ve restricted it to only the lo and virbr0 interfaces, I’d like to allow access without a password. But even with map to guest = Bad Password in the global parameters and guest ok = Yes in the share configuration, it still won’t even let me try to log in. Do I have to create a dummy user even if I don’t intend to use it?

@vgaetera I did have that box checked. Maybe manual selection is the way to go for a directly shared folder.

Samba share requires proper SELinux context and recursive permissions as mentioned here.

My feelings exactly. I’ve still got SELinux disabled while setting this up, but even setting the context correctly didn’t fix anything. Here’s my smb.conf:

[global]
        workgroup = SAMBA
        security = user
        map to guest = Bad User

        passdb backend = tdbsam
        printing = cups
        printcap name = cups

        interfaces = lo virbr0
        bind interfaces only = true
        guest account = nobody

[printers]
        path = /var/spool/samba
        printable = yes
        browseable = no

[LinuxHost]
        comment = Host SAMBA Server for VM
        path = /home/bob323/libvirt-shared
        guest ok = yes
        force user = nobody
        force group = nobody
        directory mask = 777
        writable = yes
        read only = no
        create mode = 0777
        directory mode = 0777

I’ve got a folder in my home directory called “libvirt-shared” with permissions set to 777, owned by the “nobody” user and “nobody” group. I’ve run smbpasswd -a nobody and set a password for the user (it wouldn’t let me create the user without a password). I’ve even gone through the steps in that linked post a second time.

ls -l -d -Z /{,home/{,bob323/{,libvirt-shared}}}

Post the output.

@bob323, from cursory search it looks like there’s an option to easily share any folder as samba share with “built-in samba” – i.e. without configuring samba server on your host system – in qemu/kvm, but sadly it’s not implemented in virt-manager gui.

This three-post thread on Arch Linux forums summarizes it nicely.

Just so you know there’s an alternative approach.

And one more way – maybe more complicated, but compatible with virt-manager – is described here:

I’ve encountered a comment that this way isn’t recommended for transferring large files though (but with no explanation as to why).

One more tip to configuring Samba server on your host machine. You should check that your guest machine is able to communicate with your host, and for this you need to have a proper network configuration in virt-manager.

Also make sure firewall on a host machine isn’t blocking requests from your guest machine on a proper network interface. Usually, virt-manager will create a new virtual network interface for communicating with guests, so firewall rules for your main network interface won’t automatically apply to it.

dr-xr-xr-x. 20 root       root       system_u:object_r:root_t:s0              4096 Jul 22 11:46 /
drwxr-xr-x.  4 root       root       system_u:object_r:home_root_t:s0         4096 May  3 12:20 /home/
drwx--x---+ 41 bob323     bob323     unconfined_u:object_r:user_home_dir_t:s0 4096 Jul 23 10:20 /home/bob323/
drwxr-xr-x.  2 nobody     nobody     unconfined_u:object_r:samba_share_t:s0   4096 Jul 19 15:26 /home/bob323/libvirt-shared
getfacl $HOME
getfacl: Removing leading '/' from absolute path names
# file: home/bob323
# owner: bob323
# group: bob323
user::rwx
user:qemu:--x
group::---
mask::--x
other::---
setfacl --modify="user:nobody:X,group:nobody:X" $HOME

If that doesn’t help, then:

setfacl --remove-all $HOME
chmod 755 $HOME

That was it! I read up on access control lists and the whole thing still doesn’t make a lot of sense to me, but it looks like that was the last problem to overcome. It still works when I re-enable SELinux too.

@nightromantic I tried your suggestion about spice-webdav, but I ran into a couple of problems. First, the spice-space website claims that spice-webdavd is included with the spice-guest-tools installer, but it’s not. Second, even after installing spice-webdav and running map-drive.bat, there were no new drives mapped, even though the script claims it ran successfully.

To summarize for future readers, here’s the process (as of 2019) to get this working:

  • Ensure Samba is installed
  • Edit smb.conf as reproduced above. The important part is map to guest = Bad User. I’ll come back and update this post if I find that the options should be changed as I suspect the configuration file could be improved.
  • Ensure you have a Samba account for your guest user: smbpasswd -a nobody
  • Enable Samba in your firewall: sudo firewall-cmd --permanent --add-service="samba"; sudo firewall-cmd --reload
  • I suspect the ACL problem was caused by me putting the shared folder inside my home folder. It may be possible to avoid this by putting your shared folder elsewhere. Otherwise, run the setfacl fix in @vgaetera’s post above, which will be marked as the solution.
  • Find your Samba shares in your Windows VM by going to Explorer and typing \\192.168.122.1 in the URL bar. This IP address may be different for you, but I imagine it’s standard across instances of virt-manager. This is the IP address of your host on the “virbr0” network interface, which can be found with ifconfig.
  • At this point I was able to make changes within the folder with my guest but not my main user. I fixed this by running chmod -R 777 libvirt-shared. A more secure solution might be to add your main user and your Samba guest user to a “virt-users” group or something similar and expand full permissions to the group only, or to set a Samba password for your main user and use that as the guest account if that’s even possible.
2 Likes

A few notes on this, since I’m having to do it again on a new computer and seemingly can’t edit my last post:

smbpasswd has to be run as root.

Additionally, if you’re doing this in one go (i.e. no reboots), be sure to enable and run the Samba service: sudo systemctl enable smb; sudo systemctl start smb

Don’t forget to set the Samba SELinux context and booleans: sudo setsebool -P samba_export_all_ro=1 samba_export_all_rw=1; chcon -t samba_share_t /home/bob323/libvirt-shared

It may be a good idea to change the zone of the virbr0 network interface in your firewall settings. If you do this (e.g. by changing it to “libvirt”) be sure to add --zone=libvirt or whichever zone you select to the first firewall configuration command.

Finally, I had to add read only = no to the end of my smb.conf. No idea why this wasn’t necessary the first time, but I’m up and running on the new computer now. Somehow I missed that there was more to the smb.conf file posted earlier if I scrolled down. Permissions can be set to 0755 rather than 0777.

Hello,
I’m quite a noob with linux. I hope this is the right place to ask for help (if not please let me know where). I followed the steps with which @bob323 managed to set up a samba share between the fedora host and windows guest. At first it worked (I mean windows could connect to the shared folder on 192.168.122.1), but after i rebooted the host windows could no longer establish the connection. Maybe I’m missing something obvious but I don’t have any idea what to do.
Sorry for my english and thanks in advance for your help.

I discovered that restarting samba with systemctl restart smb solves the issue. It’s not so practical but at least it works

Maybe you missed this step?

1 Like

I didn’t missed that step, but now that you made me think about it I checked the status of smb after boot and it says that it failed to start. The output is this:

● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: failed (Result: core-dump) since Fri 2020-10-02 11:52:55 CEST; 56s ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Process: 1335 ExecStart=/usr/sbin/smbd --foreground --no-process-group $SMBDOPTIONS (code=dumped, signal=ABRT)
Main PID: 1335 (code=dumped, signal=ABRT)
Status: “smbd: ready to serve connections…”
CPU: 87ms
ott 02 11:52:55 dhcppc8 smbd[1335]: #4 /usr/lib64/samba/libsmbd-base-samba4.so(+0x240a97) [0x7fec0acc9a97]
ott 02 11:52:55 dhcppc8 smbd[1335]: #5 /usr/lib64/samba/libsmbd-shim-samba4.so(exit_server+0x18) [0x7fec0a2ac9d8]
ott 02 11:52:55 dhcppc8 smbd[1335]: #6 /usr/sbin/smbd(main+0x135f) [0x55ea5cd7d1ff]
ott 02 11:52:55 dhcppc8 smbd[1335]: #7 /lib64/libc.so.6(__libc_start_main+0xf2) [0x7fec09f3b042]
ott 02 11:52:55 dhcppc8 smbd[1335]: #8 /usr/sbin/smbd(_start+0x2e) [0x55ea5cd7dd9e]
ott 02 11:52:55 dhcppc8 smbd[1335]: [2020/10/02 11:52:55.720628, 0] …/…/source3/lib/dumpcore.c:317(dump_core)
ott 02 11:52:55 dhcppc8 smbd[1335]: coredump is handled by helper binary specified at /proc/sys/kernel/core_pattern
ott 02 11:52:55 dhcppc8 smbd[1335]:
ott 02 11:52:55 dhcppc8 systemd[1]: smb.service: Main process exited, code=dumped, status=6/ABRT
ott 02 11:52:55 dhcppc8 systemd[1]: smb.service: Failed with result ‘core-dump’.

The strange thing is that if I restart smb everything work. When I check the status after restarting the output is this:

● smb.service - Samba SMB Daemon
Loaded: loaded (/usr/lib/systemd/system/smb.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2020-10-02 12:00:50 CEST; 18s ago
Docs: man:smbd(8)
man:samba(7)
man:smb.conf(5)
Main PID: 4035 (smbd)
Status: “smbd: ready to serve connections…”
Tasks: 4 (limit: 18741)
Memory: 7.9M
CPU: 62ms
CGroup: /system.slice/smb.service
├─4035 /usr/sbin/smbd --foreground --no-process-group
├─4037 /usr/sbin/smbd --foreground --no-process-group
├─4038 /usr/sbin/smbd --foreground --no-process-group
└─4039 /usr/sbin/smbd --foreground --no-process-group
ott 02 12:00:50 dhcppc8 systemd[1]: Starting Samba SMB Daemon…
ott 02 12:00:50 dhcppc8 smbd[4035]: [2020/10/02 12:00:50.082171, 0] …/…/lib/util/become_daemon.c:135(daemon_ready)
ott 02 12:00:50 dhcppc8 smbd[4035]: daemon_ready: daemon ‘smbd’ finished starting up and ready to serve connections
ott 02 12:00:50 dhcppc8 systemd[1]: Started Samba SMB Daemon.

Do anybody have any clue about what could be the problem?

Please open a new topic, thanks.

1 Like

https://discussion.fedoraproject.org/t/problem-with-samba/9486/4?u=alciregi

2 Likes