配置文件
上篇我们安装完成GRUB会在U盘中多出个boot文件夹.
我们需要在/boot/grub 下新建一个grub.cfg 配置文件.
内容如下
基础的 GRUB 配置文件使用如下的设置:
- (hdX,Y) 为磁盘 X 上的分区 Y,分区编号从 1 开始,磁盘编号从 0 开始。
- set default=N 为在用户选择时间内没有进行选择时的默认启动条目。
- set timeout=M 即在使用默认条目启动前,等待用户自行选择的时间为 M 秒。
- menuentry "title" {entry options} 为一个标题为 title 的启动条目。
- set root=(hdX,Y) 设置 \boot 分区,即内核和 GRUB 模块存储的位置。
#"关机" 菜单项
menuentry "System shutdown" {
echo "System shutting down..."
halt
}
再次启动U盘时,我会进入GRUB的菜单程序中。
以上代码是添加一个关机菜单。
menuentry "System restart" {
echo "System rebooting..."
reboot
}
以上是重启菜单。
menuentry "linux-x86_64.iso" --class iso {
set isofile="/linux.iso"
loopback loop (hd0,1)$isofile
linux (loop)/arch/boot/x86_64/vmlinuz archisolabel=ARCH_201909 img_dev=/dev/disk/by-uuid/DB1B-213D img_loop=$isofile earlymodules=loop
initrd (loop)/arch/boot/x86_64/archiso.img
}
这是直接在ISO系统文件启动的菜单样板。
menuentry "Other Linux" {
set root=(hd0,1)
linux /boot/vmlinuz (根据需要在此处添加其他选项 )
initrd /boot/initrd.img (如果其他的内核需要的话)
}
这是直接启动U盘中的系统菜单样板。
最后也可以使用grub-mkconfig生成工具自动生成配置文件。
# grub-mkconfig -o /mnt/usb/boot/grub/grub.cfg