blob: 82958a88643b5d4b1d815694bcaae89b18107cfd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
#!/bin/bash
# 由 busybox 创建一个最小的文件系统 | 不含编译部分
# 创建目录并拷贝文件
set -e
set -x
cp ./.config_busybox ../miniroot
cp ./init_busybox ../miniroot
cd .. || exit
# 工作目录改动到 miniroot
cd miniroot
if [ -e "./busybox" ]; then
read -r -t 10 -p "./busybox\" 已存在,是否删除? (回车确认,其他键取消,10s 超时)" confirm
if [[ $confirm == "" ]]; then
rm -rf "./busybox/*"
else
exit 1
fi
fi
# 如果 busybox 不存在则下载
if [ ! -e "./busybox-1.36.1.tar.bz2" ]; then
wget https://busybox.net/downloads/busybox-1.36.1.tar.bz2
fi
if [ ! -e "./busybox-1.36.1" ]; then
tar -xjf busybox-1.36.1.tar.bz2
fi
cd busybox-1.36.1
if [ ! -e "./build" ]; then
mkdir build
fi
# make O=build menuconfig
# 在 settings Build Options 中选择 # [*] Build static binary (no sharedd libs)
if [ ! -e "./build/.config" ]; then
mv ../.config_busybox ./build/.config
fi
if [ -z "$(ls -A build/_install/)" ]; then
# build/_install/ is empty"
cd build
make -j8 V=1
make install
fi
cd .. || exit
mkdir -pv busybox
cd busybox || exit
mkdir -pv {bin,sbin,etc,proc,sys,usr/{bin,sbin}}
cp -av ../busybox-1.36.1/build/_install/* .
# 写入 init 文件并设置权限
mv ../init_busybox init
chroot . /bin/sh -c "chmod u+x /init" # 可能需要 sudo
echo "最小化 Busybox 系统创建成功!"
# 打包文件系统
if read -r -t 10 -p "打包镜像? (10秒 超时取消)" confirm; then
find . -print0 | cpio --null -ov --format=newc | gzip -9 >../busybox.cpio.gz
echo "打包完毕"
else
echo "取消打包"
fi
|