Mount NAS Directories to PVE and LXC

Mounting a folder from your NAS to your Proxmox (PVE) host so that your LXCs can access it is a common and very useful setup. Here’s a comprehensive guide, covering the most common scenarios and best practices.

Understanding the Flow:

  1. NAS Share: Your NAS needs to have a share configured (e.g., SMB/CIFS or NFS). NFS is generally preferred for Linux-based systems like Proxmox due to better POSIX permissions handling and performance, but SMB/CIFS can also work.
  2. PVE Host Mount: You’ll mount the NAS share onto your Proxmox host. This makes the NAS content directly accessible by the PVE kernel.
  3. LXC Bind Mount: You’ll then “bind mount” a specific directory from the PVE host into your LXC container. This effectively makes the NAS content appear inside the LXC.

Step-by-Step Guide

Let’s assume your NAS share is //192.168.1.100/myshare (SMB) or 192.168.1.100:/myshare (NFS).

NFS is generally more robust and performs better with Linux.

Part 1: Configure NAS (NFS)

  1. Enable NFS Service: On your NAS (Synology, QNAP, TrueNAS, etc.), ensure the NFS service is enabled.
  2. Create Share: Create the folder/share you want to export (e.g., myshare).
  3. Set NFS Permissions:
  • Host: Add the IP address of your Proxmox host (e.g., 192.168.1.50) to the allowed hosts for this share. You might see options like * for all hosts (less secure) or specific subnet masks.
  • Root Squash/No Root Squash: Be careful with this.
  • no_root_squash: Root on the client (Proxmox) will be treated as root on the NFS server. This provides full control but can be a security risk if the Proxmox host is compromised.
  • root_squash (default): Root on the client will be mapped to an anonymous user/group (often nobody:nogroup) on the NFS server. This is safer but might cause permission issues if your LXC processes need root-level access to the files.
  • Permissions: Set read/write (RW) permissions if your LXC needs to write to the share.

Part 2: Mount on Proxmox Host (NFS)

  1. Install NFS Client:
apt update
apt install nfs-common
  1. Create Mount Point on PVE: Choose a location on your Proxmox host to mount the NAS share. A common place is /mnt/nas/<share_name>.
mkdir -p /mnt/nas/myshare
  1. Test Mount:
mount -t nfs 192.168.1.100:/myshare /mnt/nas/myshare
  • Common Options:
  • _netdev: Ensures the network is up before attempting to mount (important for /etc/fstab).
  • auto: Allows mounting at boot.
  • sync or async: async (default) can improve performance but risks data loss on crashes. sync is safer but slower.
  • hard or soft: hard makes the client retry indefinitely on errors (can hang processes). soft makes it return an error after a timeout. soft,intr allows processes to be interrupted. hard,intr is often a good balance.
  • nolock: If you encounter issues (less common with modern NFSv4).
  • vers=3 or vers=4: Specify NFS version if needed. Most modern setups use NFSv4.

For example:

mount -t nfs 192.168.1.100:/myshare /mnt/nas/myshare -o defaults,hard,intr,_netdev
  1. Verify Mount:
df -h /mnt/nas/myshare
ls -l /mnt/nas/myshare

You should see the contents of your NAS share.

  1. Make Mount Permanent (Add to /etc/fstab):
echo "192.168.1.100:/myshare /mnt/nas/myshare nfs defaults,hard,intr,_netdev 0 0" >> /etc/fstab
  • Important: Always test the manual mount command first.
  • After adding to fstab, run mount -a to test if it mounts correctly without rebooting.

Option 2: Using SMB/CIFS

SMB/CIFS is more common for Windows environments but works fine.

Part 1: Configure NAS (SMB/CIFS)

  1. Enable SMB/CIFS Service: On your NAS, ensure the SMB/CIFS service is enabled.
  2. Create Share: Create the folder/share you want to export (e.g., myshare).
  3. User/Permissions: Create a dedicated user on the NAS (e.g., pve_user) with read/write permissions to this specific share. This is crucial for mounting from Linux. Set a strong password.

Part 2: Mount on Proxmox Host (SMB/CIFS)

  1. Install CIFS Utilities:
apt update
apt install cifs-utils
  1. Create Mount Point on PVE:
mkdir -p /mnt/nas/myshare
  1. Store Credentials (Securely): It’s best not to put credentials directly in /etc/fstab. Create a credentials file:
mkdir -p /etc/samba
nano /etc/samba/credentials_myshare

Add these two lines:

username=pve_user
password=YourStrongPasswordHere

Secure the file:

chmod 600 /etc/samba/credentials_myshare
  1. Test Mount:
mount -t cifs //192.168.1.100/myshare /mnt/nas/myshare -o credentials=/etc/samba/credentials_myshare,uid=0,gid=0,forceuid,forcegid,file_mode=0644,dir_mode=0755
  • uid, gid, forceuid, forcegid: These options are crucial for controlling how permissions are mapped from SMB to Linux. uid=0, gid=0 (root) is a common choice for initial setup, but you might want to map to a specific user/group ID on your Proxmox host that also exists in your LXC.
  • file_mode, dir_mode: Sets default permissions for new files/directories created via the mount.
  • Guest access: If your NAS allows guest access, you might use guest or username=guest,password= instead of a credentials file.
  1. Verify Mount:
df -h /mnt/nas/myshare
ls -l /mnt/nas/myshare
  1. Make Mount Permanent (Add to /etc/fstab):
echo "//192.168.1.100/myshare /mnt/nas/myshare cifs credentials=/etc/samba/credentials_myshare,uid=0,gid=0,forceuid,forcegid,file_mode=0644,dir_mode=0755,_netdev 0 0" >> /etc/fstab
  • Run mount -a to test.

Part 3: Bind Mount into LXC

Once the NAS share is successfully mounted on your PVE host, you can bind mount it into your LXC.

  1. Identify LXC ID: Get the ID of your LXC (e.g., 101). You can find this in the Proxmox web UI.

  2. Run the following command:

pct set 101 -mp0 /host/dir,mp=/container/mount/point

To unmount simply run

pct set 101
  1. Restart LXC: For the bind mount to take effect, you must restart the LXC.
pct stop 101
pct start 101

Or through the Proxmox web UI.

  1. Verify Inside LXC: After the LXC restarts, access its console again and verify the mount:
df -h /media/nas_data
ls -l /media/nas_data

You should now see the contents of your NAS share within the LXC at /media/nas_data.

Note

Don’t forget to update permissions on your NAS side otherwise the LXC still won’t be able to access files.