GrubHowto

来自Ubuntu中文
跳到导航跳到搜索

Other Languages: ComoGrub (Spanish)


What Is GRUB 什么是Grub

  • GRUB is a bootloader, it is the first thing that loads when the computer starts. It allows you to have different operating systems, and versions of them, on the same hard drive. For example you may have Windows and Linux on a computer, GRUB would load before either of these and give you a choice. You can also create a boot floppy with GRUB to use in case of emergency.
  • Grub是一个启动引导器,它是电脑启动后加载的第一个程序。有了它,你可以在一个硬盘里面安装多个不同的操作系统、以及操作系统的不同版本。例如,您也许在您的电脑上装了Windows和Linux,Grub将在这两者之前加载之前加载到你的电脑上,并让您选择一个操作系统。您也可以创建一个Grub的启动软盘来进行急救。

Increasing the GRUB timeout 增加Grub的延迟时间

  • If you need to get into the grub menu you need to press ESC just after it starts. By default you have to press ESC very quickly. To increase this time edit /boot/grub/menu.lst, increasing the seconds in the TIMEOUT part. Alternatively you could have the menu always come up at boot time. To do this, comment out 'hiddenmenu' by inserting a # at the beginning of the line. Once you have changed menu.lst you must run:
  • 要进入Grub的菜单,必须在启动时按“ESC”键。但默认的状况是你必须很快地按“ESC”(不然就进了系统了)。为了增加这个延时,可以编辑这个文件:/boot/grub/menu.lst,找到TIMEOUT,增加他后面是数字(数字代表秒数)。或者你也可以设置成启动的时候自动显示菜单,方法是把“hiddenmenu”注释掉,也就是在hiddenmenu的前面加一个“#”。一旦您改变了menu.lst文件,你就需要运行:
sudo update-grub

attachment:IconsPage/IconNote.png

  • If the Ubuntu installer detected other operating systems on the disk during the installation, then the grub menu will be displayed by default and the timeout will be increased, so the step above will be unnecessary.
  • 如果在安装时,Ubuntu安装程序检测到你的硬盘上装有其他操作系统,则Grub菜单将自动显示,延时也会自动增加,所以将不需要以上步骤。

Automagic Kernels List

Debian uses a tool called update-grub to install grub to the MBR. It automatically detects all of the kernels you have in the /boot directory, and applies various global settings to each one. Also, whenever you install kernel updates from the repositories, update-grub is run to, well, update grub.

Debian通常会用 一个 叫做 update-grub的工具来 将grub安装到硬盘的mbr上。通常它会自动识别您已经安装到 引导分区的内核,并且为每一个设置相应的规则。因此,无论什么时候您从存储设备上安装内核,update-grub都会正常的 运行,正确安装grub.

The relevant parts of menu.lst that update-grub looks at are the ones in between the "### BEGIN AUTOMAGIC KERNELS LIST" and "### END DEBIAN AUTOMAGIC KERNELS LIST" lines. Comments are precedded by at least two '#', e.g. '## this is a comment'. Global options are after single '#', e.g. '# groot=(hd0,4)'. The most common one to change is probably the groot option. Change this if /boot resides on a different partition that /. See the appropriate section on this page for more information about different /boot partitions. Another common option is 'kopt=', which are kernel options applied to all kernels in the menu.lst.

Setting kernel parameters

设定内核参数 . In /boot/grub/menu.lst, you will find a line like this:

  • /boot/grub/menu.lst 里你可以找到下边的这句:
# kopt=root=/dev/sda1 ro

It is a comment, but do not remove the '# ' at the beginning. /!\ THIS IS IMPORTANT. If you require additional kernel parameters (for example, if someone has asked you to test booting with certain parameters in order to troubleshoot a problem), add them to the end of the line, for example to add noapic:

  • 这是一个备注, 但是不要删除最开始的'#'. /!\ 这是非常重要的. 如果你需要额外的内核参数 (比方说,如果有人需要你从一个特定的参数去启动来诊断问题的时候.), 把它在句子的最后,比方说加入 noapic:
# kopt=root=/dev/sda1 ro noapic

After editing the file, run:

  • 当结束编辑文档的时候,运行:
sudo update-grub

If /boot is on another partition

