交叉编译器: 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 +176ARCH ?= armCROSS_COMPILE ?= /usr/local/arm/3.3.2/bin/arm-linux-# make menuconfigBusybox 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/removalShells ---> 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 /devmkdir /dev/ptsmount -t devpts devpts /dev/ptsmount -t sysfs sysfs /sysmount -aecho /sbin/mdev > /proc/sys/kernel/hotplugmdev -s配置linux kernel----------------------------------------------- mdev需要改写/dev和/sys两个目录。所以必须保证这两个目录是可写的(一般会用到sysfs,tmpfs。所以要重新编译内核)。然后在你的启动脚本文件中加入/sbin/mdev -slinux-2.6.19 -- make menuconfigFile 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 linkingBusybox 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 executablesapplets/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=3400applets/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-sectionsapplets/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 ---> [ ] tasksetrunit/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