Update 03_build_disk.sh

This commit is contained in:
superconvert 2022-07-25 07:26:06 +08:00 committed by GitHub
parent 0c08b00667
commit 41a7b5485f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,33 +48,11 @@ mount -t ext3 ${loop_dev} ${diskfs}
# 安装grub 引导 # 安装grub 引导
grub-install --boot-directory=${diskfs}/boot/ --target=i386-pc --modules=part_msdos disk.img grub-install --boot-directory=${diskfs}/boot/ --target=i386-pc --modules=part_msdos disk.img
#----------------------------------------------
#
# 下载源码
#
#----------------------------------------------
mkdir -pv source
cd source
#KERNEL_SOURCE_URL=https://kernel.org/pub/linux/kernel/v4.x/linux-4.14.9.tar.xz
KERNEL_SOURCE_URL=https://mirror.bjtu.edu.cn/kernel/linux/kernel/v4.x/linux-4.14.9.tar.xz
if [ ! -f "linux-4.14.9.tar.xz" ]; then
wget $KERNEL_SOURCE_URL
fi
BUSYBOX_SOURCE_URL=https://busybox.net/downloads/busybox-1.34.1.tar.bz2
if [ ! -f "busybox-1.34.1.tar.bz2" ]; then
wget $BUSYBOX_SOURCE_URL
fi
cd ..
#--------------------------------------------- #---------------------------------------------
# #
# 制作内核和 rootfs # 制作内核和 rootfs
# #
#--------------------------------------------- #---------------------------------------------
mkdir -pv work
mkdir -pv rootfs mkdir -pv rootfs
mkdir -pv rootfs/dev mkdir -pv rootfs/dev
mkdir -pv rootfs/etc mkdir -pv rootfs/etc
@ -88,37 +66,12 @@ mkdir -pv rootfs/root
mkdir -pv rootfs/lib64 mkdir -pv rootfs/lib64
mkdir -pv rootfs/lib/modules mkdir -pv rootfs/lib/modules
if [ ! -d "./work/linux-4.14.9" ]; then
tar xvf source/linux-4.14.9.tar.xz -C work/
fi
if [ ! -d "./work/busybox-1.34.1" ]; then
tar xvf source/busybox-1.34.1.tar.bz2 -C work/
fi
cd work
# 编译内核, 最终所有模块都装到目录 /lib/modules/4.14.9
if [ ! -f "./linux-4.14.9/arch/x86_64/boot/bzImage" ]; then
# Enable the VESA framebuffer for graphics support.
# 网络需要 TUN/TAP 驱动 [ Device Drivers ] ---> [ Network device support ] ---> [ Universal TUN/TAP device driver support ]
cd linux-4.14.9 && make x86_64_defconfig && sed -i "s/.*CONFIG_FB_VESA.*/CONFIG_FB_VESA=y/" .config && make bzImage -j8 && cd ..
#cd linux-4.14.9 && make x86_64_defconfig && make bzImage -j8 && make modules && make modules_install && cd ..
fi
# 拷贝内核镜像 # 拷贝内核镜像
cp linux-4.14.9/arch/x86_64/boot/bzImage ../${diskfs}/boot/bzImage cp work/linux-4.14.9/arch/x86_64/boot/bzImage ../${diskfs}/boot/bzImage
# 编译 busybox
if [ ! -d "./busybox-1.34.1/_install" ]; then
# 静态编译 sed -i "s/# CONFIG_STATIC is not set/CONFIG_STATIC=y/g" .config
cd busybox-1.34.1 && make defconfig && make -j8 && make install && cd ..
fi
# 拷贝 busybox 到 rootfs # 拷贝 busybox 到 rootfs
echo "${CYAN}开始制作rootfs...${NC}" echo "${CYAN}开始制作rootfs...${NC}"
cp busybox-1.34.1/_install/* ../rootfs/ -r cp work/busybox-1.34.1/_install/* ../rootfs/ -r
cd ..
#----------------------------------------------- #-----------------------------------------------
# #
@ -279,4 +232,4 @@ echo ".........................................................."
# 卸载映射 # 卸载映射
umount ${loop_dev} umount ${loop_dev}
losetup -d ${loop_dev} losetup -d ${loop_dev}