grub定制启动菜单

原文链接:https://www.amder.club/thread-994-1-1.html
UEFI启动方式定制:
从我的网盘下载 “SurfacePro3-GRUB2启动文件”或者“MacBook-GRUB2启动文件”(其实两个文件除了GRUB启动菜单配置有区别,其它都是一样的),解压得到Boot文件夹,然后根据各自的具体情况用记事本修改配置文件/Boot/grub/grub.cfg。
特别说明一下:我在定制GRUB2时使用了Ubuntu的启动文件,因为这个启动文件是签名的,它可以通过UEFI的安全引导(Secure Boot),这意味着电脑在开启安全引导时可以启动到GRUB2菜单界面,但这仍然有局限,很多指令和insmod仍然是被禁止的,因此,我们的Android-x86如果放在NTFS分区,那么 insmod ntfs 是必须的,这种情况就必须禁用安全引导,如果是放在Ext4分区,那么所有的 insmod 都可以不要,这样就可以开启安全引导,象我的SurfacePro3如果禁止安全引导,开机时整个屏幕都是鲜亮红色背景,很刺眼很不舒服,所以必须放Ext4。
现就我的具体配置为例进行注释,方便大家对照修改。
SurfacePro3启动配置:
Android系统文件路径:
Android-x86官方版:/Android-x86
LineageOS:/LineageOS
RemixOS:/RemixOS
PhoenixOS:/PhoenixOS
grub.cfg文件:

GRUB2 for Surface Pro3 Boot Manager

set timeout=60
set pager=1

下面的insmod,Android如果在NTFS分区只需要保留insmod ntfs,如果在Ext4分区,所有的insmod都可以删除

insmod all_video
insmod exfat
insmod ext2
insmod fat
insmod gfxmenu
insmod gfxterm
insmod iso9660
insmod jpeg
insmod ntfs
insmod part_acorn
insmod part_amiga
insmod part_apple
insmod part_bsd
insmod part_dfly
insmod part_dvh
insmod part_gpt
insmod part_msdos
insmod part_plan
insmod part_sun
insmod part_sunpc
insmod png
insmod xfs

加载字体和主题,设置图形模式

loadfont ${prefix}/theme/unicode.pf2
loadfont ${prefix}/theme/DejaVuSansMono-18.pf2
set gfxmode=1280x1024
terminal_output gfxterm

加载主题样式

set theme=${prefix}/theme/oxygen/theme.txt
export theme

MENU BEGIN

启动Windows菜单(Win8、Win10都一样)

if search -f -n -s r /EFI/Microsoft/Boot/Bootmgfw.efi; then
menuentry “Windows 8.1 Ent” “$r” --class windows {
set root=$2
chainloader /EFI/Microsoft/Boot/Bootmgfw.efi
}
fi

启动Ubuntu菜单

注意 linux /vmlinuz root=/dev/sda5 ro quiet splash 中的 /dev/sda5 表示Ubuntu安装在第5分区,修改成你具体的

if search -f -n -s r /vmlinuz; then
menuentry “Ubuntu 18.04LTS” “$r” --class ubuntu {
set root=$2
linux /vmlinuz root=/dev/sda5 ro quiet splash
initrd /initrd.img
}
fi

启动Android-x86官方版菜单

if search -f -n -s r /Android-x86/kernel; then
menuentry “Android-x86 64bit” “$r” --class android-x86 {
set root=$2
linux /Android-x86/kernel root=/dev/ram0 androidboot.selinux=permissive quiet SRC= DATA=
initrd /Android-x86/initrd.img
}
fi

启动cm-x86(LineageOS)菜单

if search -f -n -s r /LineageOS/initrd.img; then
menuentry “LineageOS 64bit” “$r” --class android-x86 {
set root=$2
linux /LineageOS/kernel root=/dev/ram0 androidboot.selinux=permissive quiet SRC= DATA=
initrd /LineageOS/initrd.img
}
fi

启动RemixOS菜单

if search -f -n -s r /RemixOS/initrd.img; then
menuentry “RemixOS 64bit” “$r” --class android-x86 {
set root=$2
linux /RemixOS/kernel root=/dev/ram0 androidboot.selinux=permissive quiet SRC= DATA= logo.showlogo=1
initrd /RemixOS/initrd.img
}
fi

启动PhoenixOS菜单

if search -f -n -s r /PhoenixOS/initrd.img; then
menuentry “PhoenixOS 64bit” “$r” --class android-x86 {
set root=$2
linux /PhoenixOS/kernel root=/dev/ram0 androidboot.selinux=permissive quiet SRC= DATA= androidboot.hardware=android_x86
initrd /PhoenixOS/initrd.img
}
fi

