GNU GRUB 0.97 Installation

Prepared by: Nishant Limbachia
Last Updated: June 26, 2005

If you are reading this, you probably know about Linux and boot loaders but haven't downloaded, installed and configured one or you are one of those people who want to change their bootloader, most likely from LILO to GRUB. I will illustrate procedure you need to follow to install and configure GNU GRand Unified Bootloader (a.k.a GRUB) onto a floppy and Master Boot Record of hard drive. I should tell you that this tutorial is primarily written for grub installation on Slackware Linux.

I would start with a brief introduction of grub. More information on grub can be obtained via the official grub website. If you want to know all about grub, there's a complete manual of grub on the grub website. You can get the latest source code of grub from ftp://alpha.gnu.org/gnu/grub/.

  1. Download the source to your location of choice...for this example I assume /home/~user. Please replace ~user with your username or you can use any other directory of your choice.

  2. cd to the directory you downloaded grub source (/home/~user in this case).
  3. tar -zxvf grub-0.97.tar.gz
    ...this will create a directory grub-0.97.

  4. cd grub-0.97
  5. Now we start the configuration and installation procedure. I generally build using --prefix option. That way I can install the software at the location of my preference rather than the default location (which is mostly /usr/local directory). I have chosen /opt/grub as my default installation directory. You can choose whichever directory you want.

  6. ./configure --prefix=/opt/grub
  7. make
  8. make install or checkinstall

  9. Now, we are done with the installation. Now comes the part where we have to install grub either on a floppy or MBR (Master Boot Record) of your hard drive. You would have to be logged in as root to install grub. First, I will illustrate how to install grub on your MBR. Later part of the document takes explains install grub on a floppy. I would recommend the readers to first install grub on a floppy and then proceed with MBR installation.

  10. Lets get started, First create a directory grub in /boot by mkdir /boot/grub.
  11. First,
    cd /opt/grub
    You would see bin, info, lib, man, sbin directories.
  12. cd lib/grub/i386-pc.

  13. There you'll see all the stage files. Copy all the files from this directory to the newly created directory /boot/grub.
  14. Now get down into sbin directory and copy grub, grub-install, grub-md5-crypt, grub-terminfo and grub-set-default to /boot/grub.
  15. Before we start installing grub, lets take a look at how grub interprets your hard drive geometry. Grub refers to disk and partitions starting from zero. Hence first hard drive would be hd0 while second hard drive would be hd1. Similarly, first partition on first hard drive would be (hd0,0) and second partition on second drive would be (hd1,1).

    Now we will build the grub configuration file, which will present nice and selectable menu interface at boot time. I will only present few and required sections of the grub configuration file to produce a workable configuration file. Create a file /boot/grub/menu.lst. This will be our grub configuration file.

    -------------GRUB CONFIG SECTIONS--------------------
    Color Section is used to produce a nice background and foreground color
    	color cyan/blue white/blue
    
    Shaded Text Section is used to shade the selected menu entry in grub.
    	shade 1
    
    
    Time Out Section is used to boot the default operating system if there is no user
    intervention within time out at the grub interface. Time out measures time in seconds.
    timeout 20 will boot the default operating system after 20 seconds, if there is no user
    intervention within the timeout. timeout 20 Default Section is used to boot the operating system without user intervention.
    Grub counts the number from zero. Hence, default 1 will actually boot the second entry on the menu. default 1 Menu Section is used to put the entries that will show up on grub menu and which
    you will eventually boot. The disk geometry shown in the entries are entirely mine and yours
    can be different so be sure to double check where your OS are installed. I have not mentioned
    Initial RAM Disk (initrd) since I don't use them. Please include them after
    the kernel line if you use them.
    title is where you put the menu entry you would like to show up on the grub menu. title Slackware Linux kernel (hd1,0)/boot/vmlinuz-2.6.11.11 ro root=/dev/hdb1 title Windows XP Professional root (hd0,0) chainloader +1 --------------------------------------------------

    We are now done with the configuration file. I must stress the importance of a boot disk should anything go wrong while installation. If anything goes wrong you may not be able to boot into any OS hence I strongly recommend you first create a grub floppy. I have illustrated grub floppy creation at the end of this tutorial. Having said that, let's go to grub installation to the MBR.

  16. cd /boot/grub and run
  17. ./grub - this will start a grub shell. A grub shell is a cousin of bash shell albeit with less capabilities. The shell will give you a prompt like below:
  18. grub >
  19. At the grub prompt, type the following line and press enter.
  20. install (hd1,0)/boot/grub/stage1 (hd0) (hd1,0)/boot/grub/stage2 p (hd1,0)/boot/grub/menu.lst
    
  21. The command actually combines multiple commands into one. First part, install (hd1,0)/boot/grub/stage1 (hd0) actually locates stage1 and installs it onto MBR. Second part, (hd1,0)/boot/grub/stage2 tells grub where stage2 is located. The last part, p (hd1,0)/boot/grub/menu.lst tells grub where the configuration file is located.
  22. After the grub installs, you will be returned to the grub prompt. Enter quit to exit grub shell. By now, you've installed grub onto the MBR. Just to be sure that we have not messed up, we'll create a grub floppy.
  23. cd /boot/grub & insert a formatted floppy into your floppy drive.
  24. Enter the following commands while in /boot/grub & execute
  25. dd if=stage1 of=/dev/fd0 bs=512 count=1
  26. You will be returned back to grub shell, the output is pretty straightforward so you'll know whether the execution succedded. Now enter the following command & execute
  27. dd if=stage2 of=/dev/fd0 bs=512 seek=1

    By now you are all set to use the grub boot loader...remember to take the floppy out of the drive. Cross your fingers and enjoy!!!

I'm including the sample grub configuration file for reference.

---------------------########--------------------------
###GRUB Configuration file generated by Nishant 6/7/2005

###Color foreground/background 
color cyan/blue white/blue

###Shaded Text Entries
shade 1

###Time out in seconds before default entry in booted
timeout 20

###Default OS to boot
default 1

###The OS to boot go here...

title Slackware Linux
kernel (hd1,0)/boot/vmlinuz-2.6.11.11 ro root=/dev/hdb1

title Windows XP Professional
root (hd0,0)
chainloader +1
----------------------########--------------------------