调整编译grub的脚本的部分 (#108)

1、bugfix: 修复编译grub的脚本的部分错误
2、将grub下载源替换为tuna
3、优化写入磁盘镜像的脚本
4、将bios文件夹改名为legacy
This commit is contained in:
login 2022-12-14 20:01:55 +08:00 committed by GitHub
parent 38b341b8aa
commit d02e6ea411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 49 deletions

3
.gitignore vendored
View File

@ -1,8 +1,5 @@
/cmake-build-debug/ /cmake-build-debug/
/bin/ /bin/
tools/arch/i386/bios/grub/*
tools/arch/i386/efi/grub/*
tools/arch/x86_64/efi/grub/*
!.gitkeep !.gitkeep
DragonOS.iso DragonOS.iso
.idea/ .idea/

5
tools/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
grub-2.06.tar.xz*
grub-2.06/
arch/i386/legacy/grub/*
arch/i386/efi/grub/*
arch/x86_64/efi/grub/*

View File

@ -1,3 +0,0 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

View File

@ -1,3 +0,0 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

View File

View File

@ -1,3 +0,0 @@
# Ignore everything in this directory
*
# Except this file !.gitkeep

View File

@ -1,12 +1,15 @@
#!/bin/bash #!/bin/bash
grub_dir_i386_efi=arch/i386/efi/grub grub_dir_i386_efi=arch/i386/efi/grub
grub_dir_i386_bios=arch/i386/bios/grub grub_dir_i386_legacy=arch/i386/legacy/grub
grub_dir_x86_64_efi=arch/x86_64/efi/grub grub_dir_x86_64_efi=arch/x86_64/efi/grub
#编译核心数目
nproc=8 mkdir -p ${grub_dir_i386_efi}
mkdir -p ${grub_dir_i386_legacy}
mkdir -p ${grub_dir_x86_64_efi}
#检测grub是否已经安装 #检测grub是否已经安装
if [ -d ${grub_dir_i386_efi}/bin ] || [ -d ${grub_dir_i386_bios}/bin ] || [ -d ${grub_dir_x86_64_efi}/bin ] ; then if [ -d ${grub_dir_i386_efi}/bin ] || [ -d ${grub_dir_i386_legacy}/bin ] && [ -d ${grub_dir_x86_64_efi}/bin ] ; then
exit 0 exit 0
fi fi
#仅支持Ubuntu/Debain下的自动安装 #仅支持Ubuntu/Debain下的自动安装
@ -15,45 +18,49 @@ if ! hash 2>/dev/null apt-get; then
exit 0 exit 0
fi fi
#下载grub2.06 #下载grub2.06
if [ ! -f "grub-2.06.tar.xz" ]; then
wget https://mirrors.tuna.tsinghua.edu.cn/gnu/grub/grub-2.06.tar.xz || exit 1
fi
echo "开始下载grub2.06" echo "开始下载grub2.06"
wget https://ftp.gnu.org/gnu/grub/grub-2.06.tar.gz
echo "下载完成" echo "下载完成"
tar -xvzf grub-2.06.tar.gz tar xvf grub-2.06.tar.xz
#安装对应依赖 #安装对应依赖
sudo apt-get update sudo apt-get update
sudo apt-get install -y \ sudo apt-get install -y \
make \ make \
binutils \ binutils \
bison \ bison \
gcc \ gcc \
gettext \ gettext \
flex\ flex \
bison\ bison \
automake\ automake \
autoconf\ autoconf
cd grub-2.06 cd grub-2.06
echo "开始安装grub2.06" echo "开始安装grub2.06"
#编译安装三个版本的grub #编译安装三个版本的grub
./configure --target=i386 --prefix=$(dirname $PWD)/${grub_dir_i386_bios} ./configure --target=i386 --prefix=$(dirname $PWD)/${grub_dir_i386_legacy} || exit 1
make -j $(nporc) make -j $(nproc) || exit 1
make install make install || exit 1
make clean make clean || exit 1
./configure --target=i386 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_i386_efi} ./configure --target=i386 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_i386_efi} || exit 1
make -j $(nporc) make -j $(nproc) || exit 1
make install make install || exit 1
make clean make clean || exit 1
./configure --target=x86_64 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_x86_64_efi} ./configure --target=x86_64 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_x86_64_efi} || exit 1
make -j $(nporc) make -j $(nproc) || exit 1
make install make install || exit 1
cd .. cd ..
#解除权限限制 #解除权限限制
sudo chmod -R 777 ${grub_dir_i386_bios} sudo chmod -R 777 ${grub_dir_i386_legacy}
sudo chmod -R 777 ${grub_dir_i386_efi} sudo chmod -R 777 ${grub_dir_i386_efi}
sudo chmod -R 777 ${grub_dir_x86_64_efi} sudo chmod -R 777 ${grub_dir_x86_64_efi}
rm -rf grub-2.06 rm -rf grub-2.06
rm grub-2.06.tar.gz rm grub-2.06.tar.xz*
echo "grub2.06安装完成" echo "grub2.06安装完成"

View File

@ -22,13 +22,13 @@ echo "开始写入磁盘镜像..."
# toolchain # toolchain
OS=`uname -s`
if [ "${OS}" == "Linux" ]; then GRUB_PATH_I386_LEGACY_INSTALL=${root_folder}/tools/arch/i386/legacy/grub/sbin/grub-install
GRUB_PATH="$(dirname $(which grub-file))" GRUB_PATH_I386_EFI_INSTALL=${root_folder}/tools/arch/i386/efi/grub/sbin/grub-install
elif [ "${OS}" == "Darwin" ]; then GRUB_PATH_X86_64_EFI_INSTALL=${root_folder}/tools/arch/x86_64/efi/grub/sbin/grub-install
GRUB_PATH="${root_folder}/tools/grub-2.06/build/grub/bin"
fi GRUB_PATH_I386_LEGACY_FILE=${root_folder}/tools/arch/i386/legacy/grub/bin/grub-file
export PATH="${GRUB_PATH}:$PATH"
# ==============检查文件是否齐全================ # ==============检查文件是否齐全================
@ -45,7 +45,7 @@ done
# 如果是 i386/x86_64需要判断是否符合 multiboot2 标准 # 如果是 i386/x86_64需要判断是否符合 multiboot2 标准
if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
if ${GRUB_PATH}/grub-file --is-x86-multiboot2 ${kernel}; then if ${GRUB_PATH_I386_LEGACY_FILE} --is-x86-multiboot2 ${kernel}; then
echo Multiboot2 Confirmed! echo Multiboot2 Confirmed!
else else
echo NOT Multiboot2! echo NOT Multiboot2!
@ -108,13 +108,13 @@ case "$1" in
case "$2" in case "$2" in
uefi) #uefi uefi) #uefi
if [ ${ARCH} == "i386" ];then if [ ${ARCH} == "i386" ];then
./arch/i386/efi/grub/sbin/grub-install --target=i386-efi --efi-directory=${mount_folder} --boot-directory=${boot_folder} --removable ${GRUB_PATH_I386_EFI_INSTALL} --target=i386-efi --efi-directory=${mount_folder} --boot-directory=${boot_folder} --removable
elif [ ${ARCH} == "x86_64" ];then elif [ ${ARCH} == "x86_64" ];then
./arch/x86_64/efi/grub/sbin/grub-install --target=x86_64-efi --efi-directory=${mount_folder} --boot-directory=${boot_folder} --removable ${GRUB_PATH_X86_64_EFI_INSTALL} --target=x86_64-efi --efi-directory=${mount_folder} --boot-directory=${boot_folder} --removable
fi fi
;; ;;
legacy) #传统bios legacy) #传统bios
./arch/i386/bios/grub/sbin/grub-install --target=i386-pc --boot-directory=${boot_folder} /dev/$LOOP_DEVICE ${GRUB_PATH_I386_LEGACY_INSTALL} --target=i386-pc --boot-directory=${boot_folder} /dev/$LOOP_DEVICE
;; ;;
esac esac
;; ;;