SMB mount unit

Sample MOUNT unit for SMB share


It is also possible to store the username and password in a safe location readable only by root.

Replace the $VARIABLES with the values for your system

The package smbclient is enough.

NOTE: According to the archlinux wiki the uid and gid can cause I/O errors.

Warning: Using uid and/or gid as mount options may cause I/O errors, it is recommended to set/check correct File permissions and attributes instead. - https://wiki.archlinux.org/index.php/Samba#Manual_mounting

More information on Samba can be found on the archlinux wiki

SMB credentials

Create a file /etc/smb.cred or in user's home with content

user=$SMBUSER
password=$SMBPASS
workgroup=$WORKGROUP

Make the file readonly to user

sudo chmod 600 /etc/smb.cred

SMB version

If needed you add a version to the options string e.g. vers=NT1

mount unit

Name the file according to $YOUR_MOUNT_PATH.mount

[Unit]
Description=NAS SMB video share

[Mount]
What=//$YOUR_SERVER/$YOUR_SHARE
Where=$YOUR_MOUNT_PATH
Type=cifs
Options=_netdev,iocharset=utf8,rw,file_mode=0777,dir_mode=0777,credentials=/etc/smb.cred,vers=NT1
TimeoutSec=30

[Install]
WantedBy=multi-user.target

automount unit

Name the file according to $YOUR_MOUNT_PATH.automount

[Unit]
Description=Automount video share using SMB
ConditionPathExists=$YOUR_MOUNT_PATH

[Automount]
Where=$YOUR_MOUNT_PATH
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target