Share Host Storage over Samba from an LXC Container
-
Create a new unprivileged LXC.
-
Set up a mount point to ZFS (PVE host shell).
Edit the config:
nano /etc/pve/lxc/[id].confAdd a new line for the mountpoint:
mp0: /zfs1/shared,mp=/mnt/pve/sharedSave and exit (Ctrl+S, Ctrl+X).
-
Set up the user/group (LXC container shell).
Create the user/group:
groupadd -g 10419 nasuseradd nas -u 10419 -g 10419Add root to the group and reload groups for root:
usermod -aG nas rootsu root -
Install Samba in the container (LXC container shell).
Install Samba:
apt updateapt install samba samba-common-binEdit the Samba config:
nano /etc/samba/smb.confAdd the shared folder:
[Shared]path = /mnt/pve/sharedwritable = yesguest ok = novalid users = @nasAdd
nasto Samba (and enter a password):smbpasswd -a nas -
Set up host users and subordinate permission mapping (PVE host shell).
Create the user and group with ID 10419:
groupadd -g 10419 nasuseradd nas -u 10419 -g 10419Set the group as owner of the folder to be shared:
chown -R nas:nas /zfs1/sharedAllow root to map this user/group by adding them to subuid/subgid:
echo "root:10419:1" >> /etc/subuidecho "root:10419:1" >> /etc/subgid -
Set up container uid/gid mappings (PVE host shell).
Edit the container config:
nano /etc/pve/lxc/[id].confAdd new lines for mapping group/user ID 10419:
lxc.idmap: u 0 100000 10419lxc.idmap: g 0 100000 10419lxc.idmap: u 10419 10419 1lxc.idmap: g 10419 10419 1lxc.idmap: u 10420 110420 55116lxc.idmap: g 10420 110420 55116Save and exit (Ctrl+S, Ctrl+X).
-
Optional: repeat steps 2, 3, and 6 for each LXC container that needs access to the same files.
The ACL way (alternative, not sure if needed)
# install ACL tools
apt install acl
# set ZFS pool ACL type
zfs set acltype=posixacl zfs1
zfs set xattr=sa zfs1
# grant permissions to the share user (the capital X means only give to dirs)
setfacl -R -m u:sambashareuser:rwX /some/folder/path/