Proxmox: Mount CIFS share in LXC container
To mount a CIFS share in a Proxmox LXC container, we also need a privileged container with the activated feature as described in the prerequisites.
Caution!
Privileged LXC containers harbor a not inconsiderable risk. Read more here:
Privileged containers run under the root user of the host system. This means that the root user within the container also has root rights on the host.
Due to the fact that root rights of the container can be extended to the host system, privileged containers pose a higher security risk. A security problem in the container could potentially jeopardize the entire host system.
CIFS (Common Internet File System) is a network file system protocol that was developed to share files, printers and serial ports across a network. It was developed by Microsoft as an extension of the original SMB (Server Message Block) protocol. CIFS allows users to read and write files on remote servers as if they were on the local computer.
CIFS is often used in heterogeneous networks where Windows and Unix/Linux systems need to work together.
APT: Install CIFS Utils
To mount a CIFS share in an LXC container, we also have to install the corresponding package.
First we update the package sources and the installed packages themselves:
sudo apt-get update && apt-get upgrade -y
Then we install the cifs-utils:
sudo apt-get install cifs-utils
We confirm the query with Yes (Y)
CIFS Share Mount
You can then mount a CIFS share in the Proxmox LXC container. You can use the mount command for this. Drives mounted using the command are only available until the next reboot. How to mount drives automatically using fstab is described below.
Like the NFS share, the CIFS share can also be mounted using the mount command:
sudo mount -t cifs //192.168.1.3/volume1/Cybertalk /mnt/Cybertalk -o username=Tobias,password=secret
One difference to NFS is immediately apparent: Access data in the form of a user name and password are required. These are the data used to log on to the server.
This is the syntax for the mount cifs command:
sudo mount -t cifs //servername/sharename /mnt/mountpoint -o username=yourusername,password=yourpassword,domain=example,uid=1000,gid=1000
The domain uid and gid option are only required in certain cases.
Before we can mount our CIFS share on the server 192.168.1.2/volume1/Cybertalk, we must first create the local mount point (folder):
mkdir /mnt/Cybertalk
Then we can mount our CIFS share:
sudo mount -t cifs //192.168.1.3/volume1/Cybertalk /mnt/Cybertalk -o username=Tobias,password=secret
If we now navigate to our mount point, we can already see the data and folders on the share, if available:
cd /mnt/Cybertalk
ls -a
All files and folders are displayed with ls -a.
Automatically mount CIFS share
The following also applies to the CIFS mount: With the command, the share is only mounted until the next reboot of the device. So if we want the CIFS share to always be mounted automatically, we have to make an entry in the fstab file.
The fstab file can be found under /etc/fstab and can be opened with an editor of your choice.
nano /etc/fstab
This is what it looks like:
![](https://cybertalk.io/wp-content/uploads/2024/07/nfs-mount-fstab-default-1024x382.png)
However, you cannot simply copy the previously created mount command into the fstab file; the syntax is slightly different here:
//device/sharename /mnt/mountpoint cifs credentials=/home/Tobias/.smbcredentials,uid=1000,gid=1000,vers=3.0 0 0
Our customized entry looks like this:
//192.168.1.2/volume1/Cybertalk /mnt/Cybertalk cifs credentials=/home/Tobias/.smbcredentials,vers=3.0 0 0
Here the credentials are stored in a separate file. This is done to protect the access data from unauthorized access.
We create a file for this purpose. This can be located in the home directory, for example:
nano .smbcredentials
The dot in front of the file name ensures that the file is hidden. We write the following entries in this file:
username=username
password=secret
domain=workgroup
Please note that only one entry per line is written to the fstab file. We now copy our entry into the fstab file under the comment marked with # and save the file with: CTRL + X -> Save Buffer -> Y -> Enter
Then the rights must be set so that only we ourselves can view this file. To do this, we execute the following command:
chmod 600 ~/.smbcredentials
Even if we have saved the file, the CIFS share is not yet mounted. To execute the fstab manually, we need the two commands:
sudo systemctl daemon-reload
sudo mount -a
Now the CIFS share is mounted in the Proxmox LXC container and available.