User Tools

Site Tools


proxmox:guests_vms_and_containers:mount_a_network_share_in_a_linux_container

Proxmox - Guests (VMs and Containers) - Mount a Network Share in a Linux Container

How to mount a Network Share inside an Unprivileged (or Privileged) Linux Container (LXC) in Proxmox.

NOTE: This is non-trivial because Unprivileged LXC Containers do not have the privileges available to directly mount network locations.

The work around involves mounting the network share on the Container Host and then binding the mount folder on the host to a folder in the Container.

  • Unprivileged containers will only be able to read from Network Shares.
  • Privileged containers will be able to read from and write to Network Shares.
  • You cannot modify the Privilege of a container once it is made.
    • If can restore a container in either Privileged or Unprivileged mode, converting a container from Unprivileged to Privileged should be fairly straight forward.
    • The reverse isn't always true because there are files on a Privileged container that cannot exist on an Unprivileged container.

Create the mount point directory

Log into the Container as root.

mkdir /mnt/extfolder

Log out of the container and stop the container

Use the GUI.


Log into the Host Machine as root

NOTE: If necessary, create a credentials file with the username and password for the network share.

  • Remember to secure the file!

Add the following lines to /root/.credentials/my-credentials.

/root/.credentials/my-credentials
username=theusername
password=thepassword
workgroup=theworkgroup

Save your changes.


Set file permissions

chmod 600 /root/.credentials/my-credentials

Create the target mount folder

mkdir /mnt/netfolder

Edit fstab

Add a line to your fstab file to mount the network share:

Add the following line to the bottom:

/etc/fstab
//net/path/to/netfolder /mnt/netfolder cifs user,credentials=/root/.credentials/my-credentials,iocharset=utf8,noperm 0 0

Reload fstab

mount -a

NOTE: The network share content should be visible at /mnt/netfolder.


Bind the host directory to the container directory in the container config

Edit /etc/pve/nodes/hostname/lxc/mycontainer.conf.

Add the following line after memory and before net0.

/etc/pve/nodes/hostname/lxc/mycontainer.conf
mp0: /mnt/netfolder,mp=/mnt/extfolder

Restart the client

NOTE: The network share should be accessible at /mnt/extfolder


References

proxmox/guests_vms_and_containers/mount_a_network_share_in_a_linux_container.txt · Last modified: 2021/07/05 09:19 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki