GRUB
From ArchWiki
| Article summary |
|---|
| Covers various aspects of Archlinux's default bootloader, GRand Unified Bootloader (GRUB). |
| Available in languages |
| English |
| עברית |
| 简体中文 |
| Русский |
| Español |
| Related articles |
| Reinstalling GRUB |
| Grub configure examples |
| Grub-gfx |
Contents |
[edit] Installing Grub package
First install grub with pacman
pacman -Sy grub
Edit the menu.lst with your settings
nano /boot/grub/menu.lst
Note: Use hd[a-z] for ide and sd[a-z] for scsi and sata
Here is mine for example:
# 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 resume=swap:/dev/sda5 initrd /kernel26thinkpad.img
Copy the mounts to mtab
grep -v rootfs /proc/mounts > /etc/mtab
[edit] Installing the boot loader into Master Boot Record
Now usually there are two ways to install GRUB. One way is to make a boot disk (on a floppy drive, or cd-rom), and the other way is to install grub directly from a running Arch install. If you are upgrading a version of grub you might want to do the latter because its simpler and faster, but the GRUB website states that doing the boot disk method is safer.
Using the grub-install utility
grub-install --root-directory Mount-Point (hdn)
Installs grub into the MBR of a hard disc. The option gives the path to the kernel-image, if it is not in /, i.e. in /boot.
(hdn) is a disc, where n is the number of the disc, starting with 0.
Example:
If you have a separate boot partition mounted at /boot, specify the disk that contains the /boot partition and run this command
grub-install hd0 grub-install sda grub-install hda
Warning GRUB does not understand the naming schemes hda, sda, etc. It views the disk in terms of (hd0), (hd1), etc. This is why one 'must' be careful when using grub-install.
grub-install tries to map the BIOS drives to hda/sda format, and usually it does this correctly. The way to check if this is done correctly is provided by the command after it has finished installing the bootloader. grub-install will print something along the lines of
(fd0) /dev/fd0 (hd0) /dev/hda
You have to check if this mapping is correct. If it is not correct, go to /boot/grub and edit the 'device.map' file so that it is correct. Then re-run the grub-install utility to reinstall GRUB.
[edit] Boot loader configuration
The grub configuration is done in this file:
/boot/grub/menu.lst
- (hdn,m) is the partition m on disc n, numbers starting with 0
- splashimage (hdn,m)/grub/Name.xpm.gz is the splash-image-file
- default n is the default boot entry, that is choosen after timout for user action
- timeout m time m to wait in seconds for a user selection, before default is booted
- password -md5 str encrypted boot password 'str'
- title str title string 'str' for a boot entry
- root (hdn,m) base partition, where the kernel is stored to
- kernel /path ro root=/dev/device initrd /initrd.img use the root option, if the kernel not placed in /
- makeactive
chainloader +1 sets root active and gives booting procedure to its boot-loader (for Windows, f.e.) - map (hd0) (hd1)
map (hd1) (hd0) changes primary and secondary disc for a boot, necessary to boot Windows from a secondary disc - root (hdn,m,z)
kernel /boot/loader boots the FreeBSD-Partition x - default saved remembers each current boot selection and makes it the new default. Place "savedefault" at the end of each boot section, for that you want this feature shall be used.
For those who like eye-candy, there is Graphical GRUB.
[edit] Dual booting
These are the two most common ways of configuring the menu.lst file. For more complex uses, click here.
[edit] Dual booting with Windows
Add this at the end of your /boot/grub/menu.lst. This assumes that your Windows partition is [s/h]da2.
# (2) Windows XP title Windows XP rootnoverify (hd0,1) makeactive 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).
[edit] Dual booting with Windows on another hard disk
Add this at the end of your /boot/grub/menu.lst. This assumes that your Windows partition is [s/h]db1.
# (2) Windows XP title Windows XP map (hd0) (hd1) map (hd1) (hd0) rootnoverify (hd1,0) makeactive chainloader +1
The map function tricks your Windows install into thinking that a second hard drive is the primary.
[edit] Dual booting with other linux distros
This is done exactly the same way that Arch linux is loaded. Here we assume that the other distro is on partition [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)
[edit] Dual booting with other linux distro (Chainloading)
To avoid maintenance nightmare, you might want to chainload the GRUB in the MBR to another bootloader you might have installed in the bootrecord of a partition [(hd0,2) in our example] instead of the MBR. This way the auto-magic stuff of some distro will manage the menu.lst on (hd0,2) (if it is grub) for its own distro and you will boot with all the option needed (like the correct last kernel) without the need to copy/paste some part of that menu.lst into yours.
In our example [1], GRUB is in the MBR and some other bootloader (BL) (be it grub or lilo) is in the Boot Record of (hd0,2).
------------------------------------------------- | | | | % (hd0,2) | | M | | | B % | | B | (hd0,0) | (hd0,1) | L % Other | | R | | | % Distro | | | | | % | ------------------------------------------------- | ^ | chainloading | -----------------------------
Then, you simply use in your menu.lst:
title Other Linux distro root (hd0,2) chainloader +1
[edit] LiLO and GRUB interaction
If you once had used lilo Don't forget to remove it with
pacman -R lilo
as some tasks (f.e. kernel compilation using make all) will make a lilo call, and then lilo is installed over grub.
Note that this will not remove lilo from the MBR, but it will be overwritten when you install another bootloader.
[edit] Framebuffer Resolution
One can use the resolution given in the menu.lst of grub. But you might want to use your LCD wide-screen at its full native resolution. Here is what you can do to achieve this.
On wikipedia, there is a list of extended framebuffer resolution (i.e beyond the ones in the VBE standard). But, for example, the one i want to use is 1440x900 and the vga=867 does not work. May be because those resolution are outside of the standard and every graphic card manufacturer use the code they like.
So instead of using that table, i suggest using this method:
[edit] How to find the correct code to use for the resolution you want to use
- install lrmi package from [community] repository
- run vbetest as root and in a console already running on framebuffer. It will not work in a terminal in X.
- then note the number in [ ] corresponding to your desired resolution
- Press 'q' to quit vbetest interactive prompt. If you want to test the resolution you have just picked up, you can run vbetest -m yournumberhere to test the resolution. You will see a checked colored image on your console. It will return to black after some second. If the text of your console is not restored you will have to switch to another console and switch back to have your text restored. (minor glitch)
- add 512 to the previous number and use the total as code to use in vga= kernel option in menu.lst.
- reboot and voilà !
For example, what i got with vbetest is :
[356] 1440x900 (256 color palette) [357] 1440x900 (8:8:8)
so here the number i want is 357. then, 357 + 512 = 869, so i will use vga=869.
Now, you will have a console at the full native resolution of your screen. The next step is to use another font in console at a correct size. In my case i use terminus font named ter-120b
Note:
- (8:8:8) is for 24-bit color (or 32-bit ?)
- (5:6:5) is for 16-bit color
- (5:5:5) is for 15-bit color
[edit] Troubleshooting
[edit] GRUB error 15
Make sure that the kernel line has ro in menu.lst.
[edit] Reboot pulldown menu in KDE does not have any effect
If you've opened a submenu with the list of all operating system configured in grub, selected one and upon restart you still got your default OS, then you might want to check if you have line
default saved
in file /boot/grub/menu.lst.