前回抽出した ROOT ディレクトリ を改変する。
真っ先に変更すべきなのは /etc/inittab で、
以下のように 1行挿入して /bin/ash が立ち上がるようにしておく。
これだけで、
シリアル・コンソールでシェルが使えるようになる。
--- ROOT.org/etc/inittab 2007-06-19 03:47:32.000000000 +0900
+++ ROOT/etc/inittab 2007-12-15 10:28:06.317233846 +0900
@@ -1,2 +1,3 @@
::sysinit:/etc/init.d/rcS
+ttyS0::askfirst:/bin/ash --login
#::respawn:/sbin/monit -Ic /etc/monitrc
この変更だけでも、
La Fonera+ がいじり放題になるので、
改変ファームウェアを作ってみる。
当然 kernel が必要になる。
FON のソースからビルドするのは難しくはないが、
クロスコンパイル環境の構築など、
それなりの時間がかかるので、
とりあえず純正ファームウェアのものをそのまま使って、
改変ファームウェアを作ってみる。
まず純正ファームウェアから取り出した image_full のヘッダを参照して、...
senri:/tmp % od -t x1 image_full | head -1
0000000 00 21 bf de a2 14 d3 9b 00 0a 50 34 6d 00 00 80
前回説明したように image_full は以下のフォーマットなので、
「lzma 圧縮したカーネル」は、
12 バイト目から 000A5034 (上記ヘッダ 8 バイト目~ に注目)
バイトであることが分かる。
┌───────┬───────┬───────┬───<<───┬───<<───┐
│rootイメージの│チェック・サム│rootイメージの│lzma 圧縮した │root イメージ │
│サイズ 4byte│(CRC32) 4byte│位置 4byte│カーネル │squashfs │
└───────┴───────┴───────┴───>>───┴───>>───┘
000A5034 は 10進数に直すと 675892 なので、
以下のように dd コマンドに「count=675892」を指定して、
image_full から lzma 圧縮したカーネル「vmlinux.lzma」を取り出す:
senri:/tmp % dd if=image_full bs=1 skip=12 count=675892 of=vmlinux.lzma
675892+0 records in
675892+0 records out
675892 bytes (676 kB) copied, 1.25156 seconds, 540 kB/s
前述したパッチを前回抽出した ROOT ディレクトリへ適用し、
mksquashfs-lzma コマンドを使って
root イメージ root.squashfs を作成する:
senri:/tmp # patch -p0 < patch
patching file ROOT/etc/inittab
senri:/tmp # mksquashfs-lzma ROOT root.squashfs -nopad -noappend -root-owned -be
Creating big endian 3.0 filesystem on root.squashfs, block size 65536.
Big endian filesystem, data block size 65536, compressed data, compressed metadata, compressed fragments
Filesystem size 1499.77 Kbytes (1.46 Mbytes)
31.47% of uncompressed filesystem size (4766.19 Kbytes)
Inode table size 4802 bytes (4.69 Kbytes)
23.45% of uncompressed inode table size (20479 bytes)
Directory table size 5571 bytes (5.44 Kbytes)
56.99% of uncompressed directory table size (9776 bytes)
Number of duplicate files found 4
Number of inodes 639
Number of files 407
Number of fragments 28
Number of symbolic links 165
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 67
Number of uids 1
root (0)
Number of gids 0
以上で、
カーネルと root イメージの準備ができた。
vmlinux.lzma と root.squashfs をつなげて image ファイルを作成する:
senri:/tmp % fonimage.pl image vmlinux.lzma root.squashfs
fonimage.pl は、
FON のソース を展開すると、
fon/target/linux/fonera-2.6/image/fonimage.pl にある perl スクリプト。
CRC32 の算出 (前述した image_full のフォーマット参照) のため、
Digest::CRC モジュールが必要。
できた image を TFTP サーバに置いて、
La Fonera+ の flash へ書込む。
試しに起動してみる:
RedBoot> fis load loader
RedBoot> go
Failsafe loader v0.2
Looking for board config data... found at offset 0xa87f0000
Reset button GPIO: 6
Reading flash from 0xa8040000 to 0xa825bf48... done.
Verifying CRC... OK - 0x766770d6
Uncompressing Linux... Ok, booting the kernel.
[sighandler]: No more events to be processed, quitting.
[cleanup]: Waiting for children.
[cleanup]: All children terminated.
Unlocking rootfs ...
Could not open mtd device: rootfs
switching to jffs2
init started: BusyBox v1.4.1 (2007-09-03 10:39:50 UTC) multi-call binary
Please press Enter to activate this console.
BusyBox v1.4.1 (2007-09-03 10:39:50 UTC) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
______ __
/\ ___\ /\ \
\ \ \__/ __ ___ __ _ __ __ \_\ \___
\ \ _\/ __`\ /' _ `\ /'__`\/\`'__\/'__`\ /\___ __\
\ \ \/\ \L\ \/\ \/\ \/\ __/\ \ \//\ \L\.\_ \/__/\ \_/
\ \_\ \____/\ \_\ \_\ \____\\ \_\\ \__/.\_\ \ \_\
\/_/\/___/ \/_/\/_/\/____/ \/_/ \/__/\/_/ \/_/
-------------- Fonera 1.5 Firmware (v1.1.1.1) -----------------
* Based on OpenWrt - http://openwrt.org
* Powered by FON - http://www.fon.com
-----------------------------------------------------
root@OpenWrt:/#
カーネルは改変していないので、
起動ログを見ることはできないが、
シェルが使えるのでいじり放題。
では早速...
root@OpenWrt:/# cat > /etc/ipkg.conf <<EOF
> src gcd http://www.gcd.org/fonera
> dest root /
> dest ram /tmp
> EOF
root@OpenWrt:/# ipkg update
Downloading http://www.gcd.org/fonera/Packages
Updated list of available packages in /usr/lib/ipkg/lists/gcd
Done.
root@OpenWrt:/# ipkg install dropbear
Installing dropbear (0.48.1-1) to root...
Downloading http://www.gcd.org/fonera/dropbear_0.48.1-1_mips.ipk
xsystem: ERROR: fork failed before execution: `wget --passive-ftp -q -P /tmp/ipkg-0dCiiX http://www.gcd.org/fonera/dropbear_0.48.1-1_mips.ipk'
Nothing to be done
An error ocurred, return value: 22.
Collected errors:
Failed to download dropbear. Perhaps you need to run 'ipkg update'?
root@OpenWrt:/#
つまり
GCD の ipkg feed から
dropbear
をインストールしようとしたのだが、
La Fonera+ の wget は busybox 内蔵のもので
ipkg が期待する wget とは引数の形式が異なるようだ。
ipkg のためだけに GNU Wget
をインストールするのも牛刀なので、
手作業で dropbear をインストールしてみる。
root@OpenWrt:~# wget http://www.gcd.org/fonera/Plus/dropbear_0.49-1_mips.ipk
Connecting to www.gcd.org [60.32.85.216:80]
dropbear_0.49-1_mips 100% |*****************************| 98 KB --:--:-- ETA
root@OpenWrt:~# tar xvzf dropbear_0.49-1_mips.ipk
./debian-binary
./data.tar.gz
./control.tar.gz
root@OpenWrt:~# cd /
root@OpenWrt:/# tar xvzf ~/data.tar.gz
./
./usr/
./usr/sbin/
./usr/sbin/dropbear
./usr/bin/
./usr/bin/scp
./usr/bin/ssh
./usr/bin/dbclient
./usr/bin/dropbearkey
./etc/
./etc/config/
./etc/config/dropbear
./etc/init.d/
./etc/init.d/dropbear
root@OpenWrt:/# /etc/init.d/dropbear start
root@OpenWrt:/#
これで外部から ssh でログインできるようになる。
La Fonera+ 起動時に自動的に dropbear (ssh サーバ) を立ち上げるには、
root@OpenWrt:/# /etc/init.d/dropbear enable
を実行すればよい。
以上は、
dropbear を La Fonera+ に直接インストール方法であるが、
もちろん前述した ROOT ディレクトリに対して dropbear をインストールして、
dropbear 入り image ファイルを作って flash メモリに書込んだ方がよい。