Search My Blog

Sunday, October 30, 2011

GRUB bootloader - Full tutorial

GRUB bootloader - Full tutorial

This tutorial focuses on GRUB legacy. If you're looking for a tutorial on GRUB 2, the next generation of the popular bootloader, please take a look at this article.

One of the most frightening things about Linux is the horrible word bootloader. The primary reason for this is the fact that most new Linux users have only ever used Windows operating systems. In the Windows world, they have never bothered with bootloaders. For them, the issue of a system booting was a transparent one. At most, they would use Windows Recovery Console to fix problems for them. Thus, they have been spared the need to learn about the single most important piece of software on a computer - the little program that makes it all work.

This article is supposed to provide you with basic understanding of the GRUB bootloader. If you have read my other Linux articles, you are familiar with partitioning and Linux notation, as well as with the command line. The next logical step is to enhance this knowledge by taking one step further. Understanding how GRUB works and what boot entries in the boot menu mean will help you understand how the operating systems work, how to fix, recover or modify the GRUB menu to suit your needs, and how to setup different work environments with several operating systems.

In the past, we have relied on the installation setups to make the hard work for us. In fact, setting up GRUB, while frightening, is a quite simple and fully reversible procedure. Mastering the GRUB is a very important step in building up the confidence to use Linux.

So if you are ready, read on.

But first of all, a foreword of wisdom. This article is a compilation of sources and examples that will help you learn about GRUB. Of course, it's all out there somewhere, on the Internet. However, new Linux users will probably find the notion of spending hours searching for relevant pieces of information (especially if their PC won't boot) somewhat frustrating. The goal of this guide is to help provide simple and quick solutions to most common problems regarding multi-boot setups and installation of Linux operating systems.


Table of contents


  1. Everything is a file
  2. Introduction
    1. What about LILO?
  3. How does GRUB work?
  4. GRUB notation
  5. GRUB configuration
    1. Installation of GRUB
      1. GRUB on a floppy disk
      2. Installing GRUB natively
      3. Installing GRUB with grub-install
    2. Setting up GRUB manually (after installation)
      1. Backup!
      2. Adding a new operating system to the GRUB menu
  6. Common problems
    1. GRUB got deleted; how to restore?
      1. The easy way
      2. The hard way
    2. Windows is installed on a non-first hard disk (Swapping)
    3. There is more than one Windows operating system installed on one hard disk (Hide/Unhide)
    4. You resized a partition; GRUB is gone
  7. Useful tools
  8. Extras for special geeks
  9. Links
    1. My other articles
    2. General information (by alphabetic order)


Skipping on down...

Installing GRUB natively

Native install means placing GRUB Stage 1 in the first sector of the hard disk (MBR or Partition Table). This means you will be able to boot without a secondary device, like a floppy disk (which have become a rarity nowadays). However, this also means that if you install an inconsiderate OS later on (like Windows) or try to repair the MBR for some reason (by running fdisk /MBR from DOS prompt), you will erase the GRUB and render all systems listed in the menu.lst unbootable.

To install GRUB in MBR, you will need to boot from external media (floppy, live Linux CD). Then, once you reach the GRUB prompt, execute the following commands:

Find the GRUB root device:

find /boot/grub/stage1

GRUB will search for all available Stages 1 and present them. If you have more than one operating system image present (e.g. SUSE, Kubuntu, Mandriva), you will have more than one stage1 available.

Example:

Let's say the computer has the following operating systems installed on different partitions:

  • SUSE on (hd0,1)
  • Kubuntu on (hd0,2)
  • Mandriva on (hd0,4)

All these will be returned as potential roots for GRUB device (as each OS has its own files).

If you wish to use SUSE GRUB, then you will setup the GRUB root device to (hd0,1):

root (hd0,1)

If you want Mandriva's GRUB, then:

root (hd0,4)

If you know in advance what you want to do, you can skip the find command.

Once you have decided on the root, you need to write the information to the MBR:

setup (hd0)

Finally, quit the GRUB prompt:

quit

As a sequence, the commands that you need are:

find /boot/grub/stage1 (optional)
root (hdX,Y)
setup (hd0)
quit

You can also setup GRUB on another drive or partition, but then you will have to chainload GRUB to another bootloader for this to work.

