下面是對1.00版本的實驗。
1、文件準備
解壓busybox-1.00.tar.gz得到busybox-1.00目錄,進入,閱讀相關的README和INSTALL,沒什么特別的,都是提示busybox需要經過三個步驟的操作進行安裝使用。
2、配置busybox
busybox的配置程序和linux內核菜單配置方式簡直一模一樣
#make menuconfig
下面是需要編譯進busybox的功能選項,其他的可以根據需要自選,但是同樣不要太貪心.
General Configuration應該選的選項
Show verbose applet usage messages
Support for SUID/SGID handling
Runtime SUID/SGID configuration via /etc/busybox.conf
Build Options
Build BusyBox as a static binary (no shared libs)
這個選項是一定要選擇的,這樣才能把busybox編譯成靜態鏈接的可執行文件,運行時才獨立于其他函數庫.否則必需要其他庫文件才能運行,在單一個linux內核不能使他正常工作.
Installation Options
Don't use /usr
(./_install) BusyBox installation PRefix
這個選項也一定要選,否則make install 后busybox將安裝在原系統的/usr下,這將覆蓋掉系統原有的命令.選擇這個選項后,make install后會在busybox目錄下生成一個叫_install的目錄,里面有busybox和指向他的鏈接.
其他選項都是一些linux基本命令選項,自己需要哪些命令就編譯進去,一般用默認的就可以了.
配置好后退出并保存.
3,編譯并安裝busybox
#make
#make install
順利完成。
4、檢查安裝結果
根據參考資料2,檢查到編譯好后在解壓目錄busybox-1.00目錄下生成子目錄_install
# ll
總用量 8
drwxr-xr-x 2 root root 4096 12月 11 15:49 bin
lrwxrwxrwx 1 root root 11 12月 11 15:49 linuxrc -> bin/busybox
drwxr-xr-x 2 root root 4096 12月 11 15:49 sbin
其中可執行文件busybox在bin目錄下,其他的都是指向他的符號鏈接.
-rwxr-xr-x 1 root root 801400 12月 11 15:49 busybox
可見busybox只要八百k多點。根據配置選擇的不同,編譯出來的busybox大小也會有差別。根據其他資料所述,典型的busybox文件大小在動態鏈接的情況下是300 KB左右,靜態鏈接為800 KB左右,用它實現的文件系統完全可以控制在1 MB以下
在bin/下面有:
# ll
總用量 788
lrwxrwxrwx 1 root root 7 12月 11 15:49 [ -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 ash -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 basename -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 bunzip2 -> busybox
-rwxr-xr-x 1 root root 801400 12月 11 15:49 busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 bzcat -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 cat -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 chgrp -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 chmod -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 chown -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 chvt -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 clear -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 cmp -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 cp -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 cut -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 date -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 dd -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 deallocvt -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 df -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 dirname -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 dmesg -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 du -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 echo -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 egrep -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 env -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 expr -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 false -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 fgrep -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 find -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 free -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 grep -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 gunzip -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 gzip -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 head -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 hexdump -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 hostname -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 id -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 install -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 kill -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 killall -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 ln -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 logger -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 ls -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 mkdir -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 mknod -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 mktemp -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 more -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 mount -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 mv -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 openvt -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 pidof -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 ping -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 ps -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 pwd -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 readlink -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 reset -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 rm -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 rmdir -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 sed -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 sh -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 sleep -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 sort -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 strings -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 sync -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 tail -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 tar -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 tee -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 test -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 time -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 touch -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 tr -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 true -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 tty -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 umount -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 uname -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 uniq -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 unzip -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 uptime -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 usleep -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 vi -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 wc -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 wget -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 which -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 whoami -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 xargs -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 yes -> busybox
lrwxrwxrwx 1 root root 7 12月 11 15:49 zcat -> busybox
根據資料,可以這樣用busybox
#busybox ls
他的功能就相當運行ls命令
實驗如下:
在bin/目錄下
# busybox ls
[ chgrp cut du find hostname ls openvt rm sync tr uptime xargs……
實際就是把原先的命令加一個busybox的前綴就是了~
最常用的用法是建立指向busybox的鏈接,不同的鏈接名完成不同的功能.
#ln -s busybox ls
#ln -s busybox rm
#ln -s busybox mkdir
然后分別運行這三個鏈接:
#./ls
#./rm
#./mkdir
就可以分別完成了ls rm 和mkdir命令的功能.雖然他們都指向同一個可執行程序busybox
但是只要鏈接名不同,完成的功能就不同。
實際上可以看到安裝結果已經包含了這些基本命令但符號鏈接。實驗如下:
# ./ls
Using fallback suid method
[ chgrp cut du find hostname ls openvt rm sync tr uptime xargs……
# ./echo $PATH
Using fallback suid method
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin
# ./mkdir
Using fallback suid method
BusyBox v1.00 (2006.12.11-07:42+0000) multi-call binary
Usage: mkdir [OPTION] DIRECTORY...
……
# busybox mkdir
BusyBox v0.60.5 (2003.01.24-22:43+0000) multi-call binary
Usage: mkdir [OPTION] DIRECTORY...
……
可以看到,使用busybox的ls命令會多輸出一個左括符號,并會多出Using fallback suid method或BusyBox v1.00 (2006.12.11-07:42+0000) multi-call binary的提示
5、反思與總結
實際上最麻煩的工作是配置,其中動態/靜態庫,安裝位置,是否使用交叉編譯工具等幾個問題在上面操作中并沒有深入涉及。
參考資料3中提到配置時的選項:
下面三個目錄是很多人都會感興趣的:
Build Options --->
Installation Options --->
Login/PassWord Management Utilities --->
在Build Options里面有是否使用交叉編譯的選項(Do you want to build BusyBox with a Cross Compiler)。如果要對其他平臺進行編譯就要選擇它并設置相應的編譯程序前綴。
在Installation Options里面可以設置安裝的路徑,即設置為新文件系統的根目錄。當然也可以用缺省的 _install目錄,安裝之后再復制到新文件系統中去。
在設置Login/Password Management Utilities的時候,為了免去配置glibc的麻煩,最好設置使用busybox自己的password和shadow文件的功能(Use internal password and group functions rather than system functions)。
busybox 提供的命令無疑比較全面,但它的缺省配置還不能構成一個功能比較完備的文件系統。必須要添加的命令有Login/Password Management Utilities里面的getty、login和passwd,這些命令從前是由另外一個軟件包tinylogin所提供的。當然,如果不需要一個交互的登錄界面,這些命令也可以去掉。通過設定內核參數init=/bin/sh可以在系統啟圖1busybox的編譯配置界面動后直接得到一個shell。
tlenetd命令是一個遠程登錄服務程序,把它編譯進busybox中會為將來的調試提供很多的方便。當然也可以通過串口終端的方式管理嵌入式設備,但網絡登錄的方式卻更為方便。
[遺留問題]
1、Show verbose applet usage messages
Runtime SUID/SGID configuration via /etc/busybox.conf是什么意思?
[參考資料]
1、《源碼開放的嵌入式系統軟件分析與實踐——基于skyeye和arm開發平臺》陳渝 李明 楊曄 等編著 北京航空航天大學出版社
2、編譯busybox
實際上這個資料只不過是另一篇文章“
BabyLinux制作過程詳解
”中的一個片段~
3、Busybox制作嵌入式Linux的文件系統
新聞熱點
疑難解答