Using GRUB

Using GRUB

The GRUB homepage can be found at http://www.gnu.org/software/grub/grub.en.html.

This tutorial was written by Chris Giese and is also availible at his site.


================================================================
References
================================================================
This information was gleaned from my own experiments with GRUB
and from the following posts to alt.os.development:

Subject: Re: generic bootloader question
Newsgroups: alt.os.development
From: "Marv" 
Date: Sat, 7 Apr 2001 23:35:20 +0100
References: 
Message-ID: 

Subject: Re: Grub multiboot example
Newsgroups: alt.os.development
From: "Marv" 
Date: Mon, 4 Jun 2001 17:21:17 +0100
References: 
Message-ID: 

Subject: Re: Grub multiboot example
Newsgroups: alt.os.development
From: "Mike Wimpy" 
Date: Thu, 7 Jun 2001 22:17:51 -0700
References:      
Message-ID: 

Subject: Re: grub coff (solved it!)
Newsgroups: alt.os.development
From: "Mark & Candice White" 
Date: Sun, 16 Sep 2001 10:57:34 GMT
References: 
Message-ID: 

================================================================
Getting GRUB
================================================================
Source code:
	ftp://alpha.gnu.org/gnu/grub/grub-0.90.tar.gz

Binaries:
	ftp://alpha.gnu.org/gnu/grub/grub-0.90-i386-pc.tar.gz

DOS and Windows users will need PARTCOPY or RAWRITE:
	http://www.execpc.com/~geezer/johnfine/index.htm#zero
	http://uranus.it.swin.edu.au/~jn/linux/rawwrite.htm
	http://www.tux.org/pub/dos/rawrite/

================================================================
Building GRUB
================================================================
UNIX
----
        configure ; make
(...I think...)

DOS and Windows
---------------
(ha! forget it)

================================================================
Installing GRUB on a floppy with no filesystem
================================================================
1.  Get the GRUB binaries (files "stage1" and "stage2")

2.  Concatenate the files "stage1" and "stage2" into one file:

        (DOS)   copy /b stage1 + stage2 boot

        (UNIX)  cat stage1 stage2 >boot

3.  Write the file "boot" directly to the floppy disk:

        (DOS)   rawrite boot a:
                    -OR-
        (DOS)   partcopy boot 0 168000 -f0

        (UNIX)  cat boot >/dev/fd0

     PARTCOPY will give an error message because the file "boot"
     is much shorter than 0x168000 bytes, but this is OK.

================================================================
Installing GRUB on a floppy with a filesystem
================================================================
1.  Make a bootable GRUB floppy with no filesystem, as described
    above.

2.  Copy the files "stage1" and "stage2" to a second floppy disk,
    one formatted with a filesystem that GRUB recognizes. To use
    the GRUB "setup" command, these files must be stored in
    subdirectory "/boot/grub":

        (DOS)   mkdir a:\boot
                mkdir a:\boot\grub
                copy stage1 a:\boot\grub
                copy stage2 a:\boot\grub

        (UNIX)  mount /dev/fd0 /mnt
                mkdir /mnt/boot
                mkdir /mnt/boot/grub
                cp stage1 /mnt/boot/grub
                cp stage2 /mnt/boot/grub

3.  After GRUB is installed on floppy disk #2, the file "stage2"
    must not be modified, deleted, defragged, or moved. If it
    is modified in any way, the disk will no longer be bootable.
    To prevent this, make the file read-only:

        (DOS)   attrib +r +s stage2

        (UNIX)  chmod a-w stage2

    The DOS command above makes "stage2" a System file as
    well as Read-only. This is needed to protect against DEFRAG.

    NOTE: File "stage1" will be copied into the bootsector. If
    this file is moved or deleted after GRUB is installed, the
    disk will still be bootable.

4.  Boot your computer from the floppy with GRUB but no
    filesystem. At the GRUB prompt, eject this floppy and insert
    the formatted floppy disk (with the filesystem and "stage1"
    and "stage2" files, possibly in directory "/boot/grub".

5a. If files "stage1" and "stage2" are stored in "/boot/grub" on
    disk #2, you can install GRUB on disk #2 simply by typing:

        setup (fd0)

    This is apparently equivalent to this single command line:

        install /boot/grub/stage1 d (fd0) /boot/grub/stage2 p
            /boot/grub/menu.lst

5b. If files "stage1" and "stage2" are stored elsewhere, e.g. in
    subdirectory "/foo", install GRUB on the second floppy disk
    like this (this is also a single command line):

        install=(fd0)/foo/stage1 (fd0) (fd0)/foo/stage2 0x8000 p
            (fd0)/foo/menu.lst

Floppy disk #2 (the disk with the filesystem) is now bootable.

xxx - Boot from disk #2, copy new/modified "stage2", and re-run
"setup" or "install"? Will this work? (xxx - GRUB is not a
shell -- it can't copy files, or list directories -- can it?)

xxx - install syntax:
                0x8000
                This value gets embedded into the bootsector
                of the floppy to indicate the address that
                stage2 should be loaded into memory.

                p
                Modifies stage2, to report to the kernel the partition
                that stage 2 was found on (I think).

                (fd0)/boot/grub/menu.lst
                Modifies stage2, and tells it where to load the
                menu.lst (bootmenu) configuration file from.

================================================================
Making a Multiboot kernel
================================================================
Multiboot header
----------------
Whatever its file format, your kernel MUST have a Multiboot
header. This header
1. must be aligned on a dword (4-byte) boundary, and
2. must appear in the first 8K of the kernel file.

*** NOTE: An address within the first 8K of the .text section
is not necessarily within 8K of the start of the file.

ELF kernels
-----------
GRUB understands the ELF file format directly. If your kernel
is ELF, you can use the simple Multiboot header shown here:

    MULTIBOOT_PAGE_ALIGN   equ 1http://www.multimania.com/placr/binutils.html

(xxx - this server is often difficult to reach. Someone should
mirror these tools. I'm near my disk quota :)

I recommend building a regular COFF kernel, then doing this:
        objcopy-elf -O elf32-i386 krnl.cof krnl.elf

Failing this, you can make GRUB load a COFF kernel by using the
"aout kludge". This uses additional fields at the end of the
Multiboot header, like this:

    MULTIBOOT_PAGE_ALIGN   equ 1
	...
	int main(multiboot_info_t *boot_info)
	{       if(boot_info->flags & 2)
		{       kprintf("the command line is:\n'%s'\n",
				(char *)boot_info->cmdline); }
                ...

xxx - more info

================================================================
Making a boot menu (file "menu.lst")
================================================================
Example 1:
        # Entry 0:
        title   WildMagnolia
        root    (fd0)
        kernel  /boot/kernel.elf
        module  /boot/mod_a
        module  /boot/mod_b

Example 2:
        #
        # Sample boot menu configuration file
        #

        #  default - boot the first entry.
        default 0

        # if have problem - boot the second entry.
        fallback 1

        # after 30 sec boot default.
        timeout 30

        # GNU Hurd
        title  GNU/Hurd
        root   (hd0,0)
        kernel /boot/gnumach.gz root=hd0s1
        module /boot/serverboot.gz

        # Linux - boot ot second HDD
        title  GNU/Linux
        kernel (hd1,0)/vmlinuz root=/dev/hdb1

        # booting Mach - get kernel from floppy
        title  Utah Mach4 multiboot
        root   (hd0,2)
        pause  Insert the diskette now

Related

Report issues via Bona Fide feedback.

2001 - 2024 © Bona Fide OS Development | The Goal | Contributors | How To Help |