如果 /boot在另外一个分区 . If /boot is mounted on another partition and you use update-grub, then you may run into problems. One fix is to use grub-install, which is a distribution-agnostic way to install grub.

  • 如果/boot在另外一个分区,你想用update-grub的时候,你可能会遇到问题。 一种解决办法是用grub-install,这是一个distribution-agnostic(我不是电脑专业的,这个是什么意思啊?)的方法去安装grub.
sudo grub-install --root-directory=/boot /dev/sda

This is probably less desirable because update-grub is very good at setting things up properly, therefore it should be used instead. Another fix is to create a symlink in /boot to itself:

  • 这个可能不是非常这得去尝试。因为update-grub自己本身非常善于正确的设定,所以,应该用这个。 另外一种方法是建立一个symlink在/boot:
cd /boot
sudo ln -s . boot

The reasoning behind this is when grub boots, it looks at whatever partition it is installed on. update-grub (and grub-install) assumes that everything is in /boot. When /boot is on the same partition as /, then all is OK, as menu.lst will be in /boot/grub. If /boot is on a separate partition, then grub sees /boot as / (hence the '--root-directory' above). By adding a symlink, when it looks for /boot/grub, it will be there. By creating the symlink, you have put a loop in the file system, which may cause problems when using certain options of cp, mv, etc.

  • 原因是,当grub启动的时候,他回自己寻找已经安装的分区。update-grub(和undate-install)会假设所有的东西都在/boot里边。 当/boot在同一个 / 分区里,因为menu.lst会在 /boot/grub,所以就不会有问题。 如果 /boot 在另外一个分区, grub就会把/boot当成 / (也就是上边说的 '--root-diretctory'). 加入了 symlink, 他就会寻找/boot/grub, 它会在那儿的. 建立symlink, 你需要加入一个loop在file system, 当你用到一些option的时候 (比如说, cp, mv 等等),这个会造成问题.

Bootsplash

  • Grub allows an image to be displayed behind the menu. You can obtain a set of images with the package "grub-splashimages", or you can make your own. The images must be 640x480 pixels, contain no more than 16 colors (but a smaller number like 12 works better to allow some different colors for the menu text), and be in gzipped xpm format. The GIMP can be used to resize (Image -> Scale Image...), reduce colors (Image -> Mode -> Indexed...), and can save to .xpm.gz files. After creating a splash image, add a line like
splashimage=(hd0,4)/grub/splash.xpm.gz

to your menu.lst file. A useful trick is to make a symlink to the actual image named splash.xpm.gz.

cd /boot/grub
sudo ln -s my_image.xpm.gz splash.xpm.gz

Grub loads the image from the disk upon boot; it is not stored in the MBR. If you use a symlink, you will not have to edit menu.lst and reinstall grub to change the image, you just have to change the symlink. Here is an image of the GNU by Peter Gerwinski: attachment:gnu-head.xpm.gz

Splash Image with update-grub

  • The command update-grub will automatically pick up /boot/grub/splash.xpm.gz and configure the menu.lst file for you. It will take care of the correct hdX and partition number [no need to type in (hd0,4)].
sudo apt-get install grub-splashimages
sudo ln -s /boot/grub/splashimages/my_image.xpm.gz /boot/grub/splash.xpm.gz
sudo update-grub

Note: replace the my_image.xpm.gz with the one that you want.

Creating a boot floppy

  • You can use grub to create a boot floppy. See /BootFloppy

Change the default operating system

  • By default, Grub in Ubuntu boots Ubuntu by default. If you wish to change this to another operating system, see /ChangeDefaultOS

Network booting

  • If you use LTSP or Edubuntu, you may want to boot from your network card.

Specific network cards need a specifc rom to boot from. To find which one you need, run lsmod and then search for your floppy. Then go to www.rom-o-matic.com and get the appropriate rom. Edit /boot/grub/menu.lst and add the following before ### BEGIN AUTOMAGIC KERNELS LIST or after ### END DEBIAN AUTOMAGIC KERNELS LIST, otherwise your changes will be wiped out by security updates, etc.

title LTSP
root (hd0,2)
kernel /boot/(rom you get from rom-o-matic)


----
原文出处:wiki.ubuntu.org.cn
原文作者:
授权许可:[http://creativecommons.org/licenses/by-sa/2.0/ 创作共用协议Attribution-ShareAlike 2.0]
[http://www.gnu.org/copyleft/fdl.html GNU自由文档许可证]
翻译人员:x5yw ShaunDu
校对人员:
贡献者:
适用版本:
文章状态:[[翻译中]]
----