The Problem
CIFS shared file system is not mounted even after system reboot in CentOS/RHEL 7. If manually execute the “mount -a” command after the system is rebooted, the CIFS file system is normally mounted
fstab entry:
# cat /etc/fstab //192.168.0.10/Oracle /backup/oracle cifs _netdev,noexec,nosuid,vers=3.0,uid=1001,gid=1002,credentials=/root/backup_creds 0 0
demsg:
[ 27.052981] Key type cifs.idmap registered [ 33.053711] CIFS VFS: Error connecting to socket. Aborting operation. [ 33.054048] CIFS VFS: cifs_mount failed w/return code = -113
/var/log/messages:
Nov 21 15:09:29 ***** kernel: CIFS VFS: Error connecting to socket. Aborting operation. Nov 21 15:09:29 ***** kernel: CIFS VFS: cifs_mount failed w/return code = -113 Nov 21 15:09:29 ***** mount: Unable to find suitable address. Nov 21 15:09:29 ***** systemd: backup-oracle.mount mount process exited, code=exited status=32 Nov 21 15:09:29 ***** systemd: Failed to mount /backup/oracle. Nov 21 15:09:29 ***** systemd: Dependency failed for Remote File Systems. Nov 21 15:09:29 ***** systemd: Job remote-fs.target/start failed with result 'dependency'. Nov 21 15:09:29 ***** systemd: Unit backup-oracle.mount entered failed state.
The Solution
Mount units referring to local and network file systems are distinguished by their file system type specification. In some cases, this is not sufficient (for example network block device based mounts, such as iSCSI), in which case _netdev may be added to the mount option string of the unit, which forces systemd to consider the mount unit a network mount.
Additionally, systemd supports explicit order dependencies between mount entries and other units. There are 2 ways this issue can be resolved:
1. adding in x-systemd.after=network-online.target in /etc/fstab to the mount options:
//192.168.0.10/Oracle /backup/oracle cifs _netdev,x-systemd.after=network-online.target,noexec,nosuid,vers=3.0,uid=1001,gid=1002,credentials=/root/backup_creds 0 0
2. create custom systemd unit file in /etc/systemd/system with file format samba.service[Unit]:
# vi /etc/systemd/system Description=CIFS Mount Requires=network-online.target After=network-online.service Before=samba.service [Mount] What=//xxx.xxx.xxx.xxx/path/[mountpoint] Where=/mnt/path Options=username=yourusername,pass=yourpassword Type=cifs [Install] WantedBy=multi-user.target