Busybox是Linux界的瑞士军刀, 只有1-2M, 包含了大部分Linux常用命令.
嵌入式Linux/Android一般都使用busybox构建最小的运行环境.
安装依赖
sudo apt install build-essential libncurses5-dev tree wget -y
下载
cd ~/code
wget https://busybox.net/downloads/busybox-1.36.1.tar.bz2
tar xf busybox-1.36.1.tar.bz2
配置
cd busybox-1.36.1
make menuconfig
Settings
-> Build static binary (no shared libs)
编译
make install -j8
file _install/bin/busybox
## 以下为输出内容
>> busybox: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.2.0
文件系统添加:
cd _install
mkdir -p dev proc sys etc/init.d
sudo cp -a /dev/{null,console,tty,tty1,tty2,tty3,tty4} dev/
echo -e "mdev -s" > etc/init.d/rcS
touch init
chmod +x init etc/init.d/rcS
init文件写入以下内容
#!/bin/busybox sh
mount -t proc none /proc
mount -t sysfs none /sys
exec /sbin/init
建立rootfs镜像
find . -print0 | cpio --null -ov --format=newc > ../rootfs.cpio
到这里, 编译busybox并生成了最小根文件系统, 位于: ~/code/busybox-1.36.1/rootfs.cpio