mntcs (Mount Centralized System) is a tool that allows you to mange filesystem mounts in a centralized and easy way. It was created to to answer the following use case: Manage filesystem mounts (using cifs) in several ubuntu servers using a single configuration file stored in a shared folder location allowing users without previous knowledge on Linux mounts to use the system.
mntcs uses a very simple configuration file to determine which mounts have to be configured.
The "mntcs.conf" file contain a set of source and target paths for each mount like shown below:
//10.10.10.10:/source/path /target/path/one linuxuser1,linuxuser2,linuxuser3 /path/to/credentials/file
//servername:/source/path /target/path/two linuxuser1,linuxuser2 /path/to/credentials/file
//dns:/source/path /target/path/three linuxuser2,linuxuser3 /path/to/credentials/file
Then the mntcs binary read the file and configure the specified mounts (it should be configured to run as a service in order to run on server boots)
To grant local permissions for specific users, mntcs create a group for each mount and add the relevant users to it. Then it allow access to the mount only for the group members.
Note that a credential file is used for the mount operation to ensure that only root is able to access and configure the mount permissions
The mntcs utility is composed of the following:
- /etc/mntcs/mntcs.conf: configuration file
- /bin/mntcs: binary
- /var/log/mntcs.log: logs
- /lib/systemd/system/mntcs.service: service file
mntcs allows you to manage the mounts centrally as shown in the image below:
can be used on a single server although in that case it would be better to use tools like fstab. However, its true use is to manage the mounts for several servers centrally as shown below.
To achieve this, the "mntcs.conf" file should be mounted into the server and should be managed in a central location.
Then mntcs will be able to read the configuration file and set the required mounts (including the permissions for each user).
In addition, mntcs should be configured as a service to run it at boot (and not only manually)
Note that mntcs can be used on a single server as well but in that case probably would be better to use tools like fstab
- The purpose of mntcs is not to replace fstab, it was developed to solve a specific use case (without affecting the regular fstab usage)
- At the moment mntcs only uses the "mount" command defaults (does not support specifying flags)
- Currently mntcs doesn't do any validation to the configuration file
- mntcs was developed and tested for ubuntu only
- Note that mntcs is currently being used in some production environments
- mntcs was designed to perform the mounts using cifs only
- mntcs require the "cifs-utils" package, to install it you can use the command below:
sudo apt update
sudo apt install -y cifs-utils
- Create the credentials file which will be used to perform the mounts (you can create multiples files if required)
sudo touch /etc/mntcs.cred
- Configure the credentials file with the following details
vi /etc/mntcs.cred
username=MyUser
password=MyPassword
domain=mydomain.com
- Set the file readable only for root
sudo chown root: /etc/mntcs.cred
sudo chmod 600 /etc/mntcs.cred
- Create the configuration file in a shared storage location, for example:
# config file location
\\netapp\mydirectory\mntcs.conf
# example config file
//100.1.1.0/myshareddirectory/myfoldertomount1 /mnt/mount1 linuxuser1,linuxuser2 /etc/mntcs.cred
//100.1.1.0/myshareddirectory/myfoldertomount2 /mnt/mount2 linuxuser2 /etc/mntcs.cred
//100.1.1.0/myshareddirectory/myfoldertomount3 /mnt/mount3 linuxuser1,linuxuser3 /etc/mntcs.cred
- Create the directory to mount the configuration file
sudo mkdir /etc/mntcs
- Mount the configuration file using "fstab" by adding the following line to the "/etc/fstab" file:
sudo vi /etc/fstab
# NOTE: CHANGE THE SOURCE PATH BELOW WITH THE PATH WHERE YOUR CONFIG FILE IS STORED
//100.1.1.0/myshareddirectory/myfoldertomount1 /etc/mntcs cifs credentials=/etc/mntcs.cred 0 0
- Trigger the mount and ensure that it success
sudo mount /etc/mntcs
ls /etc/mntcs
cat /etc/mntcs/mntcs.conf
- Download the mntcs binary
wget https://github.com/leonjalfon1/mntcs/releases/download/v1.0/mntcs
- Grant execution permissions for the binary
sudo chmod +x ./mntcs
- Move the mntcs binary to the "/bin" directory
sudo mv ./mntcs.sh /bin/mntcs
- Ensure that the mntcs binary is located in the bin directory
ls /bin | grep mntcs
- Ensure that the binary is accessible by running
mntcs --help
- Use the command below to retrieve the service name of the generated mount used to mount the mntcs configuration (you should get: etc-mntcs.mount)
sudo systemctl list-units --type=mount | grep mntcs
- Create the service file with the following configuration
sudo vi /lib/systemd/system/mntcs.service
[Unit]
Description=Mount Centralized System (mntcs)
## Add a mount dependency as below if you use fstab to mount the configuration into the server
## Use the command "systemctl list-units --type=mount" to get the generated mount service name
After=etc-mntcs.mount
[Service]
ExecStart=/bin/mntcs
[Install]
WantedBy=multi-user.target
- Test your mounts manually
sudo mntcs
- Enable the service to run automatically on boot
sudo systemctl enable mntcs