三、grub2配置文件详解
grub2改用grub.cfg为配置文件,配置文件包含以下基本内容:(红色为解释部分)### BEGIN /etc/grub.d/00_header ###load_env#加载变量,如果在grubenv保存变量,则启动时装载set default="0"#设置默认引导项,默认值为0insmod ext2#插入文件系统支持的模块,除了用作启动的分区外,其他分区格式可在menuentry底 下再添加set root=(hd0,8)#指定系统root分区,也就是 / 分区search --no-floppy --fs-uuid --set 2d61e5f9-1d2a-4167-a6f1-b991ba00878b#指定uuid=2d61e5f9-1d2a-4167-a6f1-b991ba00878b的分区为root分区,如果前面的 分区号(hd0,8)的#uuid与这里的uuid一致,这两句作用一样,如果不一致,则指定uuid 的起作用。if loadfont /usr/share/grub/unicode.pf2 ; then#设置终端字体,unicode.pf2支持中文字符显示set gfxmode=640x480#设置显示分辨率,默认为640x480,可用800x600,1024x768,建议跟你想设定的 图片大小一致insmod gfxterm#插入终端模块gfxterm,支持中文字符显示和支持24位图像insmod vbe#插入vbe模块,GRUB2引入模块化机制,要使用它,需要在这里加入if terminal_output gfxterm ; then true ; else # For backward compatibility with versions of terminal.mod that don't # understand terminal_output terminal gfxterm#设定grub2终端为gfxtermfi if [ ${recordfail} = 1 ]; then set timeout=-1 # 若有启动失败的记录,则菜单项不再倒计时else set timeout=10 #倒计时10秒后进按默认启动项启动fi#设定默认启动前等待时间,默认为10秒### END /etc/grub.d/00_header ### ### BEGIN /etc/grub.d/05_debian_theme ### set menu_color_normal=white/black#设定菜单字体及背景颜色set menu_color_highlight=black/blue#设定选择项字体及背景颜色 #如果使用默认,背景将完全被蓝色挡住了,需要修改blue为black,背景图片才能显 示### END /etc/grub.d/05_debian_theme ### ### BEGIN /etc/grub.d/10_linux ####10_linux为系统自动添加的当前root分区linux引导项 #每个菜单项要包括menuentry双引号" "和大括号{ }才完整,否则不显示菜单menuentry "Ubuntu, Linux 2.6.31-10-generic" { set quiet=1 insmod ext2 set root=(hd0,8) search --no-floppy --fs-uuid --set 2d61e5f9-1d2a-4167-a6f1-b991ba00878b#这句与set root=(hd0,8)效果一样,可删除其一,二者不一致以这句为准linux /boot/vmlinuz-2.6.31-10-generic root=UUID=2d61e5f9-1d2a-4167-a6f1-b991ba00878b ro quiet splash#不喜欢看到一长串的, roo=UUID=***可用root=/dev/sda8(/分区的分区号)代替initrd /boot/initrd.img-2.6.31-10-generic } … ### END /etc/grub.d/10_linux ####20_memtest86+为系统自动添加的内存测试菜单项### BEGIN /etc/grub.d/20_memtest86+ ### menuentry "Memory test (memtest86+)" { linux16 /boot/memtest86+.bin } menuentry "Memory test (memtest86+, serial console 115200)" { linux16 /boot/memtest86+.bin console=ttyS0,115200n8 } ### END /etc/grub.d/20_memtest86+ ####30_os-prober或30_others为系统自动查找并添加其他系统菜单项,按windows, linux,macos顺序 #查找并添加,支持windows 7识别### BEGIN /etc/grub.d/30_os-prober ### ### END /etc/grub.d/30_os-prober ### ### BEGIN /etc/grub.d/30_otheros ### # This entry automatically added by the Debian installer for a non-linux OS # on /dev/sda1 menuentry "Microsoft Windows XP Professional" { set root=(hd0,1) search --no-floppy --fs-uuid --set e852-230b drivemap -s (hd0) $root#对以ntldr引导的系统如win2000,xp,win2003,因其引导机制只能从第一硬盘启 动,系统会自动添加#映射命令,对vista和win7就没有这句命令chainloader +1 } ### END /etc/grub.d/30_otheros ####40_custom为自定义的启动项,如启动cdlinux### BEGIN /etc/grub.d/40_custom ### menuentry "CDLinux"{ set root=(hd0,8) linux /CDlinux/bzImage root=/dev/ram0 vga=791 CDL_LANG=zh_CN.UTF-8 initrd /CDlinux/initrd } ### END /etc/grub.d/40_custom ### 定制个性化的配置文件,可以加入背景图片,使用中文字符,让启动画面独具特色, 而不是单调的黑、白、蓝三色。