Debian 使用 systemd 自动挂载 Samba

本文地址:blog.lucien.ink/archives/540

写成了一键脚本,直接执行即可。

需要注意的是,挂载的路径和 systemd service 的名字要对应上,比如挂载的路径为 /mnt/nas 那 service 的文件名应为 mnt-nas.service

shell 复制代码
#!/usr/bin/env bash

SERVER="nas.local"
USERNAME="foo"
PASSWORD="bar"

apt install cifs-utils -y

groupadd -g 17510 nas

cat <<EOF >> /etc/systemd/system/dns-ready.service
[Unit]
Description=Wait for DNS to come up using 'host'
After=nss-lookup.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c "until host ${SERVER}; do sleep 1; done"

[Install]
WantedBy=multi-user.target
EOF

cat <<EOF >> /etc/systemd/system/mnt-nas.mount
[Unit]
Description=Mount NAS
Requires=network-online.target
After=network-online.target dns-ready.service

[Mount]
What=//${SERVER}/Data
Where=/mnt/nas
Type=cifs
Options=username=${USERNAME},password=${PASSWORD},dir_mode=0775,gid=nas,rw,file_mode=0664

[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload

systemctl start dns-ready.service
systemctl enable dns-ready.service

systemctl start mnt-nas.mount
systemctl enable mnt-nas.mount
相关推荐
渣渣盟12 小时前
Zookeeper分布式协调服务全解析
分布式·zookeeper·debian
L.Ru17 小时前
在MobaXterm中使用debian以及常见的命令
运维·网络·debian·信息与通信
linchare8 天前
linux debian上只装mysql的客户端步骤
linux·mysql·debian
凌寒119 天前
Linux(Debian)安装、卸载 MySQL
linux·运维·mysql·debian
今晚务必早点睡12 天前
云服务器公共镜像怎么选?一文带你看懂 Ubuntu、Debian、CentOS、Rocky 的最佳使用场景
服务器·ubuntu·debian
achi01014 天前
Ubuntu 24.04 一站式 Flask 生产部署:pyenv + PyCharm + Gunicorn + Nginx + systemd
pycharm·flask·systemd·gunicorn·pyenv·ubuntu 24.04·生产部署
wdfk_prog16 天前
Xshell终端连接Ubuntu/Debian无颜色的解决方案
java·ubuntu·debian
nandezizai_ddc17 天前
Debian 初始设置
运维·debian
努力成为一个程序猿.19 天前
Clickhouse数据副本和分片
运维·clickhouse·debian
南林yan23 天前
Debian系统的多内核共存
linux·debian·linux内核