GRUB2 (简体中文)
From ArchWiki
Article summary |
---|
Covers various aspects of the next generation of the GRand Unified Bootloader (GRUB2). |
Available in languages |
English |
Česky |
Español |
Français |
Italiano |
Русский |
简体中文 |
Contents |
介绍
关于命令从–GRUB到GRUB2的改变. 你一般都希望新版本能像老版本一样让你感到亲切易用. 等等: "find" 已经被替换为"search"
http://grub.enbug.org/CommandList
在ARCH LINUX上面安装grub2
首先,你需要保证你的网络能正常工作
跳过 de Install Bootloader 这步并退出. 然后
# mount -o bind /dev /mnt/dev # chroot /mnt bash
接下来是安装GRUB2软件包 和安装GRUB到Master Boot Record(MBR).
安装GRUB2软件包
首先,使用PACMAN命令安装GRUB2:
# pacman -S grub2
按照你的实际情况来编辑GRUB2 配置文件. '老的' menu.lst已经被一个新的,名为 grub.cfg替换掉了:
# nano /boot/grub/grub.cfg
这是一个最基础的配置文件的情况
# Config file for GRUB2 - The GNU GRand Unified Bootloader # /boot/grub/grub.cfg # DEVICE NAME CONVERSIONS # # Linux Grub # ------------------------- # /dev/fd0 (fd0) # /dev/sda (hd0) # /dev/sdb2 (hd1,2) # /dev/sda3 (hd0,3) # # Timeout for menu set timeout=5 # Set default boot entry as Entry 0 set default=0 # (0) Arch Linux menuentry "Arch Linux" { set root=(hd0,1) linux /vmlinuz26 root=/dev/sda1 ro initrd /kernel26.img } ## (1) Windows #menuentry "Windows" { #set root=(hd0,3) #chainloader +1 #}
如果你没有一个单独的启动分区, /boot 必须加到 grub.cfg. 例如:
# (0) Arch Linux menuentry "Arch Linux" { set root=(hd0,1) linux /boot/vmlinuz26 root=/dev/sda1 ro initrd /boot/kernel26.img }
如果你使用LVM for your /boot 那么,将下面的内容加到文件最前面?(add following before menuentries:):
insmod lvm
并在你的root行中加入:
set root=(your_lvm_group_name-your_lvm_logical_boot_partition_name)
例如:
# (0) Arch Linux menuentry "Arch Linux" { insmod lvm set root=(VolumeGroup-lv_root) linux /vmlinuz26 root=/dev/mapper/VolumeGroup-lv_root ro initrd /kernel26.img }
Installing or Restoring GRUB2 to the Master Boot Record
GRUB2 may be installed from a live environment, or directly from a running Arch install.
In most cases, installing GRUB2 would be as easy as running the grub-install command as root:
# grub-install /dev/sda
where /dev/sda is the destination of the installation (in this case the MBR of the first SATA disc). If you use LVM for your /boot you can install GRUB2 on multiple physical disc.
If this fails with the error:
grub-probe: error: Cannot get the real path of `/dev/fd0' Auto-detection of a filesystem module failed. Please specify the module with the option `--modules' explicitly.
Try adding --recheck to the arguments as follows:
# grub-install --recheck /dev/sda
Alternatively, you should be able to install GRUB2 by booting the system and running the grub command as root:
# grub {this section is still incomplete, some steps should be added!!!}
(GRUB2 doesn't have an interactive prompt)
Boot loader configuration
The GRUB configuration is done in this file:
/boot/grub/grub.cfg
Be warned this section is incomplete, feel free to put all missing configuration options here!
- (hdn,m) is the partition m on disc n, partition numbers starting with 1, disc numbers starting with 0
- set default=n is the default boot entry, that is choosen after timeout for user action
- set timeout=m – time m to wait in seconds for a user selection, before default is booted
- menuentry "str"{entry options} – title string str for a boot entry & basic layout
- set root=(hdn,m) – base partition, where the kernel is stored to
- linux /path ro root=/dev/device initrd /initrd.img – use the root option, if the kernel not placed in /
- chainloader +1 sets root active and gives booting procedure to its boot-loader (for Windows, e.g.)
For UUID entries:
# blkid
This gives you the UUID. We were doing the following command to set the root device:
# root=/dev/device
Instead, replace it with this:
# root=/dev/disk/by-uuid/bc285871-413 .... and so on, for your UUID.
Dual booting
These are the two most common ways of configuring the grub.cfg file. For more complex uses, feel free to add descriptions here.
With other GNU/Linux distributions
This is done exactly the same way that Arch linux is loaded. Here we assume that the other distro is on partition [s/h]da2.
menuentry "Other Linux" { set root=(hd0,2) linux /boot/vmlinuz (add other options here as required) initrd /boot/initrd.img (if the other kernel uses/needs one) }
With Windows
Add this at the end of your /boot/grub/grub.cfg. This assumes that your Windows partition is [s/h]da3.
# (2) Windows XP menuentry "Windows XP" { set root=(hd0,3) chainloader +1 }
Note, that although commonly believed to be the case, Windows 2000 and later versions do not need to be on the first partition to boot. If the Windows partition changes number (i.e. if you after install add a partition before the windows partition), you will need to edit the Windows boot.ini file to reflect the change (see this article for details on how to do that).
With Windows Vista, via EasyBCD and NeoGRUB
Since EasyBCD's NeoGRUB currently can't understand the GRUB v2 menu format, chain-load to it by replacing the contents of your "C:\NST\menu.lst" file with lines similar to the following:
default 0 timeout 1
title Chainload into GRUB v2 root (hd0,7) kernel /boot/grub/core.img
Tips and tricks
Background Image & Bitmap Fonts
GRUB2 comes with support for background images and bitmap fonts in pf2 format. The unifont font is included in the grub2 package under the filename unicode.pf2, or, as only ascii characters under the name ascii.pf2. Image formats supported include tga, png and jpeg, providing the correct modules are loaded. The maximum supported resolution depends on your hardware. A configuration sample setting a tga file as background is shown below.
if loadfont /usr/share/grub/unicode.pf2 ; then set gfxmode="1024x768x32" insmod gfxterm insmod vbe terminal_output gfxterm if terminal_output gfxterm; then true ; else terminal gfxterm fi fi insmod tga background_image /boot/grub/archlinux.tga
Menu Colors
To change the colors in GRUB2 you would specify one option in /boot/grub/grub.cfg:
set menu_color_normal=light-blue/black set menu_color_highlight=light-cyan/blue
These are the default colors for Arch's release of GRUB-legacy. The available colors for GRUB2 are at http://www.gnu.org/software/grub/manual/html_node/color.html.
Hidden menu
For hiding menu put that code in grub.cfg after picture initialization but before menuentries (e.g. background_image /boot/grub/archlinux.tga).
set timeout=5
echo -n "Press ESC to see the menu... " if sleep --verbose --interruptible 5 ; then set timeout=0 fi
Setting the Framebuffer Resolution
To change the framebuffer resolution in grub2, add a line similar to this to the linux line in grub.cfg:
video=vesafb:mode=1024x768-32 vga=790
In the preceeding statement, the format mode=<resolution>-<colordepth> vga=<fbresolution> is used where fbresolution follows the following scheme:
+-------------------------------------------------+ | 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 +-------------------------------------------------+
Make sure you add the following somewhere, (insmod statements are usually found at the top of the grub.cfg file):
insmod vbe
Troubleshooting
Any troubleshooting should be added here.
msdos-style Error Message
grub-setup: warn: This msdos-style partition label has no post-MBR gap; embedding won't be possible! grub-setup: warn: Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and its use is discouraged. grub-setup: error: If you really want blocklists, use --force.
This error may occur when you try installing GRUB2 in a VMware container. Read more about it here. Hopefully a fix will be provided soon.
Other
I couldn't figure out how to uninstall grub1, and install grub2 to the MBR, as it isn't being booted by default. It is still booting grub1. So, an easy work-around, is rename menu.lst.pacsave or whatever, to menu.lst (in /boot/grub/) and for each menu entry that you would like to use grub2, at the end type "chainloader +1". This will tell grub1 to forward control to grub2. This is an ugly hack though, so I advise setting the menu.lst's timout as 0, otherwise the total timeout would be grub1's time out + grub2's which, for me would equal more than 18 seconds, which is quite a bit.
P.S. hopefully someone figures out how to pry grub1's dead fingers off of my MBR, and place grub2 on it :) .
In my case it had to do with my boot partition. Say boot-partition is (hd0,1) and your root is (hd0,3) (grub2 naming). grub-setup searches for (hd0,3)/boot/grub/core.img. Just because it's on (hd0,1)/grub/core.img, it is unable to find it. So I copied the grub-folder to my root partition and everything worked fine:
E.g. (as root:)
# mount /boot # cp -a /boot/grub / # umount /boot # mv /grub /boot/ # grub-install /dev/sda