[技術] SquashFS

Written on 3:25 下午 by Yu Lai

其實Squashfs已經用一陣子了,在用它之前是使用initramfs。
和initramfs相比,Squashfs較不佔記憶體的空間,
因為它是可以跑在mtd上的唯讀型壓縮檔案系統。
但也因為是唯讀的,所以在使用上仍需另外配置ramfs來提供Linux使用。
另外,initramfs和Kernel是包成同一個image的,而Squashfs是分開的。

Squashfs是一套供Linux核心使用的GPL開源唯讀壓縮檔案系統。
Squashfs能夠為檔案系統內的檔案、inode及目錄結構進行壓縮,
並支援最大1024千位元組的區段,以提供更大的壓縮比,
標準版的Squashfs採用gzip的數據壓縮。

Squashfs可以至http://squashfs.sourceforge.net/下載。

目前最新的是4.1版,是提供給Linux Kernel 2.6.29版本使用。
若使用較舊版本的Linux Kernel,請改用3.4版本。

以下是安裝Note,寫的有點亂,請見諒。
另外可以參考SquashFS HOWTO

1. 裝Linux Kernel上SquashFS patch。
# cd /opt/linux-2.6.xx
# patch -p1 < /opt/squashfs/kernel-patches/linux-2.6.xx/squashfs3.4-patch

2. 修改MTD配置,在Flash上配置出Kernel和Squashfs的partition出來。
(在此共切4個Partition,分別是0-Bootloader, 1-Kernel, 2-Rootfs, 3-Other)
若已經調整好或是使用類似Redboot的fis,可跳過這段。

3. 編Linux Kernel。
# make distclean
# make mrproper
# make menuconfig
在File systems->Miscellaneous file systems將Squashed filesystem啟動(bundled with the kernel)。
# make

4. 編出SquashFS tools (mksquashfs)。
# cd /opt/squashfs/squashfs-tools
# make

5. 將root file system透過mksquashfs來產生image。
# mksquashfs ./root_file_system rootfs.bin

6. 在Loader上用tftp把rootfs.bin載入後燒錄到Partition Rootfs對應在Flash上的Address。
e.g. # flash 0x00100000 0x80100000

7. 修改kernel command line。
請改成 "console=ttyS0 root=/dev/mtdblock2 rootfstype=squashfs"

PS1:
在root file system裡的/etc/fstab裡可加入
ramfs /tmp ramfs defaults 0 0,避免Linux無寫入的File System可以使用。

PS2:
配合mtd,在Linux下亦可以透過mtd tools直接upgrade root file system。
# flash_eraseall /dev/mtd2
# flashcp -v rootfs.bin /dev/mtd2

[技術] Dropbear - 輕量化SSH Server and Client

Written on 2:16 下午 by Yu Lai

最近工作上需要在嵌入式系統中加入SSH Server,本來是要使用OpenSSH,
但Code size差太大(1.4M vs 170K),於是改用了Dropbear。

載點: http://matt.ucc.asn.au/dropbear/dropbear.html

以下是安裝方法:

# ./configure --host=mips-linux --disable-zlib
# make

編譯完後會產生出以下的執行檔:

1. dropbear : SSH Server
2. dbclient : SSH Client
3. dropbearkey : Key Generator
4. dropbearconvert : OpenSSH Key Convertor

在使用上記得要有host key,才能執行dropbear,沒有的要請透過dropbearkey來產生。

# dropbearkey -t rsa -f /etc/dropbear/dropbear_rsa_host_key
# dropbear