BusyBox是最常用的定制根檔案系統的方法,它能夠迅速建立一套相對完整、功能豐富的檔案系統,其中包括大量常用的用程式。Busybox再設計上充分考慮到了硬體的資源受限的特殊工作環境,采用了将所有的指令通過軟連接配接的方法指向自己的方法來減自己的體積。
1. 準備環境
1.1 下載下傳BusyBox源碼
連結: https://busybox.net/downloads/
1.2 建立工程目錄
[email protected]:/opt# tree ./arm/
./arm/
├── busybox-1.26.2.tar.bz2
└── rootfs
2 編譯BusyBox
2.1 BusyBox解壓到/opt/arm/
[email protected]:/opt/arm# tar -jxvf ./busybox-1.26.2.tar.bz2
2.2 修改Makefile
[email protected]:/opt/arm/busybox-1.26.2# vim ./Makefile
查找到 CROSS_COMPILE ?=
修改為 CROSS_COMPILE ?= arm-linux-
查找到ARCH ?= 修改為 ARCH ?= arm
2.3 配置BusyBox
[email protected]:/opt/arm/busybox-1.26.2# make menuconfig Busybox Settings --->
是否使用靜态C庫: Build BusyBox as a static binary (no shared libs) (NEW)
使用軟連接配接還是硬連結: What kind of applet links to install (as soft-links) --->
安裝路徑: (/opt/arm/rootfs) BusyBox installation prefix
2.4 安裝BusyBox
[email protected]:/opt/arm/busybox-1.26.2# make
[email protected]:/opt/arm/busybox-1.26.2# make install
3. 可能遇到的問題
(1) 當出現miscutils/nandwrite.c: In function 'nandwrite_main': 問題時,複制 /usr/include/mtd/mtd-abi.h 到busybox下的include目錄下。并在nandwrite.c檔案中添加"mtd-abi.h"頭檔案。 (2) 當出現util-linux/blkdiscard.c: In function 'blkdiscard_main':問題時,複制 /usr/include/linux/fs.h 到busybox下的include目錄下。并在blkdiscard.c檔案中添加"fs.h"頭檔案。 (3) 連結時出現錯誤
debianutils/lib.a(mktemp.o): In function `mktemp_main':
mktemp.c:(.text.mktemp_main+0x98): warning: the use of `mktemp' is dangerous, better use `mkstemp'
coreutils/lib.a(sync.o): In function `sync_main':
sync.c:(.text.sync_main+0x7c): undefined reference to `syncfs'
collect2: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
Makefile:717: recipe for target 'busybox_unstripped' failed
make: *** [busybox_unstripped] Error 1
去掉Coreutils ---> sync
去掉Linux System Utilities ---> nsenter