Built-in qemu SMB serving in LXD/Incus?

Qemu can use host smbd binaries to create private shares with guests: QEMU/Options - Gentoo wiki

I was thinking of using raw.qemu.conf to override the NIC section and add the “smb” option, but I can’t find how the virtio-net NIC is defined.

Is there any way to use this qemu feature with LXD/Incus?

Network devices are tricky because they’re defined through QMP rather than through the QEMU command line or the config file, so there’s no good way to override them through a raw. type key at this point.

Specifically for the smbd case, why use that rather than virtiofs?

incus config device add VM public disk source=/usr/local/public path=/mnt/public should achieve the same end result but with significantly better performance.

I guess the main reason I could see for needing to use smbd would be Windows VMs as I’m not sure of the state of the 9p/virtiofs driver on that platform.

I tried virtiofs and it works for simple file sharing. The main issue I had is that it does not persist any Windows ACL data, all files are owned by “Everyone”. I tried to install some programs in the share but some failed, and I assume it was because of permissions.

The same tests seem to work fine on a SMB share, since Samba will use xattrs to store Windows ACL information.

Ah yeah, that sounds like a shortcoming of the virtiofs driver for Windows then…

So while you can’t easily set that config option through the raw config keys, you may be able to use raw.qemu to define an additional network interface and then have that provide the SMB server. So basically providing a NIC using QEMU’s user driver or something like that, just to provide the SMB access, but then keep using the normal NIC for internet access.

I tried adding a user interface but it seems Incus qemu doesn’t have it.

$ incus info --show-log win10
Name: win10
Type: virtual-machine
Architecture: x86_64
Created: 2023/12/23 19:47 -03
Last Used: 2023/12/23 21:14 -03


qemu-system-x86_64: -nic user,id=nic0,smb=/home/thiago/win10-share: network backend 'user' is not compiled into this binary

Would it be acceptable for Incus to have these enhancements?

  • Bundle smbd binary along with qemu and other executable dependencies so it doesn’t depend on the host’s smbd installation.
  • Either enable user nic feature, or even better: Add direct support to SMB devices to Incus VMs, which would enable the qemu SMB share on incusbr0 bridge for much better performance (user nic is not good since qemu proxies all traffic). Would be awesome adding a SMB share to a VM with something like incus config device add <instance_name> <device_name> smb source=<path_on_host>

Even though virtiofs driver works for basic file sharing, SMB is more convenient for windows considering it supports ACL and Windows supports it out of box without extra drivers/programs (virtiofs requires installing winfsp).

If it is acceptable for Incus to implement these features, I’d be willing to dive into the source code and submit pull requests.

Hmm, smbd is a bit of a can of worms security wise, so I can’t say that I’m particularly interested in having to build and ship it alongside Incus :slight_smile:

If your system already has smbd on it, then you should be able to pretty easily just run smbd on the host system and access it through the 10.X.Y.1 address from your VM.

I’m going to have to think about this a bit more…