在 Tomato 固件上设置 Time Machine 服务器

网上看到的都是 ddwrt 的设置方法,而 ddwrt 和 tomato 还是有些区别的,因此在这里记录一下供参考(简单说明,需要有点 linux 的基础知识才能看明白)。我用的是 Linksys E3000,其他路由器应该差不多可能下的包不太一样。如果有遇到问题欢迎在评论中告知。

要做的事情简单说如下:

  1. 打开 tomato 中的 jffs
  2. 适用 gparted 准备外置硬盘(分区为 swap、ext3、hfs+)
  3. 具体步骤参考 这个网页的说明,记得装上 sd-idle-2.6,建议装在 /jffs 下,sd-idle 是用来设置硬盘在空闲时停转的,我设置成 10 分钟空闲即停转。

  4. 下载并安装 hfs+ 文件系统支持
  5. 下载这里的包并解压缩,将其中的 hfsplus.ko scp 到 /jffs 下面(112k),好像 hfsplus.ko 仅和 TomatoUSB 固件兼容,@petefang 的 Tomato RAF 不兼容,这种情况可以用 NTFS 分区替代从而跳过这部分,因为我们使用的是 AFP 共享,应该没有太大影响。
    我设置的启动 Init脚本为:

    #!/bin/sh
    # wait and insert kernel module hfsplus.ko
    sleep 2
    insmod /jffs/hfsplus.ko
    # Need to wait for file system, USB, automounter to come online first so wait for some period.
    sleep 10

    # Start sd-idle to auto stop USB HDD if not used after 10min
    if [ -e /var/notice/sd-idle ]; then
    echo "[sd-idle] already started; not starting."
    else
    /jffs/bin/sd-idle-2.6 -i 600
    touch /var/notice/sd-idle
    fi

    # Initialize script in /opt/etc/init.d
    for f in /opt/etc/init.d/S* ; do
    [ -x $f ] && $f start
    done

  6. 设置关闭 Shutdown 脚本

  7. for f in /opt/etc/init.d/K* ; do
    [ -x $f ] && $f stop
    done

    # cleanup
    killall afpd
    killall avahi-daemon
    killall dbus-daemon
    rm -rf /opt/var/run/*

    # Unmount Opt from flash drive
    umount /mnt/sda3
    umount /swap
    umount /opt
    sleep 5
    led usb off

  8. 此时确认 /opt 已经挂载,安装 optware
  9. 在终端里面执行如下命令(逐行拷贝执行):

    wget http://tomatousb.org/local--files/tut:optware-installation/optware-install.sh -O - | tr -d '\r' > /tmp/optware-install.sh

    chmod +x /tmp/optware-install.sh

    sh /tmp/optware-install.sh

    ipkg update

    至此,optware 应该已经装到了 /opt 下

  10. 这里下载 dbus_1.2.16-2_mipsel.ipk.zip,并 scp 到 ~ 下手动安装
  11. 用 ipkg-opt 安装这些包:avahi、coreutils、libgcrypt
  12. 这里下载更新的包,并 scp 到 ~ 下手动安装:netatalk、libdb
  13. 在 /opt/etc/init.d/ 下建立一个 S15prepare 脚本并 chmod +x S15prepare
  14. 这个脚本是用来创建 avahi 运行时需要的用户的

    if grep -q ^netdev: /etc/group; then
    # echo There already is an netdev group on the system.
    true
    else
    addgroup -g 1 netdev
    fi

    if grep -q ^avahi: /etc/group; then
    # echo There already is an avahi group on the system.
    ADDUSER_OPT="-G avahi"
    else
    addgroup -g 2 avahi
    fi

    if grep -q ^avahi: /etc/passwd; then
    # echo There already is an avahi user on the system.
    true
    else
    echo -n "No avahi user found, creating it... "
    # adduser -h /var/run/avahi -g "avahi daemon" -s /bin/false -D -H $ADDUSER_OPT avahi > /dev/null 2>&1
    echo "avahi:x:2:2:avahi daemon:/opt/sbin/avahi-daemon:/bin/false" >> /tmp/etc/passwd

    echo done
    fi
    set -e

  15. 根据这个网页另一个网页的说明配置 avahi,用 /opt/etc/init.d/S20dbus 和 /opt/etc/init.d/S21avahi-daemon 来启动 dbus 和 avahi
  16. /opt/etc/avahi/services/timecapsule_afpd.service 的内容参考这个网页

  17. 根据这个网页的说明配置 afpd ,我使用的是匿名的选项,谁知道怎么配置用户名密码登录的请告诉我
  18. 我的 afpd 相关配置如下:
    /opt/etc/netatalk/AppleVolumes.default :

    /mnt/sda3 "Time Machine" volsizelimit:4000000 cnidscheme:tdb options:usedots,tm,upriv

    /opt/etc/netatalk/netatalk.conf :
    仅更改 ATALKD_RUN=yes为

    ATALKD_RUN=no

    /opt/etc/netatalk/afpd.conf

    - -tcp -noddp -uamlist uams_guest.so -savepassword -advertise_ssh

  19. 建立一个 /opt/etc/init.d/S30afpd 来启动 afpd ,注意给脚本使用 chmod +x S30afpd

  20. #!/bin/sh
    EXE=afpd
    BIN=/opt/sbin/$EXE
    OPTIONS=""
    RUN_D=/var/run/$EXE
    case $1 in
    start)
    mkdir -p $RUN_D
    $BIN $OPTIONS
    ;;
    stop)
    killall $BIN
    ;;
    reload)
    if [ -f $RUN_D/pid ]; then
    $BIN -r;
    else
    mkdir -p $RUN_D;
    $BIN $OPTIONS;
    fi
    ;;
    restart)
    if [ -f $RUN_D/pid ]; then
    killall $BIN
    fi
    mkdir -p $RUN_D
    $BIN $OPTIONS
    ;;
    *)
    echo "usage: $0 (start|stop|reload|restart)"
    exit 1
    esac
    exit $?

  21. 将 S20dbus、S21avahi-daemon、S30afpd 复制一份为 K20dbus、K21avahi-daemon、K30afpd,供关闭脚本调用
  22. 重启路由器,等待一会儿,应该可以在 Mac 的 Finder 里面看到出来个 Time Capsule 了,点击后应该能挂载上 /mnt/sda3 的 hfs+ 卷,这时打开系统偏好设置的 Time Machine,看能否指派这个网络卷,如果不能则在 Mac 的终端执行:

    defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

    后再看,能指派网络卷后,等待 Time Machine 初始化并开始备份,之后应该可以在 Mac 的终端中关闭

    defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 0

  23. 设置 USB Support 中的 Run after mounting 和 Run before unmounting 脚本
  24. Run after mounting

    led usb on

    Run before unmounting

    killall afpd
    killall avahi-daemon
    killall dbus-daemon
    rm -rf /opt/var/run/*
    # Unmount Opt from flash drive
    umount /swap
    umount /opt
    sleep 3
    led usb off

至此应该大功告成,建议第一次的 Time Machine 备份使用千兆网连接。

后记:avahi 提示我需要 nss-mdns 的支持,因为没有找到直接能用的包,我就没有管它。如果有谁能有办法让 nss-mdns 在 Tomato 上跑起来,请告诉我。

3条回应 to “在 Tomato 固件上设置 Time Machine 服务器”

  1. fishy Says:

    afpd.conf:
    - -transall -uamlist uams_dhx.so,uams_dhx2.so -nosavepassword

    其中有用的应该只有uams_dhx2.so,我印象里uams_dhx.so的加密不够安全已经被Mac取消支持了

  2. Peter Fang Says:

    我唯一遇到的问题就是这个指南是在Tomato USB固件上实现的,我的E3000运行的是Tomato RAF,hfsplus.ko模块似乎和内核不兼容,insmod hfsplus.ko的时候提示错误,无法打开hfs+支持。后来我把Time Machine分区改成了用NTFS分区来实现。

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Connecting to %s


加关注

Get every new post delivered to your Inbox.