menu.lst位于/boot/grub/menu.lst,而/boot/grub/grub.conf相当于是menu.lst在windows下 的快捷方式(重装系统有时破坏GRUB后,menu.lst丢失而无法启动GRUB菜单时就需要在/boot下建立menu.lst后再和 grub.conf建立链接来修复,建立链接是:ln -s menu.lst grub.conf (注意两文件的前后关系)),我们来学习如何编写GRUB的配置文件menu.lst.
首先来看一下/boot/grub/menu.lst中的内容:
default=0
timeout=5
#splashimage=(hd0,6)/boot/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.11-1.1369_FC4)
root (hd0,6)
kernel /boot/vmlinuz-2.6.11-1.1369_FC4 ro root=LABEL=/
initrd /boot/initrd-2.6.11-1.1369_FC4.img
title Windows XP
rootnoverify (hd0,0)
chainloader +1
其中:
a,default=0
表示默认启动的第0号的操作系统,在GRUB中,title定义了启动的操作系统,从第1个开始,GRUB中是0,而第2个是1,依次类推...
b,timeout=5
表示的是出现GRUB界面后,无操作情况下进入default设定的操作系统的时间,如果上下移动选择,则该选项无效
c,splashimage=(hd0,6)/boot/grub/splah.xpm.gz
表示的是允许出现的GRUB背景的path,显然(hd0,6)指定了分区(不知能否这么解释,呵呵),而后边的则是正常的path(在例子中,用#把它注释,为一可选项)
d,hiddenmenu
表示隐藏GRUB的启动菜单,直接进入由default庙宇的操作系统中去,为一可选项.
linux类
其格式一般为:
title (......)
root (hd[0-n],x)
kernel (......)
initrd (......)
其中:
title行,是定义一个启动操作系统,而后边可以自己随便写上喜欢的名字,呵,当然最起码你得写得要自己能认出来,没必要把linux写成windows吧?!
root行,指定相应的linux所有的/boot,如果在写分区和挂载时没有单独挂载,那么就和/在同一个分区中,hd[0-n]表示的是第几个硬盘,而x则表示的是[第几个分区-1],即x比分区号小1,特别要注意.
kernel 行,在这里以kernel 起始,指定Linux的内核的文件所处的绝对路径(通过在终端输入命令:ls /boot/vmlinuz*来看内核的全名);因为内核是处在/boot目录中的,而如果/boot是独立的一个分区,则需要把boot省略,因为 /boot所在的分区在root (hd[0-n],x)中指定了,所以就无需要再指明内核处在哪个分区了;ro 表示只读;root=LABEL=/ 来表示Linux的根所处的分区。LABEL=/ 这是硬盘分区格式化为相应文件系统后所加的标签;如果您不了解什么是标签,也可以直接以/dev/hd[a-z]X 或者/dev/sd[a-z]X来表示;就看您的Linux是根分区是在哪个分区了。比如我的是在/dev/hda3, 那这里就可以写成root=/dev/hda3;
initrd行,如果是/boot独立一个分区,initrd 一行要把/boot中省略;如果/boot不是处于一个分区,而是和Linux的/分区处于同一分区,不应该省略;我们通过查看/boot中的 initrd的文件名到底是什么来写这一行代码,在终端输入:ls /boot/initrd*
很容易能得到initrd文件名,然后写入.
在了解了以上情况之后,我们就很容易地理解另一种写法了:
title (......)
kernel (hd[0-n],y)(/boot)...... ro root=......
initrd (hd[0-n],y)(/boot)......
其实只是省略的root很实在地写在了kernel和initrd行中去了而已
附:
其 实在GRUB启动菜单不能工作的时候,进入GRUB命令行(可按CTRL+C键)后,我们同样可以一步一步地把系统启动起来,其实在menu.lst中, 除title不是指令外,其余的都是GRUB指令,我们只要一步步地输入它们(错了要从新开始),中间输入关于kernel和 initrd要利用
TAB键补齐写好,最后只要boot一下就行了.
用GRUB指令引导windows:
GRUB> rootnoverify (hd0,0)
GRUB> chainloader +1
GRUB> boot
用GRUB指令引导linux:
略,读者可参考本文中的一些知识自己试验.
menu.lst
- <code class="language-html">Menu.lst:
- color black/cyan yellow/cyan
- timeout 10
- default /default
-
- #Windows下引导进入Ubuntu
- #windows下hd0,对应分区表规则:主分区为0,扩展分区为1;2和3是为主分区预留的标号;逻辑分区标号从4开始,逻辑分区1的标号为4,所以此处为最后一个逻辑分区,对应6
- #Ubuntu下,dev编号从1开始,所以对应的磁盘为/dev/sda7
- #此方法可以正常从XP启动Ubuntu 11.10,
- #但在Win7下采用此写法却无法引导Ubuntu 12.10,执行到kernel时,出错:Error 15:File not found.
- #通过命令行进入grub以后,执行[root (hd0,2)]以后,执行成功,分区也没有错,但是再查看,发现无法找到/boot,只有一个/GGG目录,不解.
- #Ubuntu 12.10的/分区是ext4fs的文件类型.以前的Ubuntu 11.10是ext3fs的文件格式,不知道是不是和文件格式有关系
- title Load Ubuntu 11.10
- title Ubuntu 11.10
- kernel (hd0,6)/boot/vmlinuz-3.0.0-12-generic root=/dev/sda7 ro quiet splash
- initrd (hd0,6)/boot/initrd.img-3.0.0-12-generic
- boot
-
- title Windows XP
- rootnoverify (hd0,0)
- makeactive
- chainloader +1
-
- title reboot
- savedefault --wait=2
- reboot
-
- title halt
- savedefault --wait=2
- halt
-
- title Install Ubuntu 11.10
- root(hd0,0)
- kernel (hd0,0)/vmlinuz boot=casper iso-scan/filename=/ubuntu-11.10-desktop-i386.iso ro quiet splash locale=zh_CN.UTF-8
- initrd (hd0,0)/initrd.gz
-
- title ubuntu 12.10
- find --set-root /boot/grub/i386-pc/core.img
- kernel /boot/grub/i386-pc/core.img
- boot
- </code>
Menu.lst:color black/cyan yellow/cyantimeout 10default /default#Windows下引导进入Ubuntu#windows下hd0,对应分区表规则:主分区为0,扩展分区为1;2和3是为主分区预留的标号;逻辑分区标号从4开始,逻辑分区1的标号为4,所以此处为最后一个逻辑分区,对应6#Ubuntu下,dev编号从1开始,所以对应的磁盘为/dev/sda7#此方法可以正常从XP启动Ubuntu 11.10,#但在Win7下采用此写法却无法引导Ubuntu 12.10,执行到kernel时,出错:Error 15:File not found.#通过命令行进入grub以后,执行[root (hd0,2)]以后,执行成功,分区也没有错,但是再查看,发现无法找到/boot,只有一个/GGG目录,不解.#Ubuntu 12.10的/分区是ext4fs的文件类型.以前的Ubuntu 11.10是ext3fs的文件格式,不知道是不是和文件格式有关系title Load Ubuntu 11.10title Ubuntu 11.10kernel (hd0,6)/boot/vmlinuz-3.0.0-12-generic root=/dev/sda7 ro quiet splashinitrd (hd0,6)/boot/initrd.img-3.0.0-12-genericboottitle Windows XProotnoverify (hd0,0)makeactivechainloader +1 title rebootsavedefault --wait=2reboottitle haltsavedefault --wait=2halttitle Install Ubuntu 11.10root(hd0,0)kernel (hd0,0)/vmlinuz boot=casper iso-scan/filename=/ubuntu-11.10-desktop-i386.iso ro quiet splash locale=zh_CN.UTF-8initrd (hd0,0)/initrd.gztitle ubuntu 12.10find --set-root /boot/grub/i386-pc/core.imgkernel /boot/grub/i386-pc/core.imgboot
看我ubuntu上的这段grub2配置文件(ext4引导,图片背景)
http://hi.baidu.com/black/item/59442e4b8a7ff809e93504c6
## DO NOT EDIT THIS FILE## It is automatically generated by /usr/sbin/grub-mkconfig using templates# from and settings from /etc/default/grub#### BEGIN /etc/grub.d/00_header ###set default=0set timeout=10set root=(hd0,8)search --fs-uuid --set 90c006fd-4d2d-498c-8f92-d802a26c10bfinsmod fontif loadfont /usr/share/grub/ascii.pf2 ; then#这段代码中一开始我用的unicode.pf2结果下面的设置都不成功,反复n多次才知道这个unicode.pf2文件格式有错误,希望大家在调试的时候注意,多在grub2下运行这些命令,查看命令返回 insmod gfxterm insmod video insmod vbe set gfxmode=1024x768 if terminal_output gfxterm ; then true ; else # For backward compatibility with versions of terminal.mod that don't # understand terminal_output terminal gfxterm fi insmod jpeg background_image /boot/grub/mm.jpgfi### END /etc/grub.d/00_header ###### BEGIN /etc/grub.d/05_debian_theme ###set menu_color_normal=cyan/blueset menu_color_highlight=white/blue### END /etc/grub.d/05_debian_theme ###### BEGIN /etc/grub.d/10_linux ###menuentry "启动Ubuntu GNU/Linux, linux 2.6.27-7-generic" { set root=(hd0,8) search --fs-uuid --set 90c006fd-4d2d-498c-8f92-d802a26c10bf linux /boot/vmlinuz-2.6.27-7-generic root=UUID=90c006fd-4d2d-498c-8f92-d802a26c10bf ro locale=zh_CN initrd /boot/initrd.img-2.6.27-7-generic}menuentry "Ubuntu GNU/Linux, linux 2.6.27-7-generic (recovery mode)" { set root=(hd0,8) search --fs-uuid --set 90c006fd-4d2d-498c-8f92-d802a26c10bf linux /boot/vmlinuz-2.6.27-7-generic root=UUID=90c006fd-4d2d-498c-8f92-d802a26c10bf ro single locale=zh_CN initrd /boot/initrd.img-2.6.27-7-generic}### END /etc/grub.d/10_linux ###### BEGIN /etc/grub.d/20_memtest86+ ###menuentry "Memory test (memtest86+)" { linux /memtest86+.bin}### END /etc/grub.d/20_memtest86+ ###### BEGIN ubuntu 9.04 ####引导ext4磁盘格式的ubuntu9.04 只需要linux内核设置 不需要initrdmenuentry "Ubuntu GNU/Linux, linux 2.6.28-11-generic" { set root=(hd0,12) linux /boot/vmlinuz-2.6.28-11-generic root=/dev/sda12 ro locale=zh_CN}### END ubuntu 9.04 ###### BEGIN /etc/grub.d/30_os-prober ###menuentry "Windows NT/2000/XP (loader) (on /dev/sda1)" { set root=(hd0,1) chainloader +1}menuentry "Magic Linux Houyuan (on /dev/sda10)" {#引导magic linux set root=(hd0,10) linux /boot/vmlinuz-2.6.25.20-smp root=/dev/sda10}### END /etc/grub.d/30_os-prober ###### BEGIN /etc/grub.d/40_custom #### This file is an example on how to add custom entries### END /etc/grub.d/40_custom ####Boot