构建根文件系统之瑞士军刀BusyBox

BusyBox是最常用的定制根文件系统的方法,它能够迅速建立一套相对完整、功能丰富的文件系统,其中包括大量常用的用程序。Busybox再设计上充分考虑到了硬件的资源受限的特殊工作环境,采用了将所有的命令通过软连接的方法指向自己的方法来减自己的体积。

1. 准备环境

1.1 下载BusyBox源码

1.2 建立工程目录

root@chy-pc:/opt# tree ./arm/
./arm/
├── busybox-1.26.2.tar.bz2
└── rootfs


2 编译BusyBox

2.1 BusyBox解压到/opt/arm/

root@chy-pc:/opt/arm# tar -jxvf ./busybox-1.26.2.tar.bz2

2.2 修改Makefile

root@chy-pc:/opt/arm/busybox-1.26.2# vim ./Makefile
查找到
CROSS_COMPILE ?=
修改为
CROSS_COMPILE ?= arm-linux-

查找到ARCH ?=
修改为
ARCH ?= arm

2.3 配置BusyBox

root@chy-pc:/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

root@chy-pc:/opt/arm/busybox-1.26.2# make
root@chy-pc:/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 





  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值