fixed some issue about bootloader

This commit is contained in:
superconvert 2022-07-31 00:01:00 +08:00
parent a226dd0e9f
commit 4ec6d3e1b8
4 changed files with 42 additions and 28 deletions

View File

@ -7,6 +7,8 @@ busybox_install=`pwd`"/work/busybox_install"
libgcc_install=`pwd`"/work/libgcc_install"
binutils_install=`pwd`"/work/binutils_install"
export CFLAGS="-Os -s -fno-stack-protector -fomit-frame-pointer -U_FORTIFY_SOURCE"
#-----------------------------------------------
#
# 重新生成目标文件
@ -67,7 +69,8 @@ if [ ! -f "linux-4.14.9.tar.xz" ]; then
wget $KERNEL_SOURCE_URL
fi
GLIBC_SOURCE_URL=https://ftp.gnu.org/gnu/glibc/glibc-2.32.tar.bz2
#GLIBC_SOURCE_URL=https://ftp.gnu.org/gnu/glibc/glibc-2.32.tar.bz2
GLIBC_SOURCE_URL=https://mirrors.ustc.edu.cn/gnu/glibc/glibc-2.32.tar.bz2
if [ ! -f "glibc-2.32.tar.bz2" ]; then
wget $GLIBC_SOURCE_URL
fi
@ -77,12 +80,14 @@ if [ ! -f "busybox-1.34.1.tar.bz2" ]; then
wget $BUSYBOX_SOURCE_URL
fi
GCC_SOURCE_URL=https://ftpmirror.gnu.org/gcc/gcc-7.5.0/gcc-7.5.0.tar.xz
#GCC_SOURCE_URL=https://ftpmirror.gnu.org/gcc/gcc-7.5.0/gcc-7.5.0.tar.xz
GCC_SOURCE_URL=https://mirrors.ustc.edu.cn/gnu/gcc/gcc-7.5.0/gcc-7.5.0.tar.xz
if [ ! -f "gcc-7.5.0.tar.xz" ]; then
wget $GCC_SOURCE_URL
fi
BINUTILS_SOURCE_URL=https://ftp.gnu.org/gnu/binutils/binutils-2.36.tar.xz
#BINUTILS_SOURCE_URL=https://ftp.gnu.org/gnu/binutils/binutils-2.36.tar.xz
BINUTILS_SOURCE_URL=https://mirrors.ustc.edu.cn/gnu/binutils/binutils-2.36.tar.xz
if [ ! -f "binutils-2.36.tar.xz" ]; then
wget $BINUTILS_SOURCE_URL
fi
@ -130,10 +135,11 @@ cd work
# 编译内核, 最终所有模块都装到目录 /lib/modules/4.14.9
if [ ! -d "kernel_install" ]; then
mkdir -pv kernel_install && cd linux-4.14.9 && make mrproper
mkdir -pv kernel_install && cd linux-4.14.9 && make mrproper && make x86_64_defconfig
# Enable the VESA framebuffer for graphics support.
sed -i "s/.*CONFIG_FB_VESA.*/CONFIG_FB_VESA=y/" .config
# 网络需要 TUN/TAP 驱动 [ Device Drivers ] ---> [ Network device support ] ---> [ Universal TUN/TAP device driver support ]
make x86_64_defconfig && sed -i "s/.*CONFIG_FB_VESA.*/CONFIG_FB_VESA=y/" .config && make bzImage -j8
make bzImage -j8
#cd linux-4.14.9 && make x86_64_defconfig && make bzImage -j8 && make modules && make modules_install && cd ..
make INSTALL_HDR_PATH=${kernel_install} headers_install -j8 && cp arch/x86_64/boot/bzImage ${kernel_install} && cd ..
fi
@ -142,11 +148,13 @@ fi
if [ ! -d "glibc_install" ]; then
mkdir -pv glibc_install && cd glibc-2.32
mkdir -pv build && cd build && make distclean
../configure --prefix= \
--with-headers=${kernel_install}/include/ \
--without-gd \
../configure --prefix=/usr \
--with-headers=${kernel_install}/include \
--enable-kernel=4.0.1 \
--without-selinux \
--disable-werror
--disable-werror \
--disable-werror \
CFLAGS="$CFLAGS"
make -j8 && make install -j8 DESTDIR=${glibc_install} && cd .. && cd ..
fi
@ -155,7 +163,7 @@ if [ ! -d "busybox_install" ]; then
mkdir -pv busybox_install && cd busybox-1.34.1 && make distclean && make defconfig
# 静态编译 sed -i "s/# CONFIG_STATIC is not set/CONFIG_STATIC=y/g" .config
sed -i "s|.*CONFIG_SYSROOT.*|CONFIG_SYSROOT=\"${glibc_install}\"|" .config
sed -i "s|.*CONFIG_EXTRA_CFLAGS.*|CONFIG_EXTRA_CFLAGS=\"$CFLAGS -I${kernel_install}/include -I${glibc_install}/include -L${glibc_install}/lib\"|" .config
sed -i "s|.*CONFIG_EXTRA_CFLAGS.*|CONFIG_EXTRA_CFLAGS=\"-I${kernel_install}/include -I${glibc_install}/include -L${glibc_install}/usr/lib64 $CFLAGS\"|" .config
make busybox -j8 && make CONFIG_PREFIX=${busybox_install} install && cd ..
fi
@ -163,15 +171,15 @@ fi
if [ ! -d "libgcc_install" ]; then
mkdir -pv libgcc_install && cd gcc-7.5.0 && make distclean && rm ./config.cache
./contrib/download_prerequisites
./configure --prefix= --enable-languages=c,c++ --disable-multilib --disable-static --disable-libquadmath --enable-shared
CFLAGS="-L${glibc_install}/lib $CFLAGS" make -j8 && make install -j8 DESTDIR=${libgcc_install} && cd ..
./configure --prefix=/usr --enable-languages=c,c++ --disable-multilib --disable-static --disable-libquadmath --enable-shared
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${libgcc_install} && cd ..
fi
# 编译 binutils
if [ ! -d "binutils_install" ]; then
mkdir -pv binutils_install && cd binutils-2.36 && make distclean
./configure --prefix=
CFLAGS="-L${glibc_install}/lib $CFLAGS" make -j8 && make install -j8 DESTDIR=${binutils_install} && cd ..
./configure --prefix=/usr
CFLAGS="-L${glibc_install}/lib64 $CFLAGS" make -j8 && make install -j8 DESTDIR=${binutils_install} && cd ..
cd ..
fi

