基於busybox 1.7.0 靜態庫檔案系統製作
1.mkdir rootfs
2.cd rootfs
mkdir bin dev etc lib proc sbin sys usr mnt tmp var
3.mkdir usr/bin usr/lib usr/sbin lib/modules
4.建立裝置檔案
mknod -m 666 console c 5 1
mknod -m 666 ttyS0 c 4 64
mknod -m 666 ttyS1 c 4 65
mknod -m 666 null c 1 3
5.etc 設定檔的製作
建立指令碼檔案 etc/inittab,如下
::sysinit:/etc/init.d/rcS
::respawn:-/bin/sh
::ctrlaltdel:/bin/umount -a -r
::shutdown:/bin/umount -a -r
::shutdown:/sbin/swapoff -a
#::respawn:/sbin/getty -L ttyS0 115200 vt100
#::respawn:/sbin/getty -L ttyS1 115200 vt100
設定此指令碼執行許可權
#chmod 644 etc/inittab
建立指令碼檔案 etc/init.d/rcS, 內容如下:
#!/bin/sh
/bin/mount -t proc none /proc
/sbin/ifconfig lo 127.0.0.1 up
/sbin/ifconfig eth0 10.0.0.2 netmask 255.0.0.0 up
hostname skyeye
mkdir /var/tmp
mkdir /var/log
mkdir /var/run
mkdir /var/lock
/bin/ash
設定此指令碼執行許可權
#chmod 755 etc/init.d/rcS
當然也可以直接將人家做好的etc copy過來,cp -a xx/etc/* /nfsroot/rootfs/
6.進入檔案系統
make menuconfig
xxx:
Busybox Settings ---> Build Options ---> [*] Build BusyBox as a static binary (no shared libs)
確保 [*] Build BusyBox as a static binary (no shared libs) 被選中
xxx:
Build Option-->"Do you want to build busybox with a cross compiler" /opt/mixxx/mipsle-linux-
如果沒有cross compiler選項,
修改 Makefile, 將
ARCH ?= $(SUBARCH)
CROSS_COMPILE ?=
改為
ARCH ?= mips
CROSS_COMPILE ?= /opt/gcc-3.3.6-glibc-2.3.6/bin/mipsel-linux-
xxx:
Installation Option-->Busybox Installation Prefix(/nfsroot/rootfs)
其它的選項根據自己實際需求來選擇。
6.make
編譯出錯
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
#warning Static linking against glibc produces buggy executables
#warning (glibc does not cope well with ld --gc-sections).
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from top-level Makefile and remove this warning.
#error Aborting compilation.
#endif
解決方案:因為busybox主要應用於對空間要求非常嚴格的嵌入式系統,所以它推薦使用uclibc而不鼓勵使用glibc,如果你沒有安裝uclibc,而且在 build Options也選擇了Build BusyBox as a static binary(no shared libs),那肯定無法編譯通過的,當然如果你之前build Options選擇的是動態編譯的話就不會有這樣的問題出現了。假設你是第一種情況,我們可以這樣解決:把applets/applets.c開頭的幾行 warning注釋掉
7.make install
***********************************************************************
busybox 應該注意的選項和問題
交叉編譯器: 3.3.2
# wget -c http://www.busybox.net/downloads/busybox-1.7.0.tar.bz2
# tar jxvf busybox-1.7.0.tar.bz2
修改源碼、配置、編譯
-----------------------------------------------
# cd busybox-1.7.0
# vi Makefile +176
ARCH ?= arm
CROSS_COMPILE ?= /usr/local/arm/3.3.2/bin/arm-linux-
# make menuconfig
Busybox Settings --->
Build Options --->
[*] Build BusyBox as a static binary (no shared libs) //(1)
Installation Options --->
[*] Don't use /usr //(2)
Linux System Utilities --->
[*] mdev //(3)
[*] Support /etc/mdev.conf
[*] Support command execution at device addition/removal
Shells --->
Choose your default shell (msh) ---> //(4)
(1) 這個選項是一定要選擇的,這樣才能把busybox編譯成靜態連結的可執行檔,運行時才獨立於其他函數庫.否則必需要其他庫檔案才能運行,在單一個linux核心不能使他正常工作。
(2) 這個選項也一定要選,否則make install後,busybox將安裝在原系統的/usr下,這將覆蓋掉系統原有的命令.選擇這個選項後,make install後會在busybox目錄下產生一個叫_install的目錄,裡面有busybox和指向他的連結.
(3) 如果沒有啟動udev,造成/dev下沒有裝置檔案。也就是說所有的裝置都沒有掛接進來。最新的busybox已經包含了udev的簡化版本即mdev,且使用非常簡單。 要使用mdev還需要在rootfs中做適當配置。
vi rootfs/etc/init.d/rcS
---------------------------
mount -t tmpfs mdev /dev
mkdir /dev/pts
mount -t devpts devpts /dev/pts
mount -t sysfs sysfs /sys
mount -a
echo /sbin/mdev > /proc/sys/kernel/hotplug
mdev -s
配置linux kernel
-----------------------------------------------
mdev需要改寫/dev和/sys兩個目錄。所以必須保證這兩個目錄是可寫的(一般會用到sysfs,tmpfs。所以要重新編譯核心)。然後在你的啟動指令檔中加入/sbin/mdev -s
linux-2.6.19 -- make menuconfig
File systems --->
Pseudo filesystems --->
[*] sysfs file system support
[*] Virtual memory file system support (former shm fs)
[*] Tmpfs POSIX Access Control Lists
(4) 由於ash功能不夠強大,不能支援tab補齊,曆史紀錄等等的進階功能,所以使用busybox裡面的msh代替ash.
因為busybox主要應用於對空間要求非常嚴格的嵌入式系統,所以它推薦使用uclibc而不鼓勵使用glibc,如果你沒有安裝uclibc,而且在 build Options也選擇了Build BusyBox as a static binary(no shared libs),那肯定無法編譯通過的,當然如果你之前build Options選擇的是動態編譯的話就不會有這樣的問題出現了。假設你是第一種情況,我們可以這樣解決:把applets/applets.c開頭的幾行 warning注釋掉
# vi applets/applets.c
/*
#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
#warning Static linking against glibc produces buggy executables
#warning (glibc does not cope well with ld --gc-sections).
#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
#warning Note that glibc is unsuitable for static linking anyway.
#warning If you still want to do it, remove -Wl,--gc-sections
#warning from top-level Makefile and remove this warning.
#error Aborting compilation.
#endif
*/
# make
# make install
這時會在你的編譯目錄下產生一個_install的目錄,裡麵包含了產生的所有檔案和目錄結構。
編譯時間遇到的問題(1):
-----------------------------------------------
如果busybox編譯成static linking
Busybox Settings --->
Build Options --->
[*] Build BusyBox as a static binary (no shared libs)
# make
將會遇到下面問題:
applets/applets.c:20:2: error: #warning Static linking against glibc produces buggy executables
applets/applets.c:21:2: error: #warning (glibc does not cope well with ld --gc-sections).
applets/applets.c:22:2: error: #warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400
applets/applets.c:23:2: error: #warning Note that glibc is unsuitable for static linking anyway.
applets/applets.c:24:2: error: #warning If you still want to do it, remove -Wl,--gc-sections
applets/applets.c:25:2: error: #warning from top-level Makefile and remove this warning.
make[1]: *** [applets/applets.o] Error 1
這個警告的定義在applets/applets.c中。將這段警告注釋掉就可以了。這段警告的意思是告訴你最好用uclibc編譯,而不是用glibc因為glibc比較大,busybox在寸土寸金的嵌入式系統中運用比較多,所以會有這樣的要求。
# vi /busybox-1.7.0/applets/applets.c +20
注釋掉20 -- 28行內容即可
miscutils/taskset.c:17: error: parse error before '*' token
-----------------------------------------------
最根本的解決辦法是換一個libc庫,可是現在還不知道哪個庫最合適,唯有暫時將有問題的命令關掉
Miscellaneous Utilities --->
[ ] taskset
[ ]各式各樣的
runit/runsv.c: In function `gettimeofday_ns':
-----------------------------------------------
Runit Utilities --->
[ ] runsv
核心啟動時遇到的問題:
-----------------------------------------------
“could not run '/bin/sh': No such file or directory”
解決方案:
要這樣配置:
Shells --->
Choose your default shell (ash) --->
如果是這樣配置的話,雖然可以產生ash,但不能產生sh,將會在核心啟動時出現上面出現的問題:
Shells --->
Choose your default shell (none) --->
[*] ash