Difference between revisions of "How to mount a Network Share in a Linux Container under Proxmox"

From steamWiki
Jump to: navigation, search
Line 14: Line 14:
 
##create the target mount folder by running <pre>mkdir /mnt/netfolder</pre>
 
##create the target mount folder by running <pre>mkdir /mnt/netfolder</pre>
 
##Add a line to your fstab file to mount the network share by running <pre>nano /etc/fstab</pre> and adding the following line to the bottom <pre>//net/path/to/netfolder /mnt/netfolder cifs user,credentials=/root/.credentials/my-credentials,iocharset=utf8,noperm 0 0</pre>
 
##Add a line to your fstab file to mount the network share by running <pre>nano /etc/fstab</pre> and adding the following line to the bottom <pre>//net/path/to/netfolder /mnt/netfolder cifs user,credentials=/root/.credentials/my-credentials,iocharset=utf8,noperm 0 0</pre>
##Reload the fstab file by running <pre>mount -a</pre>Now you should be able to see your network share's content at ''/mnt/netfolder''
+
##Reload the fstab file by running <pre>mount -a</pre>Now you should be able to see your network share's content on the Host Machine at ''/mnt/netfolder''
 
##Bind the host directory to the container directory in the container config by running <pre>nano /etc/pve/nodes/hostname/lxc/mycontainer.conf</pre> and adding the following line after '''memory''' and before '''net0''' <pre>mp0: /mnt/netfolder,mp=/mnt/extfolder</pre>
 
##Bind the host directory to the container directory in the container config by running <pre>nano /etc/pve/nodes/hostname/lxc/mycontainer.conf</pre> and adding the following line after '''memory''' and before '''net0''' <pre>mp0: /mnt/netfolder,mp=/mnt/extfolder</pre>
 
#Restart the client and the network share should be accessible at '''/mnt/extfolder'''
 
#Restart the client and the network share should be accessible at '''/mnt/extfolder'''
  
 
[[Category: Linux]]
 
[[Category: Linux]]

Revision as of 10:34, 22 July 2022

This article describes how to mount a Network Share inside an Unprivileged (or Privileged) Linux Container (LXC) in Proxmox. 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.

Note that 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. You 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. This thread describes some of these issues.


  1. Log into your Container as root
    1. Create the mount point directory with
      mkdir /mnt/extfolder
    2. Log out of the container and stop the container
  2. Log into your Host Machine as root
    1. if necessary, create a credentials file with the username and password for your network share. Then secure the file
      nano /root/.credentials/my-credentials
      1. add the following lines
        username=theusername
        password=thepassword
        workgroup=theworkgroup
      2. Exit nano and save your changes by hitting Ctrl-X and then Y
      3. run
        chmod 600 /root/.credentials/my-credentials
    2. create the target mount folder by running
      mkdir /mnt/netfolder
    3. Add a line to your fstab file to mount the network share by running
      nano /etc/fstab
      and adding the following line to the bottom
      //net/path/to/netfolder /mnt/netfolder cifs user,credentials=/root/.credentials/my-credentials,iocharset=utf8,noperm 0 0
    4. Reload the fstab file by running
      mount -a
      Now you should be able to see your network share's content on the Host Machine at /mnt/netfolder
    5. Bind the host directory to the container directory in the container config by running
      nano /etc/pve/nodes/hostname/lxc/mycontainer.conf
      and adding the following line after memory and before net0
      mp0: /mnt/netfolder,mp=/mnt/extfolder
  3. Restart the client and the network share should be accessible at /mnt/extfolder