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
相关推荐
南林yan2 天前
Debian、Ubuntu、CentOS:Linux 三大发行版的核心区别
linux·ubuntu·debian·linux内核
st7802062 天前
Debian 13.1 下编译Openwrt24
运维·debian·openwrt
java_logo4 天前
Docker 部署 Debian 全流程教程
linux·运维·docker·容器·debian
柱子子子子4 天前
【邪修】linux (ubuntu/fedora/arch/debian) wifi hard blocked解决方法-AX210
linux·网络·ubuntu·debian
宇宙浪子6 天前
在 UOS(统信操作系统,基于 Debian/Ubuntu 体系)上编译 OpenCV 4.10.0
opencv·ubuntu·debian
不惑_9 天前
如何在 CentOS、Ubuntu 和 Debian 云服务器上安装 Python 3
ubuntu·centos·debian
kobe_OKOK_12 天前
windows 下载 pip包,debian离线安装
windows·debian·pip
ONE_SIX_MIX12 天前
Debian 的 网络管理器 被意外卸载,修复过程
服务器·网络·debian
迷路爸爸18012 天前
源码编译安装最新 tmux 教程(含 Debian/Ubuntu/CentOS/Arch/macOS 等系统)
linux·ubuntu·macos·centos·debian·tmux·archlinux
坐吃山猪13 天前
zk02-知识演进
运维·zookeeper·debian