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
相关推荐
路多辛1 天前
Debian新一代的APT软件源配置文件格式DEB822详解
linux·运维·ubuntu·debian
飘飘燃雪7 天前
在 Linux 系统上安装 Docker 的步骤如下(以 Ubuntu/Debian为例)
linux·ubuntu·docker·debian
ℳ₯㎕ddzོꦿ࿐8 天前
在 Debian 系统上安装 Redis服务
运维·redis·debian
samson_www10 天前
Debian系统更新实现
运维·debian
木子欢儿13 天前
在 Debian 12 上安装 Xfce 桌面
java·linux·运维·服务器·debian
Vdeilae13 天前
debian 时间同步 设置ntp服务端 客户端
java·服务器·debian
皓月盈江13 天前
Linux Deepin深度操作系统应用商店加载失败,安装星火应用商店
linux·debian·deepin·国产操作系统·深度操作系统·星火应用商店·deepin应用商店加载失败
~狂想家~16 天前
Ubuntu20.04安装和配置Samba实现Win11下共享文件夹
linux·ubuntu·samba
没有余地 EliasJie17 天前
Ubuntu/Debian 搭建 Nginx RTMP 服务器全攻略
服务器·ubuntu·debian