This guide will show you how to use systemd to mount your CIFS share from your Samba server.


.

1) Install cifs-utils

# aptitude install cifs-utils

The following NEW packages will be installed:
cifs-utils keyutils{a} python-ldb{a} python-ntdb{a} python-samba{a} python-tdb{a} samba-common{a} samba-common-bin{a}

2) Create a credentials file in your home directory (/home/username/.cifs-credentials)

username=username
password=password
domain=WORKGROUP

3) Create home-username-share.mount in /lib/systemd/system

[Mount]
What=//server/share
Where=/home/username/share
Type=cifs
Options=noauto,_netdev,x-systemd.automount,cache=none,credentials=/home/username/.cifs-credentials
SloppyOptions=on
DirectoryMode=0755
TimeoutSec=0

4) Create home-username-share.automount in /lib/systemd/system

[Unit]
DefaultDependencies=no
After=remote-fs-pre.target
Wants=remote-fs-pre.target
Conflicts=umount.target
Before=umount.target

[Automount]
Where=/home/username/share
DirectoryMode=0755
TimeoutIdleSec=0

[Install]
WantedBy=remote-fs.target

5) Activate the new systemd service

# systemctl enable /lib/systemd/system/home-username-share.automount

Created symlink from /etc/systemd/system/remote-fs.target.wants/home-username-share.automount to /lib/systemd/system/home-username-share.automount.

6) Start the home-username-share.automount service

# systemctl start home-username-share.automount

systemd log at the time of the mount:

elo 24 14:23:02 pc systemd[1]: Got automount request for /home/username/share, triggered by 1735 (bash)
elo 24 14:23:02 pc systemd[1]: Mounting /home/username/share...
elo 24 14:23:02 pc kernel: FS-Cache: Loaded
elo 24 14:23:02 pc kernel: FS-Cache: Netfs 'cifs' registered for caching
elo 24 14:23:02 pc kernel: Key type cifs.spnego registered
elo 24 14:23:02 pc kernel: Key type cifs.idmap registered
elo 24 14:23:03 pc systemd[1]: Mounted /home/username/share.

To show systemd log (think tail -f):

# journalctl -f

To see systemd log entries with explanations and in a pager:

# journalctl -xe

To see service status:

# systemctl status home-username-share.automount

Advertisements