Oracle Linux - How to mount a SMB/CIFS Share using SYSTEMD
in Linux
APPLIES TO:
Linux OS – Version Oracle Linux 7.0 to Oracle Linux 9.0 [Release OL7 to OL9]
Linux x86_64 on Oracle Public Cloud
GOAL:
Mount a SMB/CIFS share using SYSTEMD as it will give more flexible configurations. It enables you to stage dependencies when mounting if needed.
SOLUTION:
This HOWTO assumes a SMB/CIFS Server is already configured and Firewall rules allow connections among Server and Clients.
[root@alejanarol7 ~]$ rpmquery cifs-utils cifs-utils-6.2-10.el7.x86_64 [root@alejanarol7 ~]# smbclient -L 10.0.100.123 -N Anonymous login successful Sharename Type Comment --------- ---- ------- MyShare Disk My Shared Folder IPC$ IPC IPC Service (Samba 4.17.5) [root@alejanarol7 ~]# smbclient //10.0.100.123/MyShare -U nobody -L Enter SAMBA\nobody's password: Try "help" to get a list of possible commands. smb: \> ls . D 0 Thu Jun 29 02:51:16 2023 .. D 0 Thu Jun 29 02:23:46 2023 mybigfile.out A 10485760000 Thu Jun 29 02:54:11 2023 37177616 blocks of size 1024. 6190764 blocks available smb: \> quit [root@alejanarol7 ~]$ cat > /etc/mysmb.cred << EOF user=nobody password=nobody EOF [root@alejanarol7 ~]$ chmod 600 /etc/mysmb.cred [root@alejanarol7 ~]$cat > /etc/systemd/system/mySMB.mount << EOF [Unit] Description=My SMB Share Documentation=https://www.homeluna.net After=network.target [Mount] What=//10.0.100.123/MyShare Where=/mySMB Type=cifs Options=credentials=/etc/mysmb.cred,vers=3.1.1 TimeoutSec=30 [Install] WantedBy=multi-user.target EOF [root@alejanarol7 ~]# systemctl daemon-reload && systemctl enable mySMB.mount Created symlink from /etc/systemd/system/multi-user.target.wants/mySMB.mount to /etc/systemd/system/mySMB.mount. [root@alejanarol7 ~]# systemctl restart mySMB.mount [opc@alejanarol7 ~]$ systemctl status mySMB.mount ● mySMB.mount - My SMB Share Loaded: loaded (/etc/systemd/system/mySMB.mount;
Tagged:
0