74 lines
1.6 KiB
Bash
Executable File
74 lines
1.6 KiB
Bash
Executable File
#!/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
|