GRUB (简体中文)
From ArchWiki
Article summary |
---|
涵盖Archlinux缺省的启动加载器大部分方面, GRand Unified Bootloader (GRUB). |
Available in languages |
English |
עברית |
简体中文 |
Русский |
Español |
Related articles |
Reinstalling GRUB |
Grub configure examples |
Grub-gfx |
Contents |
安装Grub包
首先通过pacman安装grub
pacman -Sy grub
编辑menu.lst进行你的设定
nano /boot/grub/menu.lst
注意: 对IDE设备使用hd[a-z],对scsi和sata设备使用sd[a-z]
这里是我的一个范例:
# Config file for GRUB - The GNU GRand Unified Bootloader # /boot/grub/menu.lst # DEVICE NAME CONVERSIONS # # Linux Grub # ------------------------- # /dev/fd0 (fd0) # /dev/hda (hd0) # /dev/hdb2 (hd1,1) # /dev/hda3 (hd0,2) # # FRAMEBUFFER RESOLUTION SETTINGS # +-------------------------------------------------+ # | 640x480 800x600 1024x768 1280x1024 # ----+-------------------------------------------- # 256 | 0x301=769 0x303=771 0x305=773 0x307=775 # 32K | 0x310=784 0x313=787 0x316=790 0x319=793 # 64K | 0x311=785 0x314=788 0x317=791 0x31A=794 # 16M | 0x312=786 0x315=789 0x318=792 0x31B=795 # +-------------------------------------------------+ # general configuration: timeout 5 default 1 color light-blue/black light-cyan/blue # boot sections follow # each is implicitly numbered from 1 in the order of appearance below # # TIP: If you want a 1024x768 framebuffer, add "vga=773" to your kernel line. # #-* # (0) Arch Linux title Arch Linux [cpio] root (hd0,0) kernel /vmlinuz26 root=/dev/sda6 ro vga=773 initrd /kernel26.img title Arch Linux [thinkpad] root (hd0,0) kernel /vmlinuz26thinkpad root=/dev/sda6 ro video=vesafb:off acpi_sleep=s3_bios resume2=swap:/dev/sda5 initrd /kernel26thinkpad.img
将mounts复制到mtab
grep -v rootfs /proc/mounts > /etc/mtab
将GRUB安装在MBR(Master Boot Record)
目前有两种常用的方法安装GRUB。一种是创建一个启动盘(软盘或者光盘),另外一种是运行Arch安装程序的时候直接安装grub。如果你要升级grub的版本,你可以试试下面这种简单快捷的做法,不过GRUB官网上声明创建启动盘的方式较为安全。
使用grub-install程序
grub-install -root-directory Mount-Point (hdn)
上面的命令可以将grub安装到硬盘的MBR。内核镜像(kernel-image)如果不在/
下,例如在/boot
,可以使用 Mount-Point 指定其路径。
(hdn)表示某个硬盘,n是硬盘的编号,编号从0开始。
例如: 你有一个独立分区挂载在/boot, 那就象下面这样做
grub-install --root-directory=/boot '(hd0)' grub-install --root-directory=/boot sda grub-install --root-directory=/boot hda
如果你没有独立分区,那么只要不带--root-directory参数运行命令
grub-install /dev/sda grub-install --root-directory=/boot '(hd0)'
注意 GRUB并不了解形如hda、sda这样的命名方式。它以(hd0)、(hd1)这样的方式命名磁盘。 这就是为什么使用grub-install的时候'一定'要小心。
grub-install会试图将BIOS驱动映射到hda/sda格式,通常它都可以正确映射。要检查映射是否正确,可以在安装完启动加载器后的提示信息。grub-install会显示形如下面的提示
(fd0) /dev/fd0 (hd0) /dev/hda
你得检查这种映射是否正确。如果不正确,到/boot/grub下编辑'device.map'文件进行更正。然后重新运行grub-install程序重安装GRUB。
配置
Grub的配置文件是:
/boot/grub/menu.lst
- (hdn,m) 第n个磁盘的第m个分区,编号均从0开始(注意逻辑分区编号)
- splashimage (hdn,m)/grub/Name.xpm.gz splash图像文件
- default n 默认启动项,如果在timeout时间内用户没有操作,则自动启动对应的选项
- timeout m 在m秒内等候用户选择,m秒后用户没有操作的话启动默认选项
- password -md5 str encrypted boot password 'str'
- title str 以"str"作为启动项的标题
- root (hdn,m) 内核所在的分区,编号方式同上
- kernel /path ro root=/dev/device initrd /initrd.img 指定要启动的内核、根文件系统
- makeactive
chainloader +1 激活根分区,并将引导权转交其上的引导器(这一项可以用来启动windows) - map (hd0) (hd1)
map (hd1) (hd0) 启动时交换主、副磁盘, 用来从副磁盘启动windows - root (hdn,m,z)
kernel /boot/loader 启动FreeBSD分区 - default saved 记住当前的启动选择并将其设置为默认值。在对应的启动项后加上该语句,可以使下次默认启动当前的选项。
喜欢漂亮界面的用户可以参考图形化GRUB.
双启动
有两种常用方法配置menu.lst文件。详情请看这里.
双启动到Windows
把段内容加入到你的/boot/grub/menu.lst末尾。它假设你的Windows启动分区是位于[s/h]da2。
# (2) Windows XP title Windows XP rootnoverify (hd0,1) makeactive chainloader +1
双启动到其它硬盘上的Windows
将下面内容加入到你的/boot/grub/menu.lst末尾。这里假设你的硬盘分区是在[s/h]db1。
# (2) Windows XP title Windows XP map (hd0) (hd1) map (hd1) (hd0) rootnoverify (hd1,0) makeactive chainloader +1
map功能函数会欺骗你的Windows安装程序,让它以为第二硬盘是主硬盘。
双启动到其它Linux发行版
和Arch linux的加载方式一样。下面假设另外一个发行版位于分区[s/h]da3。
title Other Linux root (hd0,2) kernel /boot/vmlinuz (add other options here as required) initrd /boot/initrd.img (if the other kernel uses/needs one)
双启动到其它Linux发行版 (Chainloading)
要避免维护噩梦,你也许希望MBR中的GRUB可以直接chainload到其它分区如(hd0,2)(不是MBR)的bootrecord上已安装好了的启动加载器。这样将由其它发行版来负责处理(hd0,2)上的menu.lst(如果它使用grub)而你无须将部分menu.lst又复制粘贴回来。
在这个例子中[1], GRUB位于MBR,而其它启动加载器(BL) (grub或者lilo) 在(hd0,2)的Boot Record。
接着,你只要在menu.lst这样写:
title Other Linux distro root (hd0,2) chainloader +1
LiLO和GRUB的互换
如果你原来使用的是lilo,记得先将其移除:
pacman -R lilo
之所以要将其移除,是因为有些时候(如利用"make all"编译内核)会自动调用lilo程序,这会覆盖grub。 注意,执行了上面的命令后,并不会将MBR中的lilo移除,但是当你安装其它的引导器(如grub)时它会覆盖lilo。
解决遇到的问题
GRUB error 15
请menu.lst的kernel行里要有ro
。