That's it. Easy peasy orange squeasy!

Installing GRUB with grub-install

This method is considered less safe (according to the Manual), as it guesses the mapping. Still, for total newbs in need of dire help, this might be the preferred method.

You only need to invoke a single command - namely, where to install the bootloader. Furthermore, this command can be written in several ways, all equivalent:

grub-install /dev/hda

grub-install /dev/hd0

grub-install '(hd0)'

grub-install hd0

After you have installed the GRUB, your operating systems should boot. Once booted, you can once again start playing with GRUB, manually changing settings - adding and removing entries, chainloading other bootloaders, or even hiding and unhiding partitions.

Setting up GRUB manually (after installation)

You can reconfigure or reinstall GRUB at any moment.

Backup!

First, before you make any changes to the GRUB configuration file, it is most warmly recommended that you backup the existing menu. You might even consider copying to another machine or printing the menu, in case things go bunkerous.

cp /boot/grub/menu.lst /boot/grub/menu.lst_backup

To access GRUB, execute the following command in Linux terminal:

sudo grub

After a few moments, the GRUB command line should show up. You can identify it by the grub> prompt.

Alternatively, you can reach the GRUB command line during bootup. When the GRUB menu loads, press C on the keyboard.

Adding a new operating system to the GRUB menu

Let's say you have installed yet another operating system on your machine, Sabayon. During the installation, you skip the GRUB setup. This means that the original GRUB remains untouched - and it does not contain an entry about Sabayon. For all practical purposes, Sabayon is not bootable.

Note: GRUB menu entries are called stanzas (probably a twist of instance?).

So, we need to add Sabayon to the list.

If you know where Sabayon is installed, you just need to add its entry to the menu.lst.

title Sabayon
root (hdX,Y)
chainloader +1

That's it.

You can also do this while booting the computer, without editing the menu. When the original GRUB comes up, press C to reach the command line. And then:

root (hdX,Y)
chainloader +1

Optionally, you will use the find command to get around.

Basically, this is the whole of GRUB magic. As you can see, it's very very simple. But for people who have never heard of GRUB and see long lists of strange commands, the prospect can be daunting.

Now that we have covered the basics of grubbing, it's time for extras and some more common problems.

Common problems

GRUB got deleted; how to restore?

This will often happen if you install Windows after Linux. Windows assumes it's the only operating system in the world and does not try to live with existing information present in the MBR; it overwrites it. For people with dual-boot and very little knowledge of Linux, this is a disaster. Luckily, it's very easily recoverable one.

The easy way

Use Super Grub Disk. I have written about this tool in detail in my article A (cool) list of Linux tools, under Rescue.

The hard way

  • Boot from floppy disk or CD (any Linux live CD should do).
  • Get to the grub command line.
find /boot/grub/stage1 (optional)
root (hdX,Y)
setup (hd0)
quit

The same as before!

Windows is installed on a non-first hard disk (Swapping)


Read More...
http://www.dedoimedo.com/computers/grub.html


Grub Boot Loader
install grub boot loader to cd - Google Search
GNU GRUB - Obtaining GRUB
Index of ftp://alpha.gnu.org/gnu/grub/
GRUB bootloader - Full tutorial
GRUB bootloader - Full tutorial
GRUB bootloader - Full tutorial
How to make a Grub floppy/CD that boots all systems in a PC - JustLinux Forums
grub loading error 15
Help - Grub error 15 - Linux Forums
RE: Grub Loading Error 15 (Solved!)
Super Grub Disk Webpage
Grub2 info
BIOS Implementation Test Suite
How to add XP / Vista / Windows install iso to GRUB2 multiboot? - Hak5 Forums
Mastering Grub 2 The Easy Way
supergrub disk 2 - Google Search
Super Grub(2) Disk (English)
Boot Problems Open Source Tools | Super Grub Disk, Super Grub2 Disk and Rescatux
Rescatux | Boot Problems Open Source Tools
Rescatux | Boot Problems Open Source Tools

Grub2 and os-prober
DonsDeals: My brand new Debian 6 grub menu had no mention of WinXP:O
os-prober - Google Search
DonsDeals: Automatically adding other distributions to Fedora Grub using os-prober « Hedayat’s Blog
Hope this helps...

Don

No comments: