xiaowei-system/scripts/fix-fstab-lan.sh

35 lines
1.4 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# fix-fstab-lan.sh — 2026-09-04 牧尘指示SMB 备份只在家庭局域网(192.168.123.11)
# 根因fstab 把 automount 写死为 StarVPN(192.168.188.11),导致外网也挂 SMB 传大文件 → 弱网僵死
# 修复fstab 挂载 IP 改回局域网 192.168.123.11(保留 x-systemd.automount
# 外网时 dual-backup.sh 先探测 123.11:445 不通即跳过,不触发挂载;
# 在家时探测通过 → 访问挂载点触发 automount 挂局域网共享)
set -e
echo "=== 修改前 ==="
grep server-backup /etc/fstab || true
# 先卸载当前 StarVPN 残留挂载(若在且指向 188.11
if mountpoint -q /mnt/server-backup 2>/dev/null; then
if grep -q '//192\.168\.188\.11/' /proc/mounts; then
echo "卸载 StarVPN 残留挂载..."
umount -l /mnt/server-backup 2>/dev/null || umount /mnt/server-backup 2>/dev/null || true
sleep 1
fi
fi
# 备份 fstab
cp /etc/fstab /etc/fstab.bak.20260904-lan
# 只替换 IP188.11(StarVPN) → 123.11(局域网)
sed -i 's|//192\.168\.188\.11/beifen /mnt/server-backup|//192.168.123.11/beifen /mnt/server-backup|' /etc/fstab
echo "=== 修改后 ==="
grep server-backup /etc/fstab || true
# 重新加载 systemd 挂载/自动挂载单元
systemctl daemon-reload 2>/dev/null || true
echo "=== 完成fstab 已指向局域网 192.168.123.11 ==="
echo "=== 验证外网状态123.11:445 不通dual-backup 应秒级跳过 ==="