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
[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] 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.