GRUB Legacy: Difference between revisions

3,903 bytes removed ,  18 days ago
m
no edit summary
[unchecked revision][unchecked revision]
mNo edit summary
 
(14 intermediate revisions by 10 users not shown)
Line 1:
{{You}}
GRUB stands for GRand Unified Bootloader and is a [[bootloader]] and the reference implementation of the Multiboot Specification. GRUB can boot any Multiboot-compliant OS (e.g. Hurd, [http://grub.enbug.org/MultibootSystems among others]), however it can also boot some non-Multiboot-compliant OSes, e.g. Windows, via a chain-loading function, and some others via special support, e.g. Linux. mbchk can be used to determine if a file is Multiboot-compliant.
GRUB stands for GRand Unified Bootloader and is a [[bootloader]] and the reference implementation of the [[Multiboot|Multiboot Specification]]. GRUB can boot any Multiboot-compliant OS (e.g. Hurd, [http://grub.enbug.org/MultibootSystems among others]), however it can also boot some non-Multiboot-compliant OSes, e.g. Windows, via a chain-loading function, and some others via special support, e.g. Linux. mbchk can be used to determine if a file is Multiboot-compliant.
 
This article concentrates on GRUB Legacy. Information regarding modern [[GRUB 2]], a full rewrite, can be found in a separate article.
 
==Features==
Line 32 ⟶ 33:
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:
 
<sourcesyntaxhighlight lang="bash">
dd if=<stage1> of=/dev/fd0 bs=512 count=1
dd if=<stage2> of=/dev/fd0 bs=512 seek=1
</syntaxhighlight>
</source>
 
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.
Line 44 ⟶ 45:
GRUB will boot into its command shell. (If your system does boot from hard drive instead, check your BIOS boot drive settings.) When the <code>grub ></code> prompt appears, remove the auxiliary disk from the drive and replace the boot disk. From the GRUB shell, you can now complete the installation on the boot disk:
 
<sourcesyntaxhighlight lang="bash">
install (fd0)/boot/stage1 (fd0) (fd0)/boot/stage2 (fd0)/boot/menu.cfg
</syntaxhighlight>
</source>
 
The parameters tell GRUB:
Line 73 ⟶ 74:
 
===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 youyour 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.)
 
<sourcesyntaxhighlight lang="bash">
mkdir /mnt/sdb1
mount /dev/sdb1 /mnt/sdb1
</syntaxhighlight>
</source>
 
Create required directories:
 
<sourcesyntaxhighlight lang="bash">
mkdir /mnt/sdb1/boot
mkdir /mnt/sdb1/boot/grub
</syntaxhighlight>
</source>
 
Locate the <code>stage1</code>, <code>stage2</code>, and <code>*_stage1_5</code> files:
 
<sourcesyntaxhighlight lang="bash">
find / -name stage1
</syntaxhighlight>
</source>
 
Copy stage1 and stage2 files, <code>/usr/lib/grub/</code> is an example location, use the location returned by the find command:
 
<sourcesyntaxhighlight lang="bash">
cp /usr/lib/grub/stage1 /mnt/sdb1/boot/grub/stage1
cp /usr/lib/grub/stage2 /mnt/sdb1/boot/grub/stage2
</syntaxhighlight>
</source>
 
For FAT formatted USB device use:
 
<sourcesyntaxhighlight lang="bash">
cp /usr/lib/grub/fat_stage1_5 /mnt/sdb1/boot/grub/fat_stage1_5
</syntaxhighlight>
</source>
 
For ext2 formatted USB device use:
 
<sourcesyntaxhighlight lang="bash">
cp /usr/lib/grub/e2fs_stage_1_5 /mnt/sdb1/boot/grub/e2fs_stage_1_5
</syntaxhighlight>
</source>
 
Then execute the GRUB install application:
 
<sourcesyntaxhighlight lang="bash">
sudo grub
</syntaxhighlight>
</source>
 
Enter the following commands:
 
<sourcesyntaxhighlight lang="bash">
root (hd1,1)
setup (hd1)
quit
</syntaxhighlight>
</source>
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).
 
Line 138 ⟶ 139:
 
==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.
 
Line 145 ⟶ 147:
Run
 
<sourcesyntaxhighlight lang="bash">
./configure --help
</syntaxhighlight>
</source>
 
to see a list of options. In my case, I use Netgear tulip cards, so I execute:
 
<sourcesyntaxhighlight lang="bash">
./configure --enable-tulip
make
make install
</syntaxhighlight>
</source>
 
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.
Line 188 ⟶ 190:
 
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.
 
==Grub for EFI==
 
This section will tell you how to compile, build and install Grub2 on an EFI system. This have been tested on an MacBook Pro6,1
 
===Compile===
 
First you need a x86_64 linux with gcc and binutils. I downloaded a Ubuntu 10.4 LiveCD, booted it in VirtualBox and installed it to disk.
 
You need to make sure gcc, bison, flex etc are installed. Do this with the apt package manager. apt-get install gcc bison flex is what i did.
 
You need the grub2 source code. I got that from ftp://alpha.gnu.org/gnu/grub/
 
Download grub-1.9-rc2.tar.gz and unpack it.
 
Next thing to do is <pre>./configure --with-platform=efi --target=x86_64</pre>
 
next step is to compile:
 
<pre>make</pre>
 
Now you should have compiled grub2 efi if everything went ok.
 
===Build Grub EFI binary (bootx64.efi)===
 
grub.efi / bootx64.efi is a bundle of tools including grub itself. You need to make the efi image by selecting what modules you want.
 
For Grub to be able to read disk partitions you need a module for that. Either you want plain-old bootsector and msdos style partition map or you want GPT (new fancy one) you need to select correct module when bundling grub.efi.
 
For your grub to be functional you should include as many filesystems as possible and also linux,multiboot,multiboot2 etc so that you can read any type of kernel from any type of filesystem.
 
So.. Lets build grub.efi / bootx64.efi
 
Go to "grub-core" folder.
 
Execute: ../grub-mkimage -d . -o bootx64.efi -O x86_64-efi -p /efi/boot [list of modules without .mod]
 
where "-p /efi/boot" tells where "grub.cfg" is after booting and it will be loaded from this path on booting device.
 
A easy way of adding all modules is:
 
<pre>../grub-mkimage -d . -o bootx64.efi -O x86_64-efi -p /efi/boot `find *.mod | xargs | sed -e 's/.mod//g'`</pre>
 
That will build "bootx64.efi" in the subfolder and this can now be copied to a USB-disk, harddisk etc.
 
From UEFI specification the EFI bios will try to load & boot from /efi/boot/bootx64.efi on a FAT formated drive. This is for x86_64 plattform.
 
===Configuring===
 
Add a "grub.cfg" file to /efi/boot/gruf.cfg or wherever you like. Make sure to put it where you told grub to look for its files "-p option".
 
To use graphical menu you must also provide a font file. I used unicode.pf2 that i found in /usr/share/grub2 or something.
 
I did like this:
<pre>
set timeout=30
set default=0
#set debug=all
 
loadfont /efi/boot/unicode.pf2
#set gfxmode=1024x768
set gfxmode=auto
set gfxpayload=keep
terminal_output gfxterm
 
background_image -m normal /efi/boot/background.jpg
 
menuentry "OSKernel" {
set debug=all
multiboot /kernel32.exe
module /null.sys
module /console.sys
module /serial.sys
module /keyboard.sys
module /random.sys
sleep 5
}</pre>
 
Some nice to know info is that grub2 (1.99rc2 atleast) parses the video mode information in the multiboot header. It also tries to sattisfy your request. This means that you can request text/video, WxHxD from the multiboot header. Video information about mode, framebuffer address etc should be available in the multiboot info aswell. Sweet isn´t it? :)
 
===Installing===
 
I partitioned my usbdisk with MacOSX diskutil, but any partition tool should/would do. I created a small 100mb partition as first partition and created a huge secondary partition for files. I formated the partition to HFS+, but i guess FAT should be more compatible since i dont think other EFI firmwares have HFS+ filesystem support like the Mac..
 
Anyway i created "/efi/boot/" folder and copied bootx64.efi to /efi/boot/bootx64.efi on my disk. I then created a grub.cfg file alongside with it.
 
To make OSX find the bootx64.efi image on boot i did;
 
<pre>sudo bless --verbose --folder=/Volumes/EFI --file=/Volumes/EFI/efi/boot/bootx64.efi --setBoot</pre>
 
where /Volumes/EFI is the first partition on my usb disk..
 
Now i saved my work and rebooted.. Press/hold "option" key during boot will bring up boot menu. I now get an option to boot en EFI DISK. I select this and now Grub2 shows like any other Grub..
 
Configuration of grub and config file is like any other grub2 syntax.
 
The "blessing" procedure should not be needed on UEFI compatible EFI versions. These will always look for /efi/boot/bootx64.efi.
 
==Other loaders that are Multiboot compliant==
Line 292 ⟶ 197:
===Wiki Pages===
*[[Grub Error 13]]
*[[Multiboot]]
 
===Tutorials===
Line 299 ⟶ 205:
*[[Topic:9548|Switching back to real mode from GRUB]]
*[[Topic:9586|Setting boot-time graphic video mode with GRUB]]
*[[Topic:1744118255|GRUB VBE Patch]]
 
===External Links===
Line 308 ⟶ 214:
 
[[Category:Bootloaders]]
[[Category:GRUB]]
[[de:Grand Unified Bootloader]]