systemd

systemd puede montar filesystems al arrancar el sistema o bajo demanda como autofs.

First cifs mount at boot time. Determine the share and the mount point.

For example:

Share : \\192.168.56.1\mp$
Local mountpoint: /mnt/mp
User : yourCifsUser
Windows Domain : YourDomain (this is optional, also in the unit file and only necessary if you use a Domain Login)

Create the mount point

root@debdev:~# mkdir /mnt/mp

Create the systemd definition file. The Folder for custom systemd unit files is /etc/systemd/system.

Create a new file mnt-mp.mount in the diretory /etc/systemd/system. The filename must contain the mountpointname where the slashes are replaced with “minus”. Filename for /mnt/mpmnt-mp.mount

If this does not match you will get an error like:

root@debdev:~# journalctl |grep storage
storage-cifs.mount's Where= setting doesn't match unit name. Refusing.

This is a working unit

[Unit]
  Description=cifs mount script
  Requires=network-online.target
  After=network-online.service

[Mount]
  What=//192.168.56.1/mp$
  Where=/mnt/mp
  Options=username=yourCifsUser,password=Secretpassword,workgroup=YourDomain,rw
  Type=cifs

[Install]
  WantedBy=multi-user.target

Enable the previous defined config and check if error occurs.

systemctl enable mnt-mp.mount
systemctl status mnt-mp.mount

Update: From security reasons newer Kernel releases does not allow to connect to CIFS Share that only supports SMB1. Error Message: No dialect specified on mount. Default has changed to a more secure dialect, SMB2.1 or later (e.g. SMB3), from CIFS (SMB1).

To mount such shares you have to explict set the SMB protocol version to 1 by add the option vers=1.0 to the Options line in the mount unit. For example:

Options=username=yourCifsUser,password=Secretpassword,workgroup=YourDomain,rw,vers=1.0

To mount and unmount your share start or stop the unit.

root@debdev:~# systemctl start mnt-mp.mount
root@debdev:~# mount|grep 192
//192.168.56.1/mp$ on /mnt/mp type cifs (rw,relatime,vers=1.0,cache=strict,username=yourCifsUser,.....
root@debdev:~# systemctl stop mnt-mp.mount

If you make changes to your unit file while its still active, call

systemctl daemon-reload

to reload it.

It’s also possible to mount your share just on demand. Like an automounter.

Define your mount unit mnt-mp.mount like above but do not enable it via systemctl.

Create an automount unit /etc/systemd/system/mnt-mp.automount. The automount unit starts the mount unit (mnt-mp.mount) on demand.

[Unit]
  Description=cifs mount script
  Requires=network-online.target
  After=network-online.service

[Automount]
  Where=/mnt/mp
  TimeoutIdleSec=10

[Install]
  WantedBy=multi-user.target

Enable the automount unit

systemctl enable mnt-mp.automount

This will create an autofs entry in the mount tab

root@debdev:~# mount|grep systemd
systemd-1 on /mnt/mp type autofs (rw,relatime,fd=27,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
root@debdev:~# systemctl status mnt-mp.automount
● mnt-mp.automount - cifs mount script
Loaded: loaded (/etc/systemd/system/mnt-mp.automount; enabled)
Active: active (running) since Fr 2016-03-18 12:21:37 CET; 9min ago
Where: /mnt/mp

and browse to the mountpoint and see what happens:

root@debdev:~ # ls -l /mnt/mp/Andreas/Adoring_Human_Flesh/
-rwxr-xr-x 1 root root 9361449 Mai 2 2015 ZOOM0041.MP3
-rwxr-xr-x 1 root root 6881906 Mai 2 2015 ZOOM0045.MP3
-rwxr-xr-x 1 root root 5959680 Mai 2 2015 ZOOM0046.MP3
-rwxr-xr-x 1 root root 5880058 Mai 2 2015 ZOOM0051.MP3