{"id":3555,"date":"2016-03-18T11:17:17","date_gmt":"2016-03-18T10:17:17","guid":{"rendered":"http:\/\/michlstechblog.info\/blog\/?p=3555"},"modified":"2018-02-23T07:33:37","modified_gmt":"2018-02-23T06:33:37","slug":"systemd-mount-examples-for-cifs-shares","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/systemd-mount-examples-for-cifs-shares\/","title":{"rendered":"Systemd: (Auto-) Mount cifs shares"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_3555 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_3555')){$('.twoclick_social_bookmarks_post_3555').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Systemd%3A%20%28Auto-%29%20Mount%20cifs%20shares\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Asystemd%20can%20mount%20cifs%20filesystems%20at%20boot%20or%20on%20demand%20like%20autofs.%0D%0A%0D%0AFirst%20cifs%20mount%20at%20boot%20time.%20Determine%20the%20share%20and%20the%20mount%20point.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/systemd-mount-examples-for-cifs-shares\\\/\",\"post_id\":3555,\"post_title_referrer_track\":\"Systemd%3A+%28Auto-%29+Mount+cifs+shares\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>systemd can mount cifs filesystems at boot or on demand like autofs.<\/p>\n<p>First cifs mount at boot time. Determine the share and the mount point.<br \/>\n<!--more--><br \/>\nFor example:<br \/>\n<code><br \/>\nShare : \\\\192.168.56.1\\mp$<br \/>\nLocal mountpoint: \/mnt\/mp<br \/>\nUser : yourCifsUser<br \/>\nWindows Domain : YourDomain (this is optional, also in the unit file and only necessary if you use a Domain Login)<br \/>\n<\/code><br \/>\n<!--https:\/\/fedoraproject.org\/wiki\/How_to_debug_Systemd_problems--><br \/>\nCreate the mount point<br \/>\n<code><br \/>\nroot@debdev:~# mkdir \/mnt\/mp<br \/>\n<\/code><br \/>\nCreate the systemd definition file. The Folder for custom systemd unit files is \/etc\/systemd\/system.<\/p>\n<p>Create a new file mnt-mp.mount in the diretory \/etc\/systemd\/system. The filename <strong>must <\/strong>contain the mountpointname where the slashes are replaced with &#8220;minus&#8221;. Filename for \/mnt\/mp =&gt; mnt-mp.mount<\/p>\n<p>If this does not match you will get an error like:<br \/>\n<code><br \/>\nroot@debdev:~# journalctl |grep storage<br \/>\nstorage-cifs.mount's Where= setting doesn't match unit name. Refusing.<br \/>\n<\/code><\/p>\n<p>This is a working unit<\/p>\n<pre><code>\r\n[Unit]\r\n  Description=cifs mount script\r\n  Requires=network-online.target\r\n  After=network-online.service\r\n\r\n[Mount]\r\n  What=\/\/192.168.56.1\/mp$\r\n  Where=\/mnt\/mp\r\n  Options=username=yourCifsUser,password=Secretpassword,workgroup=YourDomain,rw\r\n  Type=cifs\r\n\r\n[Install]\r\n  WantedBy=multi-user.target\r\n<\/code><\/pre>\n<p>Enable the previous defined config and check if error occurs.<br \/>\n<code><br \/>\nsystemctl enable mnt-mp.mount<br \/>\nsystemctl status mnt-mp.mount<br \/>\n<\/code><\/p>\n<p><strong>Update:<\/strong> 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). <\/p>\n<p>To mount such shares you have to explict set the SMB protocol version to 1 by add the option <strong>vers=1.0<\/strong> to the Options line in the mount unit. For example:<br \/>\n<code>Options=username=yourCifsUser,password=Secretpassword,workgroup=YourDomain,rw,vers=1.0<\/code><\/p>\n<p>To mount and unmount your share start or stop the unit.<br \/>\n<code><br \/>\nroot@debdev:~# systemctl start mnt-mp.mount<br \/>\nroot@debdev:~# mount|grep 192<br \/>\n\/\/192.168.56.1\/mp$ on \/mnt\/mp type cifs (rw,relatime,vers=1.0,cache=strict,username=yourCifsUser,.....<br \/>\nroot@debdev:~# systemctl stop mnt-mp.mount<br \/>\n<\/code><\/p>\n<p>If you make changes to your unit file while its still active, call<br \/>\n<code><br \/>\nsystemctl daemon-reload<br \/>\n<\/code><br \/>\nto reload it.<\/p>\n<p>It&#8217;s also possible to mount your share just on demand. Like an automounter.<\/p>\n<p>Define your mount unit mnt-mp.mount like above but do not enable it via systemctl.<\/p>\n<p>Create an automount unit \/etc\/systemd\/system\/mnt-mp.automount. The automount unit starts the mount unit (mnt-mp.mount) on demand.<\/p>\n<pre><code>\r\n[Unit]\r\n  Description=cifs mount script\r\n  Requires=network-online.target\r\n  After=network-online.service\r\n\r\n[Automount]\r\n  Where=\/mnt\/mp\r\n  TimeoutIdleSec=10\r\n\r\n[Install]\r\n  WantedBy=multi-user.target\r\n<\/code><\/pre>\n<p>Enable the automount unit<br \/>\n<code><br \/>\nsystemctl enable mnt-mp.automount<br \/>\n<\/code><br \/>\nThis will create an autofs entry in the mount tab<br \/>\n<code><br \/>\nroot@debdev:~# mount|grep systemd<br \/>\nsystemd-1 on \/mnt\/mp type autofs (rw,relatime,fd=27,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)<br \/>\n<\/code><br \/>\n<code><br \/>\nroot@debdev:~# systemctl status mnt-mp.automount<br \/>\n\u25cf mnt-mp.automount - cifs mount script<br \/>\nLoaded: loaded (\/etc\/systemd\/system\/mnt-mp.automount; enabled)<br \/>\nActive: active (running) since Fr 2016-03-18 12:21:37 CET; 9min ago<br \/>\nWhere: \/mnt\/mp<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>and browse to the mountpoint and see what happens:<br \/>\n<code><br \/>\nroot@debdev:~ # ls -l \/mnt\/mp\/Andreas\/Adoring_Human_Flesh\/<br \/>\n-rwxr-xr-x 1 root root 9361449 Mai 2 2015 ZOOM0041.MP3<br \/>\n-rwxr-xr-x 1 root root 6881906 Mai 2 2015 ZOOM0045.MP3<br \/>\n-rwxr-xr-x 1 root root 5959680 Mai 2 2015 ZOOM0046.MP3<br \/>\n-rwxr-xr-x 1 root root 5880058 Mai 2 2015 ZOOM0051.MP3<br \/>\n<\/code><\/p>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, systemd can mount cifs filesystems at boot or on demand like autofs. First cifs mount at boot time. Determine the share and the mount point.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[296,820,224,819,818],"class_list":["post-3555","post","type-post","status-publish","format-standard","hentry","category-linux","tag-automount","tag-automounter","tag-linux-2","tag-mount-cifs","tag-systemd"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/3555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=3555"}],"version-history":[{"count":23,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/3555\/revisions"}],"predecessor-version":[{"id":8542,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/3555\/revisions\/8542"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=3555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=3555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=3555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}