GRUB Legacy: Difference between revisions
[unchecked revision] | [unchecked revision] |
Content deleted Content added
mNo edit summary |
|||
(47 intermediate revisions by 23 users not shown) | |||
Line 1:
{{You}}
GRUB stands for GRand Unified Bootloader and is a
==Features==
GRUB takes away all the complexities out of trying to boot your OS by doing it for you. GRUB can handle a variety of filesystems: from MS-DOS FAT systems over Linux ext2fs (Second Extended File System) to BSD FFS, and can load kernels in various binary formats, including "generic" [[ELF]], FreeBSD a.out, flat binary, and "generic" executables (any file with a valid Multiboot header).
One major advantage of GRUB (or more precisely, a Multiboot-compliant bootloader) is that the kernel will be entered in a known state, which includes the [[A20 Line]] having been enabled, and [[Protected mode]] having been entered. This takes a lot of the pain out of writing a kernel, rendering GRUB a very useful tool for the amateur, or anyone who wants to spend more time on the intricacies of the kernel rather than worrying about these generic start-up procedures.
Consult the [http://www.gnu.org/software/grub/manual/multiboot/ Multiboot Specification] if you want to know what GRUB expects and what you can expect from it.
==Installation and booting==
This section describes how to install GRUB on your <em>actual computer</em>, if you are using some kind of emulator (e.g. [[Bochs]]) to test your OS in you're probably more interested in the setup described in e.g. [[Bare bones#Booting the kernel|Booting the kernel]] or [http://www.jamesmolloy.co.uk/tutorial_html/1.-Environment%20setup.html Environment setup]. However, you might still be interested in [[#Load your kernel over network (TFTP)|how to load your kernel over TFTP]].
===Installing to floppy===
This tutorial will show you how to install GRUB and your self-made kernel on a floppy disk, to avoid screwing up your hard drive. Installing GRUB as your system bootloader depends heavily on your system setup and is beyond the scope of this tutorial.
GRUB cannot be installed directly to the intended boot device. Once an operating system is up and running, GRUB's probing the BIOS for available drives might yield wrong results. Thus, a four-step process is used (using two floppy disks: the boot disk to-be, and an auxiliary disk).
NOTE: creating your own GRUB bootdisk requires a
#
# create a rudimentary GRUB installation on an auxiliary disk;
# boot from the auxiliary disk, and complete the GRUB installation on the boot disk.
You will find the
===
Format a floppy disk; this will be your boot disk. Create a directory
=====Auxiliary GRUB install=====
Remove the boot disk from the floppy drive and insert the auxiliary disk. The files <code>stage1</code> and <code>stage2</code> from the GRUB distribution must be written to this disk, to sector 0 and sector 1+ respectively. In your shell (for Windows users, this means the [[Cygwin]] shell), type:
<syntaxhighlight lang="bash">
dd if=<stage1> of=/dev/fd0 bs=512 count=1
dd if=<stage2> of=/dev/fd0 bs=512 seek=1
</syntaxhighlight>
Now GRUB will be able to boot stage1 and stage2 from this disk. We cannot use it as our boot disk, though, since writing stage2 to sector 1 destroyed the floppy's format structure (you can't write files to the disk anymore, and any previously written <code>boot</code> directory could no longer be found). That's why we will now set up the other disk to boot GRUB and have a valid structure.
Leave the auxiliary disk in the drive, and boot from that floppy.
===
GRUB will boot into its command shell. (If your system does boot from hard drive instead, check your BIOS boot drive settings.) When the
<syntaxhighlight lang="bash">
install (fd0)/boot/stage1 (fd0) (fd0)/boot/stage2 (fd0)/boot/menu.cfg
</syntaxhighlight>
The parameters tell GRUB:
* where to find the stage1 file;
* which device to install GRUB on (the floppy drive) - this writes stage1 to the boot sector, you can delete <code>boot/stage1</code> afterwards;
* where to find the stage2 file (hardcoding the sector number of that file into the boot sector stage1; that's why <code>stage2</code> must not be moved after this procedure);
* where stage2 should look for the configuration file.
Remove the boot disk from the drive, and reboot your operating system so you can edit <code>/boot/menu.cfg</code>.
===
When you boot from the just-created boot floppy, GRUB stage1 is read from the floppy's boot sector. This stage1 "knows" where to find stage2 (it was told so during installation), and loads that. The stage2 does lots of interesting stuff (we'll come to that), but most importantly, it "knows" how to read file systems, so it can find the configuration file,
The configuration file tells GRUB where to look for the actual kernel image(s). You can set it up so it offers you a selection of various different kernels
Add an entry like this to the configuration file:
<pre>
root (fd0)
kernel /boot/kernel.bin
</pre>
Now all we have to do is to compile a kernel image and save it as <code>/boot/kernel.bin</code>. GRUB will find, load, and start it. For more details, menu options etc., refer to the GRUB manuals.
===Installing to USB===
'''NOTE''': I have tried many tools to install GRUB onto a USB device under windows, however, I have not been able to figure out how. So, to install, either use a Linux distro on your PC of use a Linux Live CD.
Putting GRUB onto a USB device is as easy as following the above example of installing to a standard hard disk. There is one extra step involved, finding out under which mount point your USB device is located. You may even have to mount it yourself if it is not already mounted. To install use the following steps:
If you need to mount your USB device: (Exchange <code>sdb1</code> with your device name.)
<syntaxhighlight lang="bash">
mount /dev/sdb1 /mnt/sdb1
</syntaxhighlight>
Create required
<syntaxhighlight lang="bash">
mkdir /mnt/sdb1/boot/grub
</syntaxhighlight>
Locate the <code>stage1</code>, <code>stage2</code>, and
<syntaxhighlight lang="bash">
find / -name stage1
</syntaxhighlight>
Copy stage1 and stage2 files
<syntaxhighlight lang="bash">
cp /usr/lib/grub/stage2 /mnt/sdb1/boot/grub/stage2
</syntaxhighlight>
For FAT formatted USB device use:
<syntaxhighlight lang="bash">
cp /usr/lib/grub/fat_stage1_5 /mnt/sdb1/boot/grub/fat_stage1_5
</syntaxhighlight>
For
<syntaxhighlight lang="bash">
cp /usr/lib/grub/e2fs_stage_1_5 /mnt/sdb1/boot/grub/e2fs_stage_1_5
</syntaxhighlight>
Then execute the
<syntaxhighlight lang="bash">
sudo grub
</syntaxhighlight>
Enter the following commands:
<syntaxhighlight lang="bash">
root (hd1,1)
setup (hd1)
quit
</syntaxhighlight>
if you don't know where your kernel is, you can use the command "find /boot/grub/e2fs_stage_1_5" to get the parameters which would be used in the command root (sdb1,1) and setup (sdb1).
===Installing to hard disk===
See [http://www.gnu.org/software/grub/manual/html_node/Installation.html Installation] in the official GRUB manual.
===Installing to CD===
See [[Bootable El-Torito CD with GRUB Legacy]].
==Load your kernel over network (TFTP)==
{{FirstPerson|section=1}}
You can also use GRUB's builtin network support to increase your build/test turn around time. You can boot another machine with a kernel directly from your build directory without having to copy it over manually. See also, [http://www.gnu.org/software/grub/manual/html_node/General-usage-of-network-support.html#General-usage-of-network-support How to set up your network] in the official GRUB manual.
=====Getting GRUB to support your card=====
First you need a version of GRUB that supports your network card. Most likely you will have to build one from source, so [ftp://alpha.gnu.org/gnu/grub/ grab it] and extract it to a work directly.
Run
<syntaxhighlight lang="bash">
./configure --help
</syntaxhighlight>
to see a list of options. In my case, I use Netgear tulip cards, so I execute:
<syntaxhighlight lang="bash">
./configure --enable-tulip
make
make install
</syntaxhighlight>
You may want to consider using the <code>--prefix</code> option if you don't want to overwrite your existing GRUB install or do not have root access.
NOTE: this was done on a Linux box, I assume using Cygwin under Windows would work as well.
=====Set up a TFTP server=====
You will need a TFTP server running on your build machine and pointing to your build directory. I've been using the [http://support.3com.com/software/utilities_for_windows_32_bit.htm 3CServer utility from 3COM], but there are several out there for most platforms.
Make sure any firewalls you have installed allow incoming connections on the TFTP ports.
=====Install as you would normally=====
On your target machine install the GRUB binary you just built as documented above.
=====Configure GRUB=====
I use the following entry in my <code>menu.lst</code> to boot my kernel.
<pre>
title Network Boot
# Obtain an IP address for this card
dhcp
# I don't have DHCP setup to deliver the TFTP server's IP address,
# so I set it manually this is my build machine
tftpserver 192.168.0.50
# The root device is the network
root (nd)
# My kernel is directly under the TFTP directory
kernel /kernel.exe
# I also load a module for testing out multitasking
module /module.exe
</pre>
And that should be it. If you're not running DHCP you can use <code>ifconfig</code> to manually set addresses, gateways, etc. Your can also use the BOOTP or RARP protocol.
==Other loaders that are Multiboot compliant==
Chris Giese's [http://my.execpc.com/~geezer/temp/mbload.zip MBload] also works with Multiboot-compliant kernels. Check out the [[Topic:8549|related thread]] for more info.
==See Also==
===Wiki Pages===
*[[Grub Error 13]]
*[[Multiboot]]
===Tutorials===
*[[Bare bones]]
Line 217 ⟶ 205:
*[[Topic:9548|Switching back to real mode from GRUB]]
*[[Topic:9586|Setting boot-time graphic video mode with GRUB]]
*[[Topic:
===External Links===
*[http://tldp.org/HOWTO/Linux+Win9x+Grub-HOWTO/index.html Linux+Win9x+Grub HOWTO]
*[http://www.pixelbeat.org/docs/disk/ GRUB PC Disk details]
*[http://www.gnu.org/software/grub/manual/legacy/grub.html GRUB Legacy manual]
*[https://gna.org/projects/grub4dos/ GRUB for DOS]
[[Category:Bootloaders]]
[[Category:GRUB]]
[[de:Grand Unified Bootloader]]
|