“UbuntuHelp:GrubHowto/zh”的版本间的差异
来自Ubuntu中文
(新页面: {{Translation}}{{From|https://help.ubuntu.com/community/GrubHowto}}{{Languages|UbuntuHelp:GrubHowto}}{{Translator|杏林小草}} == GRUB == GRUB is a bootloader, it is the first thing t...) |
(→Manual configuration) |
||
(未显示2个用户的4个中间版本) | |||
第1行: | 第1行: | ||
{{Translation}}{{From|https://help.ubuntu.com/community/GrubHowto}}{{Languages|UbuntuHelp:GrubHowto}}{{Translator|杏林小草}} | {{Translation}}{{From|https://help.ubuntu.com/community/GrubHowto}}{{Languages|UbuntuHelp:GrubHowto}}{{Translator|杏林小草}} | ||
− | == GRUB == | + | == GRUB == |
− | + | GRUB是一种引导加载器,换句话说,它是计算机启动后第一个加载的东东。它可实现多个操作系统多重引导,不管这些操作系统安装于同一个硬盘,还是多个硬盘。例如,你可以同时在计算机上安装Windows和Linux,GRUB先于操作系统启动,它加载后允许你选择是启动Windows还是启动Linux。你还可以使用GRUB创建紧急引导软盘。 | |
− | === | + | https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=important.png |
+ | 请确保你用sudo或root帐户启动GRUB。普通用户也能启动GRUB控制台,但缺乏足够的特权,会导致很多古怪的错误信息。例如,实际的错误是“拒绝访问”,但是GRUB给出的错误信息是“找不到硬盘”。根据这些虚假错误信息去排除故障,会让你很沮丧。 | ||
− | + | === 修改GRUB的引导选项Modifying boot options in GRUB === | |
− | === | + | 要想进入GRUB的菜单修改引导选项或者选择不同的内核,只需要在它启动后按“ESC”键。在默认配置下,你必须手脚敏捷地按动“ESC”键。如果不想那么狼狈,可以编辑GRUB的配置文件/boot/grub/'''menu.lst''',增加TIMEOUT部分的时间值。或者,你可以要求GRUB在每次启动时都自动打开菜单。要做到这一点,请在“hiddenmenu”前面加上注释号“#”。After pressing 'ESC' you will be presented with a list of kernels and operating systems that you can boot. To modify the boot options highlight the operating system you want to edit and press 'e'. There you will be presented with lines starting with 'root', 'kernel', 'initrd', 'quiet' and 'savedefault'. To receive a more verbose boot process you can remove the 'quiet' line by highlighting it and pressing 'd' to remove that line. You will also need to highlight the 'kernel' line press 'e' to edit and remove the word 'splash' from the end of the line . After making any necessary modifications you can press 'b' to boot that operating system. These modifications will not persist across reboots. https://help.ubuntu.com/community/IconsPage?action=AttachFile&do=get&target=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 使用一个叫做 <code><nowiki>update-grub</nowiki></code> 的工具去维护<code><nowiki>menu.lst</nowiki></code>. 该工具自动监测你 <code><nowiki>/boot</nowiki></code> 下的内核, 并为每一个内核应用全局的设置. 任何时候你一旦更新了内核, <code><nowiki>update-grub</nowiki></code> 将会自动运行去更新grub设置. <code><nowiki>update-grub</nowiki></code> 更新后的相关区域对应于文件 <code><nowiki>menu.lst</nowiki></code> "### BEGIN AUTOMAGIC KERNELS LIST" 和 "### END DEBIAN AUTOMAGIC KERNELS LIST" 之间的文本. 注释前至少有两个 '#', 例如: '## this is a comment'. 全局设置以单个 '#' 开头, 例如: '# groot=(hd0,4)'. 我们最常更新的是groot选项,当 <code><nowiki>/boot</nowiki></code> 目录与 <code><nowiki>/</nowiki></code> 目录不在同一个分区上的时候你就需要更改groot选项,关于这一点的更多信息见本页相应的部分. 另一个常见选项是 'kopt=', 该选项应用于所有内核. |
− | + | === Setting kernel parameters === | |
− | == | + | In `/boot/grub/menu.lst`, you will find a line like this: <code><nowiki># kopt=root=/dev/sda1 ro</nowiki></code> This looks like a comment, but do not remove the '# ' at the beginning. /!\ THIS IS IMPORTANT: <code><nowiki>grub</nowiki></code> sees this line as a comment and ignores it, but it is used as a configuration parameter by <code><nowiki>update-grub</nowiki></code> to generate the contents of the file that <code><nowiki>grub</nowiki></code> will read at boot. 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`: <code><nowiki># kopt=root=/dev/sda1 ro noapic</nowiki></code> After editing the file, run: <code><nowiki>sudo update-grub</nowiki></code> Note that you can temporarily add kernel parameters at the grub boot menu also, by pressing 'e ' and editing the kernel line. |
− | If <code><nowiki>/boot</nowiki></code> is mounted on another partition and you use <code><nowiki>update-grub</nowiki></code>, then you may run into problems. One fix is to use <code><nowiki>grub-install</nowiki></code>, which is a distribution-agnostic way to install the <code><nowiki>grub</nowiki></code> boot loader to a boot sector. <code><nowiki>sudo grub-install --root-directory=/boot /dev/sda</nowiki></code> This is probably less desirable because <code><nowiki>update-grub</nowiki></code> is very good at setting things up properly, therefore it should be used instead. Another fix is to create a symlink in <code><nowiki>/boot</nowiki></code> to itself: | + | === If /boot is on another partition === |
+ | |||
+ | If <code><nowiki>/boot</nowiki></code> is mounted on another partition and you use <code><nowiki>update-grub</nowiki></code>, then you may run into problems. One fix is to use <code><nowiki>grub-install</nowiki></code>, which is a distribution-agnostic way to install the <code><nowiki>grub</nowiki></code> boot loader to a boot sector. <code><nowiki>sudo grub-install --root-directory=/boot /dev/sda</nowiki></code> This is probably less desirable because <code><nowiki>update-grub</nowiki></code> is very good at setting things up properly, therefore it should be used instead. Another fix is to create a symlink in <code><nowiki>/boot</nowiki></code> to itself: | ||
<pre>cd /boot | <pre>cd /boot | ||
sudo ln -s . boot</pre> | sudo ln -s . boot</pre> | ||
− | The reasoning behind this is when grub boots, it looks at whatever partition it is installed on. <code><nowiki>update-grub</nowiki></code> (and <code><nowiki>grub-install</nowiki></code>) assumes that everything is in <code><nowiki>/boot</nowiki></code>. When <code><nowiki>/boot</nowiki></code> is on the same partition as <code><nowiki>/</nowiki></code>, then all is OK, as <code><nowiki>menu.lst</nowiki></code> will be in <code><nowiki>/boot/grub</nowiki></code>. If <code><nowiki>/boot</nowiki></code> is on a separate partition, then grub sees <code><nowiki>/boot</nowiki></code> as <code><nowiki>/</nowiki></code> (hence the '--root-directory' above). By adding a symlink, when it looks for <code><nowiki>/boot/grub</nowiki></code>, 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 <code><nowiki>cp</nowiki></code>, <code><nowiki>mv</nowiki></code>, etc. | + | The reasoning behind this is when grub boots, it looks at whatever partition it is installed on. <code><nowiki>update-grub</nowiki></code> (and <code><nowiki>grub-install</nowiki></code>) assumes that everything is in <code><nowiki>/boot</nowiki></code>. When <code><nowiki>/boot</nowiki></code> is on the same partition as <code><nowiki>/</nowiki></code>, then all is OK, as <code><nowiki>menu.lst</nowiki></code> will be in <code><nowiki>/boot/grub</nowiki></code>. If <code><nowiki>/boot</nowiki></code> is on a separate partition, then grub sees <code><nowiki>/boot</nowiki></code> as <code><nowiki>/</nowiki></code> (hence the '--root-directory' above). By adding a symlink, when it looks for <code><nowiki>/boot/grub</nowiki></code>, 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 <code><nowiki>cp</nowiki></code>, <code><nowiki>mv</nowiki></code>, etc. |
− | === Changing the Disk that Grub is installed to === | + | === Changing the Disk that Grub is installed to === |
− | Consider the following problem: You have two hard drives, one SATA (/dev/sda), the other PATA (/dev/hda). Your BIOS seems to think that PATA drives should always be booted in preference of SATA drives, but you want to boot from the SATA drive. Grub can work around this problem. Finding groot First, figure out what Grub names the drives. This is listed in <code><nowiki>/boot/grub/device.map</nowiki></code>. There you will find a table of Grub-style names (e.g. ''(hd0)'') and Linux-style names (e.g. ''/dev/hda/''). You need to know what drive and partition <code><nowiki>/boot</nowiki></code> is on. To find where <code><nowiki>/boot</nowiki></code> is, use <code><nowiki>df</nowiki></code>: <code><nowiki>df /boot</nowiki></code> This should tell you the Linux-style partition name where <code><nowiki>/boot</nowiki></code> is. Then simply match it with the Grub-style name in <code><nowiki>device.map</nowiki></code>. This is what ''groot'' should be. Example: | + | Consider the following problem: You have two hard drives, one SATA (/dev/sda), the other PATA (/dev/hda). Your BIOS seems to think that PATA drives should always be booted in preference of SATA drives, but you want to boot from the SATA drive. Grub can work around this problem. Finding groot First, figure out what Grub names the drives. This is listed in <code><nowiki>/boot/grub/device.map</nowiki></code>. There you will find a table of Grub-style names (e.g. ''(hd0)'') and Linux-style names (e.g. ''/dev/hda/''). You need to know what drive and partition <code><nowiki>/boot</nowiki></code> is on. To find where <code><nowiki>/boot</nowiki></code> is, use <code><nowiki>df</nowiki></code>: <code><nowiki>df /boot</nowiki></code> This should tell you the Linux-style partition name where <code><nowiki>/boot</nowiki></code> is. Then simply match it with the Grub-style name in <code><nowiki>device.map</nowiki></code>. This is what ''groot'' should be. Example: |
<pre>$ df /boot | <pre>$ df /boot | ||
Filesystem Size Used Avail Use% Mounted on | Filesystem Size Used Avail Use% Mounted on | ||
第34行: | 第37行: | ||
(hd0) /dev/hda | (hd0) /dev/hda | ||
(hd1) /dev/sda</pre> | (hd1) /dev/sda</pre> | ||
− | So ''groot'' should be (hd1,4) (note that Grub partition numbers are always one less than Linux numbers). Thus in <code><nowiki>/boot/grub/menu.lst</nowiki></code>, | + | So ''groot'' should be (hd1,4) (note that Grub partition numbers are always one less than Linux numbers). Thus in <code><nowiki>/boot/grub/menu.lst</nowiki></code>, |
<pre>## default grub root device | <pre>## default grub root device | ||
# groot=(hd1,4)</pre> | # groot=(hd1,4)</pre> | ||
− | Finding kernel root The other piece of the puzzle is telling the kernel where <code><nowiki>/</nowiki></code> is. Simply find out where <code><nowiki>/</nowiki></code> is mounted. <code><nowiki>df /</nowiki></code> This is what ''root'' should be in ''kopt''. Example: | + | Finding kernel root The other piece of the puzzle is telling the kernel where <code><nowiki>/</nowiki></code> is. Simply find out where <code><nowiki>/</nowiki></code> is mounted. <code><nowiki>df /</nowiki></code> This is what ''root'' should be in ''kopt''. Example: |
<pre>$ df / | <pre>$ df / | ||
Filesystem Size Used Avail Use% Mounted on | Filesystem Size Used Avail Use% Mounted on | ||
/dev/sda3 14G 8.3G 5.0G 63% /</pre> | /dev/sda3 14G 8.3G 5.0G 63% /</pre> | ||
− | <code><nowiki>/</nowiki></code> is on <code><nowiki>/dev/hda3</nowiki></code>. Because this is going to be passed to the kernel, there's no need to translate to Grub notation. The 'ro' causes the kernel to mount the drive read-only initially; later the drive will be remounted read/write. This is generally done so <code><nowiki>fsck</nowiki></code> can run on <code><nowiki>/</nowiki></code> at bootup. | + | <code><nowiki>/</nowiki></code> is on <code><nowiki>/dev/hda3</nowiki></code>. Because this is going to be passed to the kernel, there's no need to translate to Grub notation. The 'ro' causes the kernel to mount the drive read-only initially; later the drive will be remounted read/write. This is generally done so <code><nowiki>fsck</nowiki></code> can run on <code><nowiki>/</nowiki></code> at bootup. |
<pre>## default kernel options | <pre>## default kernel options | ||
# kopt=root=/dev/sda3 ro</pre> | # kopt=root=/dev/sda3 ro</pre> | ||
− | In summary, ''groot'' is where <code><nowiki>/boot</nowiki></code> is, and is what Grub sees that drive as. ''kopt=root'' is where <code><nowiki>/</nowiki></code> is, and is what the kernel sees that drive as. | + | In summary, ''groot'' is where <code><nowiki>/boot</nowiki></code> is, and is what Grub sees that drive as. ''kopt=root'' is where <code><nowiki>/</nowiki></code> is, and is what the kernel sees that drive as. |
− | + | ||
− | + | ||
− | + | === Boot splash images === | |
− | + | 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. | |
− | + | I'm out of laegue here. Too much brain power on display! | |
− | + | ||
− | + | ||
− | + | ||
− | ==== Splash Image with update-grub ==== | + | ==== 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)]. | + | 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)]. |
<pre>sudo apt-get install grub-splashimages | <pre>sudo apt-get install grub-splashimages | ||
sudo ln -s /boot/grub/splashimages/my_image.xpm.gz /boot/grub/splash.xpm.gz | sudo ln -s /boot/grub/splashimages/my_image.xpm.gz /boot/grub/splash.xpm.gz | ||
sudo update-grub</pre> | sudo update-grub</pre> | ||
− | '''Note:''' replace the my_image.xpm.gz with the one that you want. | + | '''Note:''' replace the my_image.xpm.gz with the one that you want. |
− | === Backup, Repairing and Reinstalling GRUB === | + | === Backup, Repairing and Reinstalling GRUB === |
− | To make a backup a copy of the existing menu.lst file use: cp /boot/grub/menu.lst /boot/grub/menu.lst.old You can try re-installing the grub using the Ubuntu Live CD, in two different ways. | + | To make a backup a copy of the existing menu.lst file use: cp /boot/grub/menu.lst /boot/grub/menu.lst.old You can try re-installing the grub using the Ubuntu Live CD, in two different ways. |
− | ==== GUI ==== | + | ==== GUI ==== |
− | # Boot your computer up with Ubuntu CD | + | #Boot your computer up with Ubuntu CD |
− | # Go through all the process until you reach "[!!!] Disk Partition" | + | #Go through all the process until you reach "[!!!] Disk Partition" |
− | # Select Manual Partition | + | #Select Manual Partition |
− | # Mount your appropriate linux partions | + | #Mount your appropriate linux partions |
<pre>/ | <pre>/ | ||
/boot | /boot | ||
第80行: | 第78行: | ||
..... | ..... | ||
</pre> | </pre> | ||
− | 5.#5 DO NOT FORMAT THEM. | + | 5.#5 DO NOT FORMAT THEM. |
− | # Finish the manual partition | + | #Finish the manual partition |
− | # Say "Yes" when it asks you to save the changes | + | #Say "Yes" when it asks you to save the changes |
− | # It will give you errors saying that "the system couldn't install ....." after that | + | #It will give you errors saying that "the system couldn't install ....." after that |
− | # Ignore them, keep select "continue" until you get back to the Ubuntu installation menu | + | #Ignore them, keep select "continue" until you get back to the Ubuntu installation menu |
− | 10. Jump to "Install Grub ...." 11. Once it is finished, just restart your computer | + | 10. Jump to "Install Grub ...." 11. Once it is finished, just restart your computer |
− | ==== Command line ==== | + | ==== Command line ==== |
− | # Boot your computer up with Ubuntu CD | + | #Boot your computer up with Ubuntu CD |
− | # Open a terminal window or switch to a tty. | + | #Open a terminal window or switch to a tty. |
− | # Go SuperUser (that is, type "sudo -s"). Enter root passwords as necessary. | + | #Go SuperUser (that is, type "sudo -s"). Enter root passwords as necessary. |
− | # Type "grub" | + | #Type "grub" |
− | # Type "find /boot/grub/stage1". You'll get a response like "(hd1,0)". Use whatever your computer spits out for the following lines. | + | #Type "find /boot/grub/stage1". You'll get a response like "(hd1,0)". Use whatever your computer spits out for the following lines. |
− | # Type "root (hd1,0)", or whatever your harddisk + boot partition numbers are for Ubuntu. | + | #Type "root (hd1,0)", or whatever your harddisk + boot partition numbers are for Ubuntu. |
− | # Type "setup (hd1,0)", ot whatever your harddisk nr is. | + | #Type "setup (hd1,0)", ot whatever your harddisk nr is. |
− | # Quit grub by typing "quit". | + | #Quit grub by typing "quit". |
− | # Reboot and remove the bootable CD. | + | #Reboot and remove the bootable CD. |
− | === Creating a boot floppy === | + | === Creating a boot floppy === |
− | You can use grub to create a boot floppy. See [[UbuntuHelp:GrubHowto/BootFloppy|BootFloppy]] | + | You can use grub to create a boot floppy. See [[UbuntuHelp:GrubHowto/BootFloppy|BootFloppy]] |
− | === Change the default operating system === | + | === 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 [[UbuntuHelp:GrubHowto/ChangeDefaultOS|ChangeDefaultOS]] | + | By default, Grub in Ubuntu boots Ubuntu by default. If you wish to change this to another operating system, see [[UbuntuHelp:GrubHowto/ChangeDefaultOS|ChangeDefaultOS]] |
− | === Network booting === | + | === 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 <code><nowiki>lsmod</nowiki></code> 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 <code><nowiki>### BEGIN AUTOMAGIC KERNELS LIST</nowiki></code> or after <code><nowiki>### END DEBIAN AUTOMAGIC KERNELS LIST</nowiki></code>, otherwise your changes will be wiped out by security updates, etc. | + | 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 <code><nowiki>lsmod</nowiki></code> 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 <code><nowiki>### BEGIN AUTOMAGIC KERNELS LIST</nowiki></code> or after <code><nowiki>### END DEBIAN AUTOMAGIC KERNELS LIST</nowiki></code>, otherwise your changes will be wiped out by security updates, etc. |
<pre>title LTSP | <pre>title LTSP | ||
root (hd0,2) | root (hd0,2) | ||
kernel /boot/(rom you get from rom-o-matic)</pre> | kernel /boot/(rom you get from rom-o-matic)</pre> | ||
− | === Security === | + | === Security === |
− | By editing the boot command in grub, root access can be gained without the need of a password. To avoid this, edit the part "## password ['--md5'] passwd" of `/boot/grub/menu.lst`: | + | By editing the boot command in grub, root access can be gained without the need of a password. To avoid this, edit the part "## password ['--md5'] passwd" of `/boot/grub/menu.lst`: |
<pre>password yourfancyplaintextpassword | <pre>password yourfancyplaintextpassword | ||
</pre> | </pre> | ||
− | Insert the password of your choice. To prevent normal users to read this password, you should also remove read permission for these: | + | Insert the password of your choice. To prevent normal users to read this password, you should also remove read permission for these: |
<pre>sudo chmod o-r /boot/grub/menu.lst | <pre>sudo chmod o-r /boot/grub/menu.lst | ||
</pre> | </pre> | ||
− | You can also use a md5 password, more info in the [http://www.gentoo.org/doc/en/security/security-handbook.xml?part=1&chap=2 Gentoo Security Handbook]. | + | You can also use a md5 password, more info in the [http://www.gentoo.org/doc/en/security/security-handbook.xml?part=1&chap=2 Gentoo Security Handbook]. |
− | === Windows === | + | === Windows === |
− | See : | + | See : |
− | * [[UbuntuHelp:WindowsDualBoot|WindowsDualBoot]] | + | *[[UbuntuHelp:WindowsDualBoot|WindowsDualBoot]] |
− | * [[UbuntuHelp:RecoveringUbuntuAfterInstallingWindows|RecoveringUbuntuAfterInstallingWindows]] | + | *[[UbuntuHelp:RecoveringUbuntuAfterInstallingWindows|RecoveringUbuntuAfterInstallingWindows]] |
− | === More information === | + | === More information === |
− | * The official [http://www.gnu.org/software/grub/manual/html_node/index.html GNU GRUB manual] has a "DOS/Windows" chapter with hints on setting up dual-boot systems. | + | *The official [http://www.gnu.org/software/grub/manual/html_node/index.html GNU GRUB manual] has a "DOS/Windows" chapter with hints on setting up dual-boot systems. |
− | * [http://users.bigpond.net.au/hermanzone/p15.htm This] page has a lot of Grub information (and other general information). | + | *[http://users.bigpond.net.au/hermanzone/p15.htm This] page has a lot of Grub information (and other general information). |
− | * [http://www.howtogeek.com/howto/ubuntu/reinstall-ubuntu-grub-bootloader-after-windows-wipes-it-out/ Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out] | + | *[http://www.howtogeek.com/howto/ubuntu/reinstall-ubuntu-grub-bootloader-after-windows-wipes-it-out/ Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out] |
− | * [http://www.gnu.org/software/grub/manual/grub.html#Installing-GRUB-using-grub_002dinstall Installing GRUB using grub-install] | + | *[http://www.gnu.org/software/grub/manual/grub.html#Installing-GRUB-using-grub_002dinstall Installing GRUB using grub-install] |
− | * [http://linuxmint.com/wiki/index.php/How_to_repair_your_grub How To Repair your GRUB] | + | *[http://linuxmint.com/wiki/index.php/How_to_repair_your_grub How To Repair your GRUB] |
− | * [[UbuntuHelp:HowtoPartition|HowtoPartition]] | + | *[[UbuntuHelp:HowtoPartition|HowtoPartition]] |
== Other Languages == | == Other Languages == |
2011年8月16日 (二) 22:40的最新版本
点击翻译: |
English • 中文 |
目录
- 1 GRUB
- 1.1 修改GRUB的引导选项Modifying boot options in GRUB
- 1.2 自发现内核列表
- 1.3 Setting kernel parameters
- 1.4 If /boot is on another partition
- 1.5 Changing the Disk that Grub is installed to
- 1.6 Boot splash images
- 1.7 Backup, Repairing and Reinstalling GRUB
- 1.8 Creating a boot floppy
- 1.9 Change the default operating system
- 1.10 Network booting
- 1.11 Security
- 1.12 Windows
- 1.13 More information
- 2 Other Languages
GRUB
GRUB是一种引导加载器,换句话说,它是计算机启动后第一个加载的东东。它可实现多个操作系统多重引导,不管这些操作系统安装于同一个硬盘,还是多个硬盘。例如,你可以同时在计算机上安装Windows和Linux,GRUB先于操作系统启动,它加载后允许你选择是启动Windows还是启动Linux。你还可以使用GRUB创建紧急引导软盘。
请确保你用sudo或root帐户启动GRUB。普通用户也能启动GRUB控制台,但缺乏足够的特权,会导致很多古怪的错误信息。例如,实际的错误是“拒绝访问”,但是GRUB给出的错误信息是“找不到硬盘”。根据这些虚假错误信息去排除故障,会让你很沮丧。
修改GRUB的引导选项Modifying boot options in GRUB
要想进入GRUB的菜单修改引导选项或者选择不同的内核,只需要在它启动后按“ESC”键。在默认配置下,你必须手脚敏捷地按动“ESC”键。如果不想那么狼狈,可以编辑GRUB的配置文件/boot/grub/menu.lst,增加TIMEOUT部分的时间值。或者,你可以要求GRUB在每次启动时都自动打开菜单。要做到这一点,请在“hiddenmenu”前面加上注释号“#”。After pressing 'ESC' you will be presented with a list of kernels and operating systems that you can boot. To modify the boot options highlight the operating system you want to edit and press 'e'. There you will be presented with lines starting with 'root', 'kernel', 'initrd', 'quiet' and 'savedefault'. To receive a more verbose boot process you can remove the 'quiet' line by highlighting it and pressing 'd' to remove that line. You will also need to highlight the 'kernel' line press 'e' to edit and remove the word 'splash' from the end of the line . After making any necessary modifications you can press 'b' to boot that operating system. These modifications will not persist across reboots. 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 使用一个叫做 update-grub
的工具去维护menu.lst
. 该工具自动监测你 /boot
下的内核, 并为每一个内核应用全局的设置. 任何时候你一旦更新了内核, update-grub
将会自动运行去更新grub设置. update-grub
更新后的相关区域对应于文件 menu.lst
"### BEGIN AUTOMAGIC KERNELS LIST" 和 "### END DEBIAN AUTOMAGIC KERNELS LIST" 之间的文本. 注释前至少有两个 '#', 例如: '## this is a comment'. 全局设置以单个 '#' 开头, 例如: '# groot=(hd0,4)'. 我们最常更新的是groot选项,当 /boot
目录与 /
目录不在同一个分区上的时候你就需要更改groot选项,关于这一点的更多信息见本页相应的部分. 另一个常见选项是 'kopt=', 该选项应用于所有内核.
Setting kernel parameters
In `/boot/grub/menu.lst`, you will find a line like this: # kopt=root=/dev/sda1 ro
This looks like a comment, but do not remove the '# ' at the beginning. /!\ THIS IS IMPORTANT: grub
sees this line as a comment and ignores it, but it is used as a configuration parameter by update-grub
to generate the contents of the file that grub
will read at boot. 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`: # kopt=root=/dev/sda1 ro noapic
After editing the file, run: sudo update-grub
Note that you can temporarily add kernel parameters at the grub boot menu also, by pressing 'e ' and editing the kernel line.
If /boot is on another partition
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 the grub
boot loader to a boot sector. 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:
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.
Changing the Disk that Grub is installed to
Consider the following problem: You have two hard drives, one SATA (/dev/sda), the other PATA (/dev/hda). Your BIOS seems to think that PATA drives should always be booted in preference of SATA drives, but you want to boot from the SATA drive. Grub can work around this problem. Finding groot First, figure out what Grub names the drives. This is listed in /boot/grub/device.map
. There you will find a table of Grub-style names (e.g. (hd0)) and Linux-style names (e.g. /dev/hda/). You need to know what drive and partition /boot
is on. To find where /boot
is, use df
: df /boot
This should tell you the Linux-style partition name where /boot
is. Then simply match it with the Grub-style name in device.map
. This is what groot should be. Example:
$ df /boot Filesystem Size Used Avail Use% Mounted on /dev/sda5 46M 15M 30M 33% /boot $ cat /boot/grub/device.map (hd0) /dev/hda (hd1) /dev/sda
So groot should be (hd1,4) (note that Grub partition numbers are always one less than Linux numbers). Thus in /boot/grub/menu.lst
,
## default grub root device # groot=(hd1,4)
Finding kernel root The other piece of the puzzle is telling the kernel where /
is. Simply find out where /
is mounted. df /
This is what root should be in kopt. Example:
$ df / Filesystem Size Used Avail Use% Mounted on /dev/sda3 14G 8.3G 5.0G 63% /
/
is on /dev/hda3
. Because this is going to be passed to the kernel, there's no need to translate to Grub notation. The 'ro' causes the kernel to mount the drive read-only initially; later the drive will be remounted read/write. This is generally done so fsck
can run on /
at bootup.
## default kernel options # kopt=root=/dev/sda3 ro
In summary, groot is where /boot
is, and is what Grub sees that drive as. kopt=root is where /
is, and is what the kernel sees that drive as.
Boot splash images
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.
I'm out of laegue here. Too much brain power on display!
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.
Backup, Repairing and Reinstalling GRUB
To make a backup a copy of the existing menu.lst file use: cp /boot/grub/menu.lst /boot/grub/menu.lst.old You can try re-installing the grub using the Ubuntu Live CD, in two different ways.
GUI
- Boot your computer up with Ubuntu CD
- Go through all the process until you reach "[!!!] Disk Partition"
- Select Manual Partition
- Mount your appropriate linux partions
/ /boot swap .....
5.#5 DO NOT FORMAT THEM.
- Finish the manual partition
- Say "Yes" when it asks you to save the changes
- It will give you errors saying that "the system couldn't install ....." after that
- Ignore them, keep select "continue" until you get back to the Ubuntu installation menu
10. Jump to "Install Grub ...." 11. Once it is finished, just restart your computer
Command line
- Boot your computer up with Ubuntu CD
- Open a terminal window or switch to a tty.
- Go SuperUser (that is, type "sudo -s"). Enter root passwords as necessary.
- Type "grub"
- Type "find /boot/grub/stage1". You'll get a response like "(hd1,0)". Use whatever your computer spits out for the following lines.
- Type "root (hd1,0)", or whatever your harddisk + boot partition numbers are for Ubuntu.
- Type "setup (hd1,0)", ot whatever your harddisk nr is.
- Quit grub by typing "quit".
- Reboot and remove the bootable CD.
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)
Security
By editing the boot command in grub, root access can be gained without the need of a password. To avoid this, edit the part "## password ['--md5'] passwd" of `/boot/grub/menu.lst`:
password yourfancyplaintextpassword
Insert the password of your choice. To prevent normal users to read this password, you should also remove read permission for these:
sudo chmod o-r /boot/grub/menu.lst
You can also use a md5 password, more info in the Gentoo Security Handbook.
Windows
See :
More information
- The official GNU GRUB manual has a "DOS/Windows" chapter with hints on setting up dual-boot systems.
- This page has a lot of Grub information (and other general information).
- Reinstall Ubuntu Grub Bootloader After Windows Wipes it Out
- Installing GRUB using grub-install
- How To Repair your GRUB
- HowtoPartition
Other Languages
ComoGrub (Spanish)