Skip to content

Instantly share code, notes, and snippets.

@MadDirtMonkey
Created December 20, 2024 20:57
Show Gist options
  • Save MadDirtMonkey/80d3bcc5b976da5ab4449a7827321794 to your computer and use it in GitHub Desktop.
Save MadDirtMonkey/80d3bcc5b976da5ab4449a7827321794 to your computer and use it in GitHub Desktop.
Proxmox - passing CIFS share to unprivileged LXC container

To pass a CIFS/SMB share to an unprivileged LXC container, we will need to configure the mount on the Proxmox host and then pass this through to the LXC container.

The following steps need to be performed on your Proxmox host:

1. Create a mount point

mkdir -p /mnt/media

2. Add CIFS credentials

nano /root/.cifs_credentials

Add the content:

username=your_cifs_username
password=your_cifs_password

Then secure the file by restricting R/W access to root only:

chmod 600 /root/.cifs_credentials

3. Configure the mount

Edit /etc/fstab and configure the share mounted with the uid and gid of the container's root user, which is by default 100000:

//x.x.x.x/media /mnt/media cifs vers=3.0,credentials=/root/.cifs_credentials,uid=100000,gid=100000,nofail,x-systemd.automount 0 0

Note that I also use nofail and x-systemd.automount here since my Proxmox host also runs my TrueNAS instance, so after rebooting the share may not be available on the initial mounting attempt.

4. Update the LXC configuration

Bind the mount into the LXC container like this:

pct set <container_id> -mp0 /mnt/media,mp=/mnt/media

If you have multiple mounts you can just use -mp1, -mp2, etc.

Conclusion

That's it! If you now run mount -a this will ensure that the new /etc/fstab configuration takes effect.

Now reboot (or start) your container and it will have access to your newly added mounts. Easy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment