定制编译openwrt.

八 14th, 2011

配置完openwrt之后,觉得实在是还不够。想装个tcpdump,结果发现没有空间了。看样子得想办法省出点空间。

仔细看了看openwrt的文件系统结构,发现openwrt是把编译出来的一份只读系统打包了,装载在/rom下,然后,修改新加的内容,单独放在另一个可读写的地方,装载在/overlay上。/rom和/overlay的文件都不是全部,两者结合,才真正形成了一个复合的文件系统,加载于/。对系统文件进行替换后,由于/rom不可写,不要的那个文件并没有真正删除,其空间也就浪费了。这在小小的路由器上,是不可接受的。因此对系统的修改,比如我重新弄了个改完BUG后的dropbear,就实在是大大的浪费。

而且/rom里的文件,实际存储是压缩了的,文件压缩自然可省空间。因此有必要编译一份openwrt。过程:
1. host安装必要的组件: apt-get install gawk flex unzip git subversion
2. 下载源代码。 svn co svn://svn.openwrt.org/openwrt 。从此trunk目录就成了build_root目录。
3. 更新feeds. ./scripts/feeds update -a
4. 安装必须的组件 ./scripts/feeds install tcpdump psmisc
5. make menuconfig,设置一些组件。使得Target System为Atheros AR71xx/AR7240/AR913x/AR934x。Target Profile为TP-LINK TL-WR841ND v7。
6. 继续设置menuconfig里的组件。完了后make defconfig检查,确保得到以下结果:

diff  y
kmod-ipt-nathelper-extra y
kmod-mppe y
kmod-pptp y
pptp y
uhttpd  y
tcpdump y
psmisc m

注意psmisc用Module方式就可以了,因为里面有多个程序,我只需要最重要的pstree。
7. make
8. 修改dropbear bug。见: http://www.swigger.net/archives/291.html
cd ./build_dir/target-mips_r2_uClibc-0.9.32/dropbear-0.53.1

note @2012-01-22: this bug is fixed by dropbear.
9. 修改config.sh ./package/base-files-network/files/lib/network/config.sh
http://www.swigger.net/archives/316.html
- if [ -d /proc/sys/net/$fam ]; then
+ if ls /proc/sys/net/$fam/*/$ifn 2>/dev/null ; then
10. 修改package/base-files-network/files/sbin/ifdown . 见 http://www.swigger.net/archives/336.html
11. 修改 rcS

--- package/base-files/files/etc/init.d/rcS     (revision 29839)
+++ package/base-files/files/etc/init.d/rcS     (working copy)
@@ -4,15 +4,15 @@
 run_scripts() {
        for i in /etc/rc.d/$1*; do
                [ -x $i ] && $i $2 2>&1
-       done | $LOGGER
+       done
 }
 
 system_config() {
        config_get_bool foreground $1 foreground 0
 }
 
-LOGGER="cat"
-[ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"
+#LOGGER="cat"
+#[ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"
 
 . /etc/functions.sh

12. 来到build_root目录,执行:

$ mkdir -p files/etc/config
$ mkdir files/etc/ppp
$ cp ./build_dir/target-mips_r2_uClibc-0.9.32/dropbear-0.53.1/ipkg-ar71xx/dropbear/etc/config/dropbear files/etc/config
$ vim files/etc/config/dropbear
+  option GatewayPorts 1
$ cp ./build_dir/target-mips_r2_uClibc-0.9.32/pptp-1.7.1/ipkg-ar71xx/pptp/etc/ppp/options.pptp files/etc/ppp/
$ vim files/etc/ppp/options.pptp
- defaultroute
$ cp build_dir/target-mips_r2_uClibc-0.9.32/root-ar71xx/etc/shells files/etc/
$ vim files/etc/shells
+ /bin/false
$ mkdir -p files/usr/bin
$ cp build_dir/target-mips_r2_uClibc-0.9.32/psmisc-22.13/ipkg-ar71xx/psmisc/usr/bin/pstree files/usr/bin/
$ ./staging_dir/toolchain-mips_r2_gcc-4.5-linaro_uClibc-0.9.32/bin/mips-openwrt-linux-strip files/usr/bin/pstree 
$ make

13. 大功告成。使用 bin/ar71xx/openwrt-ar71xx-generic-tl-wr841nd-v7-squashfs-factory.bin 刷系统。
刷完系统再改改配置文件。(/rom/etc/config下的总是会copy到/overlay/etc/config中,预置配置文件省不了空间)组件就不用装了。
结果是嵌了tcpdump和其它我需要的几个组件,最后还剩下几百K的空间。总的来说成果很好。

root@OpenWrt:~# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/root                 1792      1792         0 100% /rom
tmpfs                    14780        84     14696   1% /tmp
tmpfs                      512         0       512   0% /dev
/dev/mtdblock3             844        80       764   9% /overlay
overlayfs:/overlay         844        80       764   9% /
root@OpenWrt:~# mount
rootfs on / type rootfs (rw)
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,noatime)
sysfs on /sys type sysfs (rw,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime,size=14780k)
tmpfs on /dev type tmpfs (rw,noatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,noatime,mode=600)
/dev/mtdblock3 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlayfs (rw,noatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
标签:
  1. Van Gollis
    八 30th, 201108:17

    As a code you impart here I definitely like you blog and it was pretty cool and fantastic one. I will bookmark you site. Keep it up! Thanks for this.
    site Vertical Blinds

  2. Denise P. Grigg
    八 30th, 201108:50

    Are you the one who made this codes???Anyway thanks for sharing the source codes in here. It is very useful and helpful to us. I’m going try to download the FLV converter later.

  3. Lonely
    八 30th, 201114:28

    Carefully looked at the openwrt file system structure, that openwrt is to build out a read-only system, packaged, and loaded in the / rom, and then modify the new additional content can be read separately in another place, mounted on / overlay on. / rom and / overlay file is not full, a combination of both, really form a complex file system, load on /. Replace the system files, due to / rom can not write, do not that does not really delete the file, its also a waste of space. This little router is unacceptable. Therefore, the system changes, such as I re-broke a complete change BUG after dropbear, it really is a big waste.Anyway, thanks for sharing.

  4. Jellyn
    八 30th, 201114:29

    Replace the system files, due to / rom can not write, do not that does not really delete the file, its also a waste of space. This little router is unacceptable. Therefore, the system changes, such as I re-broke a complete change BUG after dropbear, it really is a big waste.Anyway, thanks for sharing.

  5. E-bike
    十一 10th, 201101:50
    #5
  6. a chorus line movie wiki
    一 24th, 201215:10
    #6
*