Linux GRUB配置文件
GRUB(Grand Unified Bootloader)是一种用于管理多操作系统的引导加载程序。GRUB配置文件在Linux中通常被命名为grub.cfg,该文件位于/boot/grub目录下。GRUB的配置文件使用类似于Shell脚本的语法,用于指定启动菜单和相关选项。
以下是GRUB配置文件的一个示例:
# This file provides a means to add custom menu entries. Simply type the
# menu entries you want to add after this comment. Be careful not to change
# the 'exec tail' line above.
menuentry 'Ubuntu' {
set root='(hd0,msdos1)'
linux /boot/vmlinuz-5.4.0-52-generic root=UUID=e12fdb6f-0a1b-42af-8cd0-442aef2c3e3b ro quiet splash
initrd /boot/initrd.img-5.4.0-52-generic
}
menuentry 'Windows 10' {
insmod part_gpt
insmod ntfs
insmod search_fs_uuid
insmod chain
search --fs-uuid --no-floppy --set=root 4C13E4DE13E4C074
chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi
}
在配置文件中,每个menuentry都代表一个启动选项。菜单项后面的大括号内包含了具体的配置信息。其中,set root用于设置根分区,linux行指定Linux内核的位置和启动选项,initrd行指定初始化内存盘的位置。Windows菜单项用到了GRUB的一些模块,并用chainloader命令指定了Windows引导程序的位置。
配置文件中还可以指定其他选项,如设置默认启动项、超时时间、背景图像等。
注意:GRUB的配置文件属于系统级文件,修改前最好备份原配置文件以防出错。修改配置文件后需要运行sudo update-grub命令使更改生效。