下面是高级选项子菜单

submenu “Advanced Option >” --class forward {

启动Win8PE菜单(如果需要可在我网盘下载)

if search -f -n -s r /Boot/sources/Bootx64.efi; then
    menuentry "Windows 8 PE" "$r" --class windows {
    set root=$2
    chainloader /Boot/sources/Bootx64.efi
    }
fi

启动Parted Magic菜单(如果需要可在我网盘下载)

if search -f -n -s r /Pmagic/pmagic.cfg; then
    submenu "Parted Magic 2016 >" "$r" --class gnu-linux {
    menuentry "Parted Magic (RAM and Vendor)" "$2" --class gnu-linux {
    set root=$2
    linux /Pmagic/bzImage64 edd=on vga=normal quiet acpi_backlight=vendor
    initrd /Pmagic/initrd.img /Pmagic/fu.img /Pmagic/m64.img
    }
    menuentry "Parted Magic Official config >" "$2" --class forward {
    set root=$2
    configfile /Pmagic/pmagic.cfg
    }
}
fi

下面为搜索本地其它可引导文件,不需要的可删除至下一条注释之间的内容

if [ "${grub_cpu}" == "i386" ]; then
    set uefi=bootia32.efi
    set fbk=fallback.efi
    set grub=grubia32.efi
else
    set uefi=bootx64.efi
    set fbk=fallback_x64.efi
    set grub=grubx64.efi
fi
echo Searching for local OS...
set add_os=0
add_os_if_exist /efi/boot/${uefi} "UEFI OS" os
add_os_if_exist /efi/microsoft/boot/bootmgfw.efi "Windows (7/8/10/2008 etc.)" windows
add_os_if_exist /efi/ubuntu/${grub} "Ubuntu" ubuntu
add_os_if_exist /efi/boot/${fbk} "Fallback" os
add_os_if_exist /efi/centos/${grub} "CentOS" centos
add_os_if_exist /efi/debian/${grub} "Debian" debian
add_os_if_exist /efi/fedora/${grub} "Fedora" fedora
add_os_if_exist /efi/gentoo/${grub} "Gentoo" gentoo
add_os_if_exist /efi/linuxmint/${grub} "Linux Mint" linuxmint
add_os_if_exist /efi/opensuse/${grub} "openSUSE" opensuse
add_os_if_exist /efi/boto/bootx64.efi "OPENTHOS" openthos
add_os_if_exist /boot/grub/grub.cfg "GRUB2 config" grub cfg
add_os_if_exist /boot.cfg "Custom GRUB2 boot" custom cfg
if [ ${add_os} == 0 ]; then
    echo
    echo No local OS is found
fi
sleep 3

固件设置

menuentry "Firmware Settings" --class setup { fwsetup }

}

重启电脑

menuentry “Reboot” --class reboot { reboot }

关闭电源

menuentry “Power Off” --class shutdown { halt }

MENU END

下面为搜索本地包括USB设备中其它可引导文件相关函数,不需要的可全部删除以下内容

$1=boot file $2=title $3=–class $4=type

function add_os_if_exist {
for n in 0 1 2 3 4 5 6 7 8 9; do
for p in 1 2 3 4 5 6 7 8 9 cd; do
if [ “ p " = = " c d " ] ; t h e n s e t d = c d p" == "cd" ]; then set d=cd n
elif [ -f (hd n , g p t n,gpt p) 1 ] ; t h e n s e t d = h d 1 ]; then set d=hd n,gpt p e l i f [ f ( h d p elif [ -f (hd n,msdos$p) 1 ] ; t h e n s e t d = h d 1 ]; then set d=hd n,msdos p e l s e s e t d = h d p else set d=hd n, p f i i f [ " p fi if [ " d” != “ r o o t " a s ( root" -a -s ( d)$1 ]; then
if [ “$4” == “cfg” ]; then
menuentry “$2 at d > " " d >" " d” “$1” --class “$3” {
set root=$2
configfile KaTeX parse error: Expected 'EOF', got '}' at position 6: 3 }̲ elif [ "{grub_platform}” == “efi” ]; then
menuentry “$2 at d " " d" " d” “$1” --class “$3” {
set root=$2
chainloader $3
}
else
menuentry “$2 at d " " d" " d” “$1” --class “$3” {
set root=$2
ntldr KaTeX parse error: Expected 'EOF', got '}' at position 6: 3 }̲ fi set add…d)$1
fi
done
done
}

发布了13 篇原创文章 · 获赞 6 · 访问量 8783

猜你喜欢

转载自blog.csdn.net/qq_26227841/article/details/91511907