View File

@ -23,7 +23,7 @@ with_gcc=$1
# 进行目录瘦身
#
#----------------------------------------------
./mk_strip.sh
#./mk_strip.sh
#----------------------------------------------
#
@ -33,7 +33,7 @@ with_gcc=$1
echo "${CYAN}--- build disk --- ${NC}"
# 创建磁盘 64M
if [ ! -n "${with_gcc}" ]; then
dd if=/dev/zero of=disk.img bs=1M count=64
dd if=/dev/zero of=disk.img bs=1M count=256
else
dd if=/dev/zero of=disk.img bs=1M count=512
fi
@ -67,6 +67,7 @@ grub-install --boot-directory=${diskfs}/boot/ --target=i386-pc --modules=part_ms
# 制作内核和 rootfs
#
#---------------------------------------------
rm -rf rootfs
mkdir -pv rootfs
mkdir -pv rootfs/dev
mkdir -pv rootfs/etc
@ -86,18 +87,22 @@ cp work/kernel_install/bzImage ${diskfs}/boot/bzImage
# 拷贝 glibc 到 rootfs
cp work/glibc_install/* rootfs/ -r
rm -rf rootfs/lib/*.a
rm -rf rootfs/lib/gconv
rm -rf rootfs/bin/*
rm -rf rootfs/share
rm -rf rootfs/var/db
# 编译的镜像带有 gcc 编译器
if [ ! -n "${with_gcc}" ]; then
rm -rf rootfs/include
echo "without-gcc tools."
#rm -rf rootfs/include
else
echo "${RED} with-gcc tools --- you can build your world${NC}"
cp work/glibc_install/lib/libc_nonshared.a rootfs/lib
#cp work/glibc_install/lib/libc_nonshared.a rootfs/lib
fi
#----------------------------------------------------------------------
# 这个解释器必须设置对,否则系统会启动时 crash, 导致启动失败 !!!!!!
#-----------------------------------------------------------------------
ln -s /lib/ld-2.32.so rootfs/lib64/ld-linux-x86-64.so.2
# 拷贝 busybox 到 rootfs
cp work/busybox_install/* rootfs/ -r
@ -191,16 +196,16 @@ if [ "${with_gcc}" ]; then
cp work/libgcc_install/* ${diskfs} -r
cp work/binutils_install/* ${diskfs} -r
fi
rm -rf ${diskfs}/init ${diskfs}/linuxrc ${diskfs}/lost+found ${diskfs}/share
rm -rf ${diskfs}/init ${diskfs}/linuxrc ${diskfs}/lost+found
# 我们测试驱动, 制作的镜像启动后,我们进入此目录 insmod hello_world.ko 即可
./make_driver.sh $(pwd)/${diskfs}/lib/modules
./mk_drv.sh $(pwd)/${diskfs}/lib/modules
# 编译网卡驱动 ( 目前版本内核已集成 e1000 )
# cd work/linux-4.14.9 && make M=drivers/net/ethernet/intel/e1000/ && cd ../..
# 生成 grub.cfg 文件
# 生成 grub.cfg 文件, 增加 console=ttyS0 就会让 qemu 输出日志到 qemu.log
cat - > ${diskfs}/boot/grub/grub.cfg << EOF
set timeout=6
set timeout=3
menuentry "smart-os" {
root=(hd0,msdos1)
linux /boot/bzImage console=tty0

View File

@ -74,8 +74,9 @@ stop_dns() {
#----------------------------------------------
start_nat
rm -rf ./qemu.log
# 启动镜像 网络对应 run_nat.sh 里面的配置
qemu-system-x86_64 -drive format=raw,file=disk.img -netdev tap,id=nd0,ifname=tap0 -device e1000,netdev=nd0
qemu-system-x86_64 -serial file:./qemu.log -drive format=raw,file=disk.img -netdev tap,id=nd0,ifname=tap0 -device e1000,netdev=nd0
# stop nat
stop_nat
@ -85,6 +86,6 @@ stop_nat
# 多硬盘测试 -hdb extra.img
#
#----------------------------------------------------
# make_sdb.sh
# ./mk_sdb.sh
# qemu-system-x86_64 -drive format=raw,file=disk.img -hdb extra.img

View File

@ -10,7 +10,7 @@ losetup -o 1048576 ${loop_dev} disk.img
mkdir -p ./tmp_docker
mount -t ext3 ${loop_dev} ./tmp_docker
cd ./tmp_docker
tar -cvpf ../${dock_name}.tar --directory=./ --exclude=proc --exclude=sys --exclude=dev --exclude=run --exclude=boot .
tar -cpf ../${dock_name}.tar --directory=./ --exclude=proc --exclude=sys --exclude=dev --exclude=run --exclude=boot .
cd ..
umount ./tmp_docker
rm -rf ./tmp_docker