定制最小linux系统 - 2: 编译busybox

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq85058522

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值