首先下载 Busybox
https:
根据自己的工具链下载最新的版本, 例如: glibc = 2.18 最多兼容到 busybox- 1.35
修改busybox的Makefile指定处理器架构和交叉编译器
cp busybox- 1. xx. x. tar. bz2 / opt/
cd / opt/
tar - xvf busybox- 1. xx. x. tar. bz2
cd / opt/ busybox- 1. xx. x 进入busybox源码根目录
vim Makefile 修改下makefile
配置交叉编译器: CROSS_COMPILE = arm- xxx- linux- xxx- 可以不配, 使用 make CROSS_COMPILE = arm- xxx- linux- xxx-
配置平台: ARCH = arm 可以不配, 会从CROSS_COMPILE 里推算
编译
cd / opt/ busybox- 1. xx. x
make menuconfig 图形配置选择组件特性, 这里默认不变, 选择保存, 或者 make defconfig
make 编译
安装
make install
ls / opt/ busybox- 1. xx. x/ _install 查看编译生成的二进制文件内容
bin sbin usr linuxrc 查看是否有三个目录 和一个文件
追加 etc dev sys proc home var temp lib 空目录 不是每个都要先全加了就好
复制busybox动态库
arm- xxx- linux- xxx- readelf - d / opt/ busybox- 1. xx. x/ _install/ bin/ busybox 执行依赖查看命令
Tag Type Name/ Value
0x00000001 ( NEEDED) Shared library: [ libm. so. 6 ]
0x00000001 ( NEEDED) Shared library: [ libresolv. so. 2 ]
0x00000001 ( NEEDED) Shared library: [ libc. so. 6 ]
根据 NEEDED 描述知道需要 libm. so. 6 和 libc. so. 6 . . 等库
找到文件, 一般在 / 工具链目录/ sysroot/ lib , 可在工具链里用 find 查找
cd / 工具链目录/ . . / sysroot/ lib
ls . / libc. so. 6 - lh 查看文件
输出: / 工具链目录/ . . / sysroot/ lib/ libc. so. 6 -> libc- 2.18 - 2013.10 . so 可以看到这个是链接文件, 两个文件都要复制
cp / 工具链目录/ . . / sysroot/ lib/ libc. so. 6 / opt/ busybox- 1. xx. x/ _install/ lib - d 复制 libc. so. 6 到文件系统
cp / 工具链目录/ . . / sysroot/ lib/ libc- 2.18 - 2013.10 . so / opt/ busybox- 1. xx. x/ _install/ lib - d 复制 libc- 2.18 - 2013.10 . so 到文件系统
三个文件同样处理. . .
复制动态链接功能的依赖
cp / 工具链目录/ . . / sysroot/ lib/ ld- * / opt/ busybox- 1. xx. x/ _install/ lib - d
### 添加系统启动的必要配置文件 和 系统启动的脚本文件
vim / opt/ busybox- 1. xx. x/ _install/ etc/ inittab 打开添加如下内容:
:: sysinit: / etc/ init. d/ rcS
:: respawn: - / bin/ sh
保存退出
mkdir/ opt/ busybox- 1. xx. x/ _install/ etc/ init. d/
vim / opt/ busybox- 1. xx. x/ _install/ etc/ init. d/ rcS
mount - a #当执行此命令, 系统自动解析执行根文件系统/ etc/ fstab文件
echo / sbin/ mdev > / proc/ sys/ kernel/ hotplug #向hotplug写入字符串/ sbin/ mdev, 跟驱动自动挂载有关
mdev - s
保存退出
chmod 777 / opt/ busybox- 1. xx. x/ _install/ etc/ init. d/ rcS 给脚本添加可执行权限
向根文件系统rootfs的etc添加系统启动必要配置文件fstab
vim/ opt/ busybox- 1. xx. x/ _install/ etc/ fstab 添加三句必要配置命令
proc / proc proc defaults 0 0
sysfs / sys sysfs defaults 0 0
tmpfs / dev tmpfd defaults 0 0
保存
精简根文件系统rootfs,缩减体积
动态库进行精简体积: 去掉符号和调试信息
arm- xxx- linux- xxx- strip / opt/ busybox- 1. xx. x/ _install/ lib
全部完成, 复制文件夹到NFS网络目录, 或者打包到镜像
cp / opt/ busybox- 1. xx. x/ _install / opt/ nfs/ rootfs - frd
运行效果