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
相关推荐
tianyuanwo2 天前
Debian 系统 deb 仓库管理与配置完全指南
debian·deb
WXDcsdn3 天前
新安装的Debian 12系统开启root用户和ssh登录权限
运维·debian·ssh
fiveym4 天前
Debian 12 PXE 安装报错:Bad archive mirror 复合型故障排查全记录
运维·服务器·debian·php
fiveym6 天前
PXE安装Debian报错:GRUB安装失败排查指南
运维·debian
NashSKY6 天前
RK3588 Debian 系统安装与WiFi/SSH配置笔记
debian·ssh·rk3588
小尘要自信7 天前
踩过坑才明白:为什么 ZooKeeper 集群才是正经事
分布式·zookeeper·debian
络合白泽8 天前
Debian 13 + NVIDIA Optimus 笔记本:从零配置 Wayland Explicit Sync 完整指南
运维·debian
键盘上的GG小怪兽GG11 天前
Debian 安装CUPS操作
linux·服务器·debian
xiaobobo333011 天前
安装samba服务器后,无法输入\\192.xx.xx.xx访问共享文件
samba·无法访问共享文件夹
xiaobobo333011 天前
ubuntu14.04搭建Samba服务器实现文件共享
ubuntu·samba·共享文件夹