1#!/bin/bash 2grub_dir_i386_efi=arch/i386/efi/grub 3grub_dir_i386_legacy=arch/i386/legacy/grub 4grub_dir_x86_64_efi=arch/x86_64/efi/grub 5 6mkdir -p ${grub_dir_i386_efi} 7mkdir -p ${grub_dir_i386_legacy} 8mkdir -p ${grub_dir_x86_64_efi} 9 10 11#检测grub是否已经安装 12if [ -d ${grub_dir_i386_efi}/bin ] || [ -d ${grub_dir_i386_legacy}/bin ] && [ -d ${grub_dir_x86_64_efi}/bin ] ; then 13 exit 0 14fi 15#仅支持Ubuntu/Debain下的自动安装 16if ! hash 2>/dev/null apt-get; then 17 echo "脚本暂不支持对该系统下grub的安装,请手动完成" 18 exit 0 19fi 20#下载grub2.06 21if [ ! -f "grub-2.06.tar.xz" ]; then 22 wget https://mirrors.tuna.tsinghua.edu.cn/gnu/grub/grub-2.06.tar.xz || exit 1 23fi 24 25echo "开始下载grub2.06" 26 27echo "下载完成" 28tar xvf grub-2.06.tar.xz 29#安装对应依赖 30sudo apt-get update 31sudo apt-get install -y \ 32 make \ 33 binutils \ 34 bison \ 35 gcc \ 36 gettext \ 37 flex \ 38 bison \ 39 automake \ 40 autoconf 41 42cd grub-2.06 43echo "开始安装grub2.06" 44#编译安装三个版本的grub 45./configure --target=i386 --prefix=$(dirname $PWD)/${grub_dir_i386_legacy} || exit 1 46make -j $(nproc) || exit 1 47make install || exit 1 48make clean || exit 1 49 50./configure --target=i386 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_i386_efi} || exit 1 51make -j $(nproc) || exit 1 52make install || exit 1 53make clean || exit 1 54 55./configure --target=x86_64 --with-platform=efi --prefix=$(dirname $PWD)/${grub_dir_x86_64_efi} || exit 1 56make -j $(nproc) || exit 1 57make install || exit 1 58 59cd .. 60#解除权限限制 61sudo chmod -R 777 ${grub_dir_i386_legacy} 62sudo chmod -R 777 ${grub_dir_i386_efi} 63sudo chmod -R 777 ${grub_dir_x86_64_efi} 64rm -rf grub-2.06 65rm grub-2.06.tar.xz* 66echo "grub2.06安装完成" 67