|
|||
![]() |
|||
|
|||
|
Booting OS using GRUB.
In previous tutorial, we have seen that BIOS loads the first sector of the bootable media. Loading rest of the kernel is the responsibility of the code written in the first boot sector which itself is a big project. There are boot loader like GRUB, LILO which can load the OS image from the secondary storage device to the RAM and start booting that OS.
Grub is one such multi-boot compliant loader which can recognize different file systems and can locate OS on secondary device. The OS image can be of ELF or a.out format. It can even load OS image from network You can find the information about multi-boot compliant boot loader specification.
In this tutorial, we will see how to make GRUB boot floppy which can load our OS (ELF format) and displays message "Hello world" on screen. One advantage we get from booting using GRUB is that GRUB moves the x86 processor in the protected mode and loads OS above 1MB. So OS can use RAM above 1MB (up to 4GB in 32 bit architecture). It initializes the code segment and data segment base address as 0x0.
Making GRUB floppy
1. Format floppy if it is not formatted. fdformat /dev/fd0
2. Create ext2 FS. mke2fs /dev/fd0
3. Mount floppy. mount -t ext2 /dev/fd0 /mnt/floppy
4. Install grub on floppy. grub-install --root-directory=/mnt/floppy '(fd0)'
This will create grub bootable floppy. It will
create following directories and copy necessary files.
/boot & /boot/grub
5. Create grub.conf file as follows and copy to /mnt/floppy/boot/grub.
default=0
timeout=10
title MyOS
root (fd0)
kernel /boot/kernel
6. Copy the kernel to /mnt/floppy/boot/kernel
7. Unmount floppy. Umount /mnt/floppy
Note : This floppy will display grub menu and is capable of loading kernel (OS image) located at boot directory of floppy.
MyOS:tut2.zip
Here we have three files. start32.s main.c display.c
Start32.S
Grub will look for magic word 0x1BADB002 in the first 8192 bytes of the OS image and loads the OS image. It jumps at _start. This OS will be in ELF format.
Code starts from symbol _start. This code gets executed as follows.
1. Clears eflag registers.
2. Initialize stack.
3. Call function "main" written in "C".
4. Wait indefinitely
5. It should have multi boot compliant header.
Main.c : It prints the message on screen.
Display.c : It has printf function.
Makefile :
Code Zip File : tut2.zip
For any help Contact : ajaylohia_linux@rediffmail.com