Skip to content

Instantly share code, notes, and snippets.

@zaki-hanafiah
Last active July 2, 2024 16:16
Show Gist options
  • Save zaki-hanafiah/a0105480e6d69d103be1f2fcd824fac6 to your computer and use it in GitHub Desktop.
Save zaki-hanafiah/a0105480e6d69d103be1f2fcd824fac6 to your computer and use it in GitHub Desktop.
Proxmox: Create CIFS shared storage between host and LXCs (Linux Containers)

In the LXC (run commands as root user)

  1. Create the group "lxc_shares" with GID=10000 in the LXC which will match the GID=110000 on the PVE host.

   groupadd -g 10000 lxc_shares

  1. Add the user(s) that need access to the CIFS share to the group "lxc_shares". f.e.: jellyfin, plex, ... (the username depends on the application)

   usermod -aG lxc_shares USERNAME

  1. Shutdown the LXC.

On the PVE host (run commands as root user)

  1. Create the mount point on the PVE host.

   mkdir -p /mnt/lxc_shares/nas_rwx

  1. Add NAS CIFS share to /etc/fstab.
Spoiler: command explanation
  • Adjust //NAS/nas/ in the middle of the command to match your CIFS hostname (or IP) //NAS/ and the share name /nas/.
  • Adjust user=smb_username,pass=smb_password at the end of the command.

{ echo '' ; echo '# Mount CIFS share on demand with rwx permissions for use in LXCs (manually added)' ; echo '//NAS/nas/ /mnt/lxc_shares/nas_rwx cifs _netdev,x-systemd.automount,noatime,uid=100000,gid=110000,dir_mode=0770,file_mode=0770,user=smb_username,pass=smb_password 0 0' ; } | tee -a /etc/fstab

  1. Mount the share on the PVE host.

   mount /mnt/lxc_shares/nas_rwx

  1. Add a bind mount of the share to the LXC config. Adjust the LXC_ID at the end of the command.
RWX (Read | Write | Execute) Permissions You can mount it in the LXC with read+write+execute (rwx) permissions.

   { echo 'mp0: /mnt/lxc_shares/nas_rwx/,mp=/mnt/nas' ; } | tee -a /etc/pve/lxc/LXC_ID.conf

RO (Read Only) Permissions You can also mount it in the LXC with read-only (ro) permissions.

   { echo 'mp0: /mnt/lxc_shares/nas_rwx/,mp=/mnt/nas,ro=1' ; } | tee -a /etc/pve/lxc/LXC_ID.conf

You can now start the LXC and verify that /mnt/nas/ is accessible from the container.

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