
好久之前入手了一台華芸科技 ASUSTOR AS-604T 的 NAS,對於某些玩家來說(像我),不能方便的用 apt 安裝自己想要的軟體實在是很麻煩,還好的是用 Ubuntu Core 來在上面製作一個簡單的 Ubuntu rootfs 是非常容易的。本文最後將在 Ubuntu Core 上安裝另一個 SSH server 做為介紹。
考量到為了以後方便移植軟體進去 NAS,推薦使用跟 AS-604T 相容的 Ubuntu 版本 (11.10) 未來才不會遇到太多函式庫相依的問題。
接著本文將展示
- 使用 Ubuntu Core
- Hacking ASUSTOR NAS
安裝 Ubuntu Core
$ ssh root@192.168.0.50 # ssh to your NAS $ # Download Ubuntu Core 11.10 $ cd /volume1/ $ wget http://cdimage.ubuntu.com/ubuntu-core/releases/11.10/release/ubuntu-core-11.10-core-amd64.tar.gz $ # Extract it to ubuntu $ mkdir ubuntu && tar xvf ubuntu-core-11.10-core-amd64.tar.gz -C ubuntu/
mount.sh
$ cat << END > mount.sh
#!/bin/sh
ubuntu=/volume1/ubuntu
if [ "\$1" == "umount" ]; then
if grep -q " \$ubuntu/" /proc/mounts; then
awk -v ubuntu=$ubuntu '$2 ~ /ubuntu\// { print \$2 }' /proc/mounts | sort -u | xargs umount
else
true
fi
elif [ "\$1" == "mount" ]; then
grep -q " \$ubuntu/proc " /proc/mounts || mount -o bind /proc \$ubuntu/proc
grep -q " \$ubuntu/sys " /proc/mounts || mount -o bind /sys \$ubuntu/sys
grep -q " \$ubuntu/mnt" /proc/mounts || mount -o bind /volume1 \$ubuntu/mnt
grep -q " \$ubuntu/dev/pts" /proc/mounts || mount -t devpts /dev/pts \$ubuntu/dev/pts
else
awk -v ubuntu=\$ubuntu '\$2 ~ /ubuntu\// { print \$2 }' /proc/mounts | sort -u
fi
END
$ chmod +x mount.shchroot.sh
$ cat << END > chroot.sh
#!/bin/sh
if [ \$# == "0" ] ; then
chroot /volume1/ubuntu /bin/bash
else
chroot /volume1/ubuntu \$*
fi
END
$ chmod +x chroot.sh安裝基本工具 and 切換到 Ubuntu
$ echo nameserver 8.8.8.8 >> /etc/resolv.conf $ cat << END >> /etc/apt/source.list deb http://tw.archive.ubuntu.com/ubuntu/ precise universe deb-src http://tw.archive.ubuntu.com/ubuntu/ precise universe deb http://tw.archive.ubuntu.com/ubuntu/ precise-updates universe deb-src http://tw.archive.ubuntu.com/ubuntu/ precise-updates universe END $ ./mount.sh mount # 掛載 filesystems,每次開機只要做一次 $ ./chroot.sh #切換到 Ubuntu $ apt-get update $ apt-get install command-not-found less vim x11-apps至此我們已經有一個 Ubuntu 可以使用了。
安裝另一個 OpenSSH server
$ apt-get install openssh-server $ passwd root $ sed -i 's/^Port 22$/Port 2222/' /etc/ssh/sshd_config $ /etc/init.d/ssh start從別台電腦登入新開的 ssh server,順便啟用 X11 Forwarding
$ xhost + $ ssh -X root@192.168.0.50 -p 2222 $ # 設 local ip:display number $ export DISPLAY=192.168.0.100:0 $ xclock結果如同第一張圖所示,我們新開了一個 ssh service 在 2222 埠,連進去後 X11 Forwarding 也能順利使用(原先 ASUSTOR NAS 的 ssh server 不提供 X11 forwarding)。
順便提供自動設 DISPLAY 參數的 script,可以加在 ~/.bashrc,以後就不用每次 export DISPLAY=...
# DISPLAY
remote_ip=`env | awk '$0 ~ /^SSH_CLIENT=/ {print substr($1, index($1, "=") + 1)}'`
if [ ! -z "$remote_ip" ] ; then
export DISPLAY=$remote_ip:0
echo DISPLAY=$DISPLAY
fi
ASUSTOR NAS 程式自動啟動
可以在 /usr/local/AppCentral/*/CONTROL/start-stop.sh 找到一些 ASUSTOR NAS 的啟動 script。我隨便挑了一個 python 的 start-stop.sh 來偷加入剛才的 ssh server 啟動結束指令,如下列第 11 及 17 行
1 #!/bin/sh
2
3 EASY_INSTALL_BIN=/usr/local/AppCentral/python/bin/easy_install
4 EASY_INSTALL_LINK=/usr/local/bin/easy_install
5
6 case $1 in
7
8 start)
9 echo "Starting python..."
10 ln -sf $EASY_INSTALL_BIN $EASY_INSTALL_LINK
11 /volume1/mount.sh mount && /volume1/chroot.sh /etc/init.d/ssh start
12 ;;
13
14 stop)
15 echo "Stopping python..."
16 rm -rf $EASY_INSTALL_LINK
17 /volume1/chroot.sh /etc/init.d/ssh stop && /volume1/mount.sh umount
18 ;;
19
20 *)
21 echo "usage: $0 {start|stop}"
22 exit 1
23 ;;
24
25 esac
26 exit 0(為什麼 NAS 系統不直接以 Ubuntu/Debian/... 當做 base system 就好)
No comments:
Post a Comment