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
相关推荐
爱的si念10 小时前
嵌入式ARM64 基于RK3588原生SDK添加用户配置选项./build lunch & debian
linux·debian·嵌入式
蚂蚁舞10 小时前
在arm架构的Debian系统手动安装和卸载Mysql8的操作
arm开发·debian·安装mysql·mysql8·卸载mysql
圆山猫19 小时前
[VF2] Boot Ubuntu和Debian发行版
ubuntu·postgresql·debian
etcix19 小时前
for my debian 12 mxlinux install the podman
运维·debian·podman
Jtti2 天前
在 Debian 系统上清理缓存的方式和具体操作方法
运维·缓存·debian
Molesidy4 天前
【随笔】【Debian】【ArchLinux】基于Debian和ArchLinux的ISO镜像和虚拟机VM的系统镜像获取安装
运维·debian·archlinux
程序员 _孜然14 天前
Ubuntu/Debian修改网卡名字enP3p49s0为eth0
linux·运维·驱动开发·嵌入式硬件·ubuntu·debian
Gavin_91518 天前
从零开始部署经典开源项目管理系统最新版redmine6-Linux Debian12
linux·ruby on rails·开源·debian·ruby·redmine
天朝八阿哥18 天前
Debian从12升到13的翻车记
debian
闻道且行之20 天前
嵌入式|VNC实现开发板远程Debian桌面
运维·debian·嵌入式