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

From steamWiki
Jump to: navigation, search
 
Line 3: Line 3:
  
 
#Log into your Container as root
 
#Log into your Container as root
##Create the a mount point directory
+
##Create the a mount point directory with <pre>mkdir /mnt/extfolder</pre>
##*''mkdir /mnt/extfolder''
 
 
##Log out of the container and stop the container
 
##Log out of the container and stop the container
 
#Log into your Host Machine as root
 
#Log into your Host Machine as root
##if necessary, create a credentials file with the username and password for your network share.  Then secure the file.
+
##if necessary, create a credentials file with the username and password for your network share.  Then secure the file <pre>nano /root/.credentials/my-credentials</pre>
##*''nano /root/.credentials/my-credentials''
+
###add the following lines <pre>username=theusername&#10;password=thepassword&#10;workgroup=theworkgroup</pre>
###add the following lines
+
###Exit nano and save your changes by hitting '''Ctrl-X''' and then '''Y'''
##*''username=theusername''
+
##run <pre>chmod 600 /root/.credentials/my-credentials</pre>
##*''password=thepassword''
+
##create the target mount folder by running <pre>mkdir /mnt/netfolder</pre>
##*''workgroup=theworkgroup''
+
##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>
###Exit nano and save your changes
+
##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>
##*''Ctrl-X''
+
#Restart the client and the network share should be accessible at '''/mnt/extfolder'''
##*''Y''
 
##*''chmod 600''
 
##create the target mount folder
 
##*''mkdir /mnt/netfolder''
 
##Add a line to your fstab file to mount the network share
 
##*''nano /etc/fstab''
 
###add the following line
 
##*''//net/path/to/netfolder /mnt/netfolder cifs user,credentials=/root/.credentials/my-credentials,iocharset=utf8,noperm 0 0''
 
##Bind the host directory to the container directory in the container config
 
#*''nano /etc/pve/nodes/hostname/lxc/mycontainer.conf''
 
##add the follow line after ''memory'' and before ''net0''
 
#*''mp0: /mnt/netfolder,mp=/mnt/extfolder''
 
#Restart the client and the network share should be accessible at ''/mnt/extfolder''
 
  
 
[[Category: Linux]]
 
[[Category: Linux]]

Latest revision as of 12:15, 9 July 2019

This article describes how to mount a Network Share inside a Linux Container (LXC). This is non-trivial because 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.


  1. Log into your Container as root
    1. Create the a 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
    2. run
      chmod 600 /root/.credentials/my-credentials
    3. create the target mount folder by running
      mkdir /mnt/netfolder
    4. 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
    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