grub定制启动菜单

编程入门 行业动态 更新时间:2024-10-10 00:27:07

grub定制<a href=https://www.elefans.com/category/jswz/34/1433376.html style=启动菜单"/>

grub定制启动菜单

原文链接:/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; thenmenuentry "Windows 8 PE" "$r" --class windows {set root=$2chainloader /Boot/sources/Bootx64.efi}
fi

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

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

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

if [ "${grub_cpu}" == "i386" ]; thenset uefi=bootia32.efiset fbk=fallback.efiset grub=grubia32.efi
elseset uefi=bootx64.efiset fbk=fallback_x64.efiset 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 ]; thenechoecho 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 &quot; = = &quot; c d &quot; ] ; t h e n s e t d = c d p&quot; == &quot;cd&quot; ]; then set d=cd p"=="cd"];thensetd=cdn
elif [ -f (hd n , g p t n,gpt n,gptp) 1 ] ; t h e n s e t d = h d 1 ]; then set d=hd 1];thensetd=hdn,gpt p e l i f [ − f ( h d p elif [ -f (hd pelif[−f(hdn,msdos$p) 1 ] ; t h e n s e t d = h d 1 ]; then set d=hd 1];thensetd=hdn,msdos p e l s e s e t d = h d p else set d=hd pelsesetd=hdn, p f i i f [ &quot; p fi if [ &quot; pfiif["d” != “ r o o t &quot; − a − s ( root&quot; -a -s ( root"−a−s(d)$1 ]; then
if [ “$4” == “cfg” ]; then
menuentry “$2 at d &gt; &quot; &quot; d &gt;&quot; &quot; 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 &quot; &quot; d&quot; &quot; d""d” “$1” --class “$3” {
set root=$2
chainloader $3
}
else
menuentry “$2 at d &quot; &quot; d&quot; &quot; 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
}

更多推荐

grub定制启动菜单

本文发布于:2024-02-13 15:07:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1759093.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:启动菜单   grub

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!