Grub Legacy
Recently, while preparing for the LPIC 1 exam, I had to dig into something I’ve never wanted to touch: grub.
Now that I have grasped a fair amount of it, I hope this little blog can be of some help to others.
This post is going to:
- Describe very briefly how
grub legacyworks. - Give instruction to install
grub legacyonto a hard drive.
This post assumes basic understanding of:
- Boot loaders in general
- Hard disk concepts such as partition, filesystem, partition table, Master Boot Record, Partition Boot Record…
During learning about grub legacy and composing this blog, I found materials at GRUB bootloader - Full tutorial and GNU GRUB Manual 0.97 specially helpful.
How it works
- When control is passed to the grub bootloader, it reads the configuration from
/boot/grub/menu.ls - The configuration file typically contains
- Default options for grub: waiting time before loading the default OS/bootloader, default OS/bootloader
- List of menu entries: each is either instruction to load an OS or another bootloader
Install Grub Legacy onto an MBR-formatted hard disk
A Little reminder of BIOS system boot up process
- After BIOS does its work, control is passed to the first stage bootloader in the MBR of the disk which is marked bootable.
- This first stage bootloader then loads the second stage bootloader (we’ll skip the 1.5 stage bootloader).
- The second stage bootloader takes care of loading the OS.
In the case of grub legacy:
- The second stage bootloader then loads the grub configuration file
- The configuration file is at
/boot/grub/menu.ls
What does installing grub onto a hard disk mean?
It means installing/copying the first stage boot loader onto the disk’s MBR and the second stage bootloader onto the hard disk.
I find the easiest way to install grub onto a hard disk is using the grub-install command as follows:
- Boot into a running Linux machine which has
grub legacyinstalled (such asubuntu 9.04). - Make sure the hard disk is MBR formated.
- Create a partition along with a filesystem on the hard disk and mount it.
- Run `grub-install –boot-directory=
The last command does 3 things:
- Install the first stage bootloader onto the disk’s MBR.
- Install the second stage bootloader onto the disk.
- Create a
/bootdirectory containing files necessary forgrubto work.
You can then attach this hard drive to another machine. If you config its BIOS to boot from this hard disk, you will be able to boot into the grub bootloader from the disk.