GNU
GRUB (0.97) Simplified for Newbies
by
Joydeep
Bakshi
12-NOV-2007
|
Copyright
and
License
Copyright©2007
by Joydeep Bakshi.
This material may be distributed only subject to the terms and
conditions set
forth in the Open Content License, v1.0 or later (the latest version is
presently available at opencontent.org ).
Credits
GRUB
originated in 1995 when Erich Boleyn was trying to boot the GNU Hurd
with the University of Utah's Mach4 microkernel (now known as GNU
Mach). Erich and Brian Ford designed the Multiboot Specification,
because they were determined not to add to the large number of
mutually-incompatible PC boot methods.
Erich then began modifying the Free BSD boot loader so that it would
understand Multiboot. He soon realized that it would be a lot easier to
write his own boot loader from scratch than to keep working on the
Free BSD boot loader, and so GRUB was born.
Erich added many features to GRUB, but other priorities prevented him
from keeping up with the demands of its quickly-expanding user base. In
1999, Gordon Matzigkeit and Yoshinori K. Okuji adopted GRUB as an
official GNU package, and opened its development by making the latest
sources available via anonymous CVS.
GNU GRUB
("GRUB" for short) is
a boot loader from the GNU Project. GNU GRUB is a very powerful boot
loader,
which can load a wide variety of free operating systems, as well as
proprietary operating systems with chain-loading. It can be used to
select
from different kernel images available on a particular operating
system's
partitions, as well as to pass boot-time parameters to such kernels.
GNU GRUB developed from a
previous package called the GRand Unified Bootloader. The GNU operating
system uses GNU GRUB as its boot loader, as do most general-purpose
Linux
distributions.
In this tutorial I
simply mention GRUB to indicate GNU GRUB
| MBR,
Boot-loader
and Boot-sector |
The very
first sector (512
bytes) of computer's hard disk is called MBR or Master Boot Record.
Computer's BIOS is generally programmed to read the code at MBR during
booting to know where to look next. MBR is divided into three sections
as
below.
The first sector of a
partition is known as the 'boot sector'. The first sector of a
partition may
or may not have any bootloader's code
| GRUB stage1, stage1.5 and stage2 |
The 446 byte area of the bootloader is really too small for any decent
boot
loader to fit into. That's why a small amount of code called the 'IPL'
or
Initial Program Loader is installed there by GRUB. 'First stage' of the
boot
loader or stage1 is name for the same code. IPL or first stage of a
bootloader tells the BIOS where on the hard disk to go looking for the
rest
part of the boot loader.
e2fs_stage1_5, fat_stage1_5, ffs_stage1_5, jfs_stage1_5,
minix_stage1_5,
reiserfs_stage1_5, vstafs_stage1_5, xfs_stage1_5 are called Stage1.5,
because they serve as a bridge between stage1 and stage2. stage1.5 is
loaded
by stage1 and stage1.5 loads stage2. The difference between stage1 and
stage1.5 is that the former doesn't understand any file-system while
the
latter understands file-system (e.g. e2fs_stage1_5 understands ext2fs).
So you
can move the stage2 image to another location safely, even after GRUB
installation.
stage2 contains most of the GRUB logic. It loads the menu.lst file and
executes the statements. If
there is no menu.lst then it starts the
GRUB shell
interface.
When a computer is turned on
the computer's BIOS reads (after a successful POST) the master boot
record
(MBR) from Hard disk.
The MBR contains GRUB stage1. The function of stage1 is to find either
stage1.5 or stage2,
and pass
control over to them. stage1 finds stage1.5 or stage2 by means of
physical
block addresses that are encoded into the stage1 when GRUB is
installed.
stage1.5 is not strictly
required. When used, stage1.5 will receive control from stage1, and
then pass
control over to stage2. stage1.5 understands the file system hence
capable of
locating stage2 as a file within a file system, rather than the
physical
block addresses that stage1 uses. If the physical location of the
stage2 file
changes, stage1.5 will still be able to find it via the file system,
while stage1 can't. GRUB has several stage1.5 images available. Each of
these
images understands one file system, and they are named accordingly. The
decision to install (or not) stage1.5 is made by the GRUB installation
code,
depending on whether or not there is room for it. stage1.5 is too large
to
fit into a single 512 byte sector, so there is not always a place to
put it. stage1.5 can be installed into the area right after an MBR (in
the
first 30
kilobytes of hard disk immediately following the MBR) or installed to a
ReiserFS partition.
stage2 is the core of
GRUB and contains the GRUB shell. It is the component which displays
the boot
menu from menu.lst (usually located at /boot/grub/menu.lst). Once the
OS has
been selected in the menu GRUB either loads the associated kernel into
the
memory and passes control on to the kernel or call another loader using
chain
loading if the operating system required so. If there is no menu.lst
then
stage2 enters the GRUB shell command prompt.
| Boot-loader or
IPL (Stage 1) Backup and Restore |
The
command below creates a
backup of the Boot-loader (446 bytes) in my home directory
dd if=/dev/hda of=/home/joy/17Oct2007_Backup_MBR bs=446 count=1
1+0 records in 1+0 records out 446 bytes transferred in 0.023787 seconds (18750 bytes/sec)
|
save the file in a CD,
Floppy or Pen drive. If somehow the MBR will be modified by any
application
the boot-loader will be modified also. Fixing the boot-loader will
restore
the system If the partitions are unchanged. Boot the system with a Live
Linux
CD and mount the media where you save the backup. Now restore the
previous
boot-loader with the command.
dd if=/<path>/17Oct2007_Backup_MBR of=/dev/hda bs=446 count=1 NOTE : Replace the <path> with your actual backup path
|
| Never
backup the entire MBR |
It is quite
possible to make
the backup of entire MBR, 512 bytes. This will also keep the record of
partition table. If you re-partition your disk later and restore the
previous
backup of MBR; it will then not match with the recent partition table
as well
as file system and make the disk un-readable. In this situation you
have to
repartition and reformat the disk. So never backup the entire MBR but
only
the boot-loader.
GRUB follows a different numbering system than the linux device node
First floppy disk drive = (fd0)
First hard drive = (hd0)
Second hard drive = (hd1)
... and so on
First partition = 0
second partition = 1
.... and so on
1st partition on first
hard drive = (hd0,0)
10th partition on first hard drive = (hd0,9)
3rd partition on second hard drive= (hd1,2)
Hence we can say that
1st partition on first hard drive = (hd0,0) in GRUB = /dev/hda1 in
Linux
device node
2nd partition on second hard drive = (hd1,1) in GRUB = /dev/hdb2 in
Linux
device node
etc...........
| Disk
investigation with GRUB shell |
GRUB's shell
interface supports
Tab completion. We can use this feature to
investigate disk attached with the
computer.
grub> null (
and pressing the Tab shows in my system
grub> null ( Possible disks are: fd0 hd0 hd1 cd
|
It is also possible to
know the partition on say hd0. To do that we have to type (hd0, (comma)
and
press Tab. Here is the result
grub> null (hd0, Possible partitions are: Partition num: 0, Filesystem type unknown, partition type 0x7 Partition num: 1, Filesystem type unknown, partition type 0x82 Partition num: 2, Filesystem type is reiserfs, partition type 0x83 Partition num: 3, Filesystem type is xfs, partition type 0x83
|
Confirm this output with
geometry command in grub shell
grub> geometry (hd0) drive 0x80: C/H/S = 16383/255/63, The number of sectors = 78242976, /dev/hda Partition num: 0, Filesystem type unknown, partition type 0x7 Partition num: 1, Filesystem type unknown, partition type 0x82 Partition num: 2, Filesystem type is reiserfs, partition type 0x83 Partition num: 3, Filesystem type is xfs, partition type 0x83
|
| File
name |
Possible location |
Purpose |
| device.map |
/boot/grub/device.map |
describes relationship between
Linux and GRUB drive designations.created by 'grub-install' if
file doesn't already exist in /boot/grub
|
| menu.lst |
/boot/grub/menu.lst |
displays the GRUB boot menu |
| grub |
/sbin/grub |
GRUB shell that runs from within Linux. GRUB can be
installed or reinstalled from here |
| grub-install |
/sbin/grub-install |
Script that invokes /sbin/grub and installs GRUB to a
specified location.
Also generates device.map file and populates /boot/grub
with GRUB image files on first install
|
| update-grub |
/sbin/update-grub
Specific to Debian and Debian- based systems
|
Script that automatically generates and updates |
| stage1 |
/boot/grub/stage1 |
boot sector image file containing initial boot
code.Gets installed in MBR, partition boot sector, or floppy boot sector |
| stage2 |
/boot/grub/stage2 |
Core image file for GRUB. Executes GRUB shell and menu
interface. |
| *_stage1_5 |
/boot/grub/*_stage1_5 |
A set of intermediate stage 1.5 image files, each one
specific to just one file system. Locates Stage 2 via the file system
it knows. Is embedded outside of any file system |
| Find
partition
having Linux kernel |
grub> find /vmlinuz (hd0,2)
|
you may see multiple partitions if you have multiple linux installed in
your box.
If the kernel has some other name than vmlinuz, that partition will not
be shown.
grub> find /sbin/init (hd0,2)
|
You may see multiple partitions if you have multiple linux installed in
your box.
| Check the contains
of a partition |
GRUB shell has the intelligence to show the contains of a partition.
Say we like to see the root partition which is (hd0,2) in my machine.
"null (hd0,2)/"
and then pressing a Tab will show us the needed
information.
grub> null (hd0,2)/ Possible files are: bin dev etc lib mnt opt srv tmp sys var usr boot home proc sbin root cdrom .reiserfs_priv initrd vmlinuz
|
We can go further and check the /opt directory by "null (hd0,2)/opt/"
and pressing Tab after
grub> null (hd0,2)/opt/ Possible files are: vim71 vim-7.1.tar.bz2 cdrtools-beta.tar.gz modding hackl7 advanced_software schily kmobiletools-0.5_beta1
|
GRUB supports "cat" command too. we can check menu.lst as below
grub> cat (hd0,2)/boot/grub/menu.lst
|
| Creating GRUB
bootable
CD-ROM |
GRUB supports the no emulation mode in the El Torito specification.
Hence we can use the whole CD-ROM from GRUB.
http://orgs.man.ac.uk/documentation/grub/grub_fot.html#FOOT5
For booting from a CD-ROM, GRUB uses a special stage2 called stage2_eltorito. We
need only this file to make bootable CD-ROM. A
config file `menu.lst' is optional. We don't need to use `stage1' or
`stage2', because El Torito is quite different from the standard boot
process.
1> Make a directory for the bootable image, say, `CD_GRUB'
mkdir CD_GRUB
2> Make a directory for GRUB
mkdir -p CD_GRUB/boot/grub
3> Copy the file `stage2_eltorito' . In debian it is located at
/lib/grub/i386-pc/
cp /lib/grub/i386-pc/stage2_eltorito CD_GRUB/boot/grub
4> If desired, make the config file `menu.lst' under
`CD_GRUB/boot/grub'
or copy th existing one like
cp /boot/grub/menu.lst CD_GRUB/boot/grub
The 'savedefault' command in each operating system's boot entry cause
GRUB not to work from a CD. The 'savedefault' command in a
hard-disk writes to a file in /boot/grub named 'default', and
records the last system that was booted. We cannot use this when
running GRUB from a CD, because we can't write changes to a CD with
GRUB. So we need to delete all instances of the savedefault command.
5> Now make a ISO9660 image file like this
mkisofs -R -b boot/grub/stage2_eltorito -no-emul-boot \
-boot-load-size 4 -boot-info-table -o cd_grub.iso CD_GRUB
-boot-load-size 4 bit is required for compatibility with the BIOS on
many older machines.
6> Burn the created .iso image. mkisofs has
already set up the disc to boot from the
boot/grub/stage2_eltorito file.
| Creating GRUB bootable
Floppy |
We have to install both stage1 and stage2 in the Floppy disk. Grub
files are resided at /lib/grub/i386-pc/ in debian.
1> cd /lib/grub/i386-pc/
2> stage1 installation
dd if=stage1 of=/dev/fd0 bs=512 count=1
1+0 records in 1+0 records out 512 bytes transferred in 1.152603 seconds (444 bytes/sec)
|
3> stage2 installation
dd if=stage2 of=/dev/fd0 bs=512 seek=1
211+1 records in 211+1 records out 108168 bytes transferred in 6.406743 seconds (16883 bytes/sec)
|
Warning
: This procedure will destroy stored data on the floppy
| Method - 2 (using grub-floppy
command) |
grub-floppy is a program to build a generic grub boot disc. The boot
disc when booted provides the grub command line. grub-floppy will
create a more generic floppy only limited by architecture
grub-floppy /dev/fd0
| Method - 3 (Computer specific
boot floppy with /boot/grub) |
We can also create a GRUB boot floppy with a file system and menu.lst
Like below. ( be super user first )
1> mke2fs /dev/fd0 (creating ext2 file
system
on floppy)
2> mount -t ext2 /dev/fd0 /mnt/floppy
(mounting the floppy at /mnt/floppy)
3> grub-install --root-directory=/mnt/floppy fd0
(Installing GRUB and creating /boot/grub in the floppy)
4> cp /boot/grub/menu.lst /mnt/floppy/boot/grub/
(copy menu.lst)
5> umount /mnt/floppy (floppy is ready,
unmount it)
| Method - 4 (by GRUB shell,
non-interactive mode, also have /boot/grub) |
Be super user first
1> mke2fs /dev/fd0
2> mount -t ext2 /dev/fd0 /mnt/floppy
3> mkdir /mnt/floppy/boot
4> cp -R /boot/grub /mnt/floppy/boot
5> /sbin/grub --batch --device-map=/dev/null
<<EOF
device (fd0) /dev/fd0
root (fd0)
setup (fd0)
quit
EOF
Step 5 is actually a batch mode of grub shell interface. Here is the
output of step 5
debian:# /sbin/grub --batch --device-map=/dev/null <<EOF > device (fd0) /dev/fd0 > root (fd0) > setup (fd0) > quit > EOF
GNU GRUB version 0.97 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename. ] grub> device (fd0) /dev/fd0 grub> root (fd0) Filesystem type is ext2fs, using whole disk grub> setup (fd0) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5 (fd0)"... failed (this is not fatal) Running "embed /boot/grub/e2fs_stage1_5 (fd0)"... failed (this is not fatal) Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/menu.lst"... succeeded Done. grub> quit
|
You can
modify/delete menu.lst from /mnt/floppy/boot/ or keep it to get
computer specific menu
6> umount /mnt/floppy
| Method - 5 (by GRUB shell,
interactive mode, have /boot/grub) |
Be super user first
1> mke2fs /dev/fd0
2> mount -t ext2 /dev/fd0 /mnt/floppy
3> mkdir /mnt/floppy/boot
4> cp -R /boot/grub /mnt/floppy/boot
5> umount /mnt/floppy
6> Fire up GRUB shell interface and execute root (fd0)
grub> root (fd0) Filesystem type is ext2fs, using whole disk
|
7) Install GRUB by setup (fd0)
grub> setup (fd0) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/fat_stage1_5" exists... yes Running "embed /boot/grub/fat_stage1_5 (fd0)"... failed (this is not fatal) Running "embed /boot/grub/fat_stage1_5 (fd0)"... failed (this is not fatal) Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/menu.lst "... succeeded Done.
|
8) Exit from GRUB
You can
modify/delete menu.lst from /mnt/floppy/boot/ or keep it to get
computer specific menu
| Creating GRUB bootable
USB pen drive |
Be super user.
Identify the device node which your system assigns to the USB
pen drive. Execute tail -f /var/log/messages and
then plugin the USB drive. Here is mine.
debian:# tail -f /var/log/messages
SCSI device sda: 248321 512-byte hdwr sectors (127 MB) sda: Write Protect is off SCSI device sda: 248321 512-byte hdwr sectors (127 MB) sda: Write Protect is off sda: sda1 Attached scsi removable disk sda
|
So /dev/sda is the device node for USB pen drive
and
/dev/sda1 is pointing the partition in that drive.
Now create a directory and mount the USB drive there.
mkdir /mnt/USB_drive
mount -t vfat /dev/sda1 /mnt/USB_drive
The file system of my USB pen drive is FAT that's why I am using -t
vfat. Change the file system to suit your USB drive.
Identify the drive number GRUB assigns to the USB drive. Here is mine
grub> null ( Possible disks are: fd0 hd0 hd1 cd
|
Here hd1 is my USB drive as GRUB recognized
| Method - 1 (with
/boot/grub) |
1> Install GRUB on the USB drive by executing
grub-install --root-directory=/mnt/USB_drive hd1
debian:# grub-install --root-directory=/mnt/USB_drive hd1 Probing devices to guess BIOS drives. This may take a long time. Installation finished. No error reported. This is the contents of the device map /mnt/USB_drive//boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'.
(fd0) /dev/fd0 (hd0) /dev/hda (hd1) /dev/sda
|
2> (Optional) Copy the menu.lst to get computer specific menu
cp /boot/grub/menu.lst /mnt/USB_drive/boot/grub/
3> Confirm that USB drive has /boot/grub
grub> find /boot/grub/stage1 (hd0,2) (hd1,0)
|
4> Unmount the drive
unmount /mnt/USB_drive
| Method - 2 (using interactive
GRUB shell, also have /boot/grub) |
1> mkdir /mnt/USB_drive/boot
2> cp /boot/grub /mnt/USB_drive/boot
3> umount /mnt/USB_drive
4> Fire up the GRUB shell and execute root (hd1,0)
grub> root (hd1,0) Filesystem type is fat, partition type 0x6
|
5> Install GRUB by setup (hd1)
grub> setup (hd1) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/fat_stage1_5" exists... yes Running "embed /boot/grub/fat_stage1_5 (hd1)"... 15 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done.
|
6> Exit from GRUB
You can
modify/delete menu.lst from /mnt/floppy/boot/ or keep it to get
computer specific menu
| Method - 3 (by
non-interactive mode of GRUB shell) |
1> mkdir /mnt/USB_drive/boot
2> cp /boot/grub /mnt/USB_drive/boot
3> umount /mnt/USB_drive
4> Here is the batch command for USB drive
/sbin/grub --batch --device-map=/dev/null <<EOF
device (hd1) /dev/sda
root (hd1,0)
setup (hd1)
quit
EOF
debian:# /sbin/grub --batch --device-map=/dev/null <<EOF > device (hd1) /dev/sda > root (hd1,0) > setup (hd1) > quit > EOF
GNU GRUB version 0.95 (640K lower / 3072K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB lists possible command completions. Anywhere else TAB lists the possible completions of a device/filename. ] grub> device (hd1) /dev/sda grub> root (hd1,0) Filesystem type is fat, partition type 0x6 grub> setup (hd1) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/fat_stage1_5" exists... yes Running "embed /boot/grub/fat_stage1_5 (hd1)"... 15 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd1) (hd1)1+15 p (hd1,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done. grub> quit
|
You can delete
menu.lst from /mnt/USB_drive/boot/ or keep it to get computer specific
menu
stage1
and stage2 on
different media
PC specific
GRUB bootable Floppy/USB with stage1 only |
stage1 will
reside in the boot able Floppy or USB drive. And this stage1 will call
stage2 located in the Hard disk.
| Method - 1 (using grub-install
command) |
We can do this with grub-install like
grub-install /dev/fd0
for floppy
| Method - 2 (using GRUB
shell) |
Within GRUB shell we have to first find out the hard disk partition
having /boot/grub to set root device and then execute
root
(hd0,2)
setup (fd0)
| Method - 3 (using batch mode of
GRUB shell) |
With GRUB batch mode
/sbin/grub
--batch <<EOF
root (hd0,2)
setup (fd0)
quit
EOF
After
repartitioning the hard disk by gparted; stage1 may not find stage2 or
installing windows after linux modify the MBR with Windows MBR. What
ever may be the situation GRUB can be recovered with three easy steps.
Boot the system with a Live Linux disk and execute "grub" command to
get its shell interface
Find out the device which contains the stage1. Generally stage1 resides
at /boot/grub/stage1 (in debian too). If your distro has a different
path search accordingly.
grub> find /boot/grub/stage1 (hd0,2)
|
Set the GRUB's root device to the partition containing the boot
directory. ( see the command in Step-1 )
grub> root (hd0,2) Filesystem type is reiserfs, partition type 0x83
|
Install the GRUB boot loader (stage1) on the Master Boot Record (MBR)
of the first drive
grub> setup (hd0) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/reiserfs_stage1_5" exists... yes Running "embed /boot/grub/reiserfs_stage1_5 (hd0)"... 18 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd0) (hd0)1+18 p (hd0,2)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done.
|
Restart the machine with out Live Linux disk
| What is SUPER
GRUB DISK ? |
Super GRUB Disk has features that allow users to execute GRUB commands
through menu interface
and without prior knowledge about GRUB commands that only advanced
users who have studied and practiced GRUB commands could do before. One
can select what he wants to do from simple menus. Super GRUB Disk also
helps to teach what GRUB commands can be used for.
Super GRUB Disk is used for solving many types of bootloader problems.
Users without knowing GRUB's Commands can use Super GRUB Disk to fix
bootloader problem.
Super GRUB is available as CD, Floppy and Pen drive image.
http://geocities.com/supergrubdisk/
| Importance of device.map file |
GRUB guesses BIOS devices and stores the result in device.map It is
created during installation
of GRUB.
When GRUB is used as boot-loader; device.map is useless. hd0 is the
first hard disk given by the bios, hd1 is the second... and so. But
under Linux environment grub needs to know which linux device
correspond to which grub device.
After adding or removing any disk drive from the system, we can edit
device.map to add or remove
corresponding entry for that particular drive as well as we can also
correct any entry in the file if GRUB can't generate the right
combination.
grub-install
is able to regenerate the device.map with --recheck
Here is my /boot/grub/device.map
After adding Floppy and pen drive I executed (as root)
grub-install --recheck
/dev/hda
debian:# grub-install --recheck /dev/hda Probing devices to guess BIOS drives. This may take a long time. Installation finished. No error reported. This is the contents of the device map /boot/grub/device.map. Check if this is correct or not. If any of the lines is incorrect, fix it and re-run the script `grub-install'.
(fd0) /dev/fd0 (hd0) /dev/hda (hd1) /dev/sda
|
and now the modified device.map has
(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/sda
| Boot
Manually
from GRUB's shell interface |
When MBR (stage1) is modified by the windows MBR or corrupted; it is
still very much possible to boot
existing linux kernel. Boot the machine from a Floppy/CD or Pen drive
and within GRUB shell
follow the steps below
| Step-1
>>>>>> Find device
and partition having vmlinuz
<<<<<< |
grub>find /vmlinuz (hd0,2)
|
| Step-2
>>>>>> Set GRUB's
root device
<<<<<< |
grub> root (hd0,2) Filesystem type is reiserfs, partition type 0x83
|
| Step-3
>>>>>> Point to the
kernel
<<<<<< |
grub> kernel /vmlinuz [Linux-bzImage, setup=0x1e00, size=0x17c244]
|
We can also execute
kernel /vmlinuz root=/dev/hda3
to manually set the '/' (root partition); which contains the /sbin/init file
Recall that /dev/hda3 in
linux is (hd0,2) in GRUB
| Step-4
>>>>>> Point to the
initrd
<<<<<< |
Skip this step if there
is no intird; like in case of custom kernel
grub> initrd /initrd.img [Linux-initrd @ 0x1f96a000, 0x675773e bytes]
|
| Step-5
>>>>>> Boot the
kernel <<<<<< |
grub> boot_ uncompressing linux... OK, booting the kernel
|
| Skip Manual
booting by calling menu.lst and get GUI interface |
Why manual booting ? If menu.lst
is there just call it by configfile
to get the GUI interface.
grub> configfile (hd0,2)/boot/grub/menu.lst
|
And this gives you the GUI interface :-)
| GRUB GUI
configuration with menu.lst file |
# foreground/background text_color highlighted_color
color green/black white/black
# Set a timeout, in seconds, before automatically booting the default entry
timeout 20
# Default entry; Count from 0
default 1
# Fallback entry.
#if, for any reason, the default entry doesn't work
# fall back to the "fallback"
fallback 2
#Entry 0
title Ram tester
root (hd0,2)
kernel /boot/memtest86+-1.70.bin
boot
# Entry 1
title Debian GNU/Linux, kernel 2.6.17
root (hd0,2)
kernel /boot/vmlinuz-2.6.17 root=/dev/hda3 ro
boot
# Entry 2
title Debian GNU/Linux, kernel 2.6.17 (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.17 root=/dev/hda3 ro single
boot
# Shutdown
title Shutdown PC
halt
| Protection with Encrypted
Password |
Generate md5 password with in GRUB shell. md5crypt is the
command to do the same
grub> md5crypt Password: ************ Encrypted: $1$j4fjD$pegn7h0etNea5vN18/J1w/
|
Now see how to protect GRUB shell interface, edit mode and also how to
protect GRUB entries with different passwords.
# foreground/background text_color highlighted_color
color green/black white/black
# Set a timeout, in seconds, before automatically booting the default entry
timeout 20
########################
# This password protects the GRUB shell interface
# and edit mode
password --md5 $/ee33x434d$dsqasd/wc
########################
# Default entry; Count from 0
default 1
# Fallback entry.
#if, for any reason, the default entry doesn't work
# fall back to the "fallback"
fallback 2
#Entry 0
title Ram tester
root (hd0,2)
kernel /boot/memtest86+-1.70.bin
boot
# Entry 1
title Debian GNU/Linux, kernel 2.6.17
root (hd0,2)
kernel /boot/vmlinuz-2.6.17 root=/dev/hda3 ro
boot
#############################
# Password protected entry
title Debian GNU/Linux, kernel 2.6.17 (recovery mode)
# This password is required to boot this kernel
password --md5 $1$j4fjD$pegn7h0etNea5vN18/J1w/
root (hd0,2)
kernel /boot/vmlinuz-2.6.17 root=/dev/hda3 ro single
boot
############################### Shutdown
title Shutdown PC
halt
You can create multiple passwords for multiple entries, so
that
particular entry will have unique password. When you boot the protected
entry it asks for the password
Pressing <p>
at the boot menu also asks a password. This password
is for enabling the GRUB shell interface and edit mode
There
is no
splashimage
support in GRUB-0.97. You have to patch the source code to get it.
debian is
shipped with patched GRUB-0.97 to support splashimage.
"splashimage" feature displays a nice image at boot
time while
user selects the OS/kernel image to load. splashimage must be
1> xpm.gz format
2> 640x480 resolution
3> 14 colors
The operating system's graphics drivers not be in operation
when GRUB
displays splashimage. Therefore GRUB counts on the video capabilities
of the BIOS. Most computer's BIOSes can't handle fancy, high quality
images, so splashimage is limited to an image size of 640x480 pixels
and a 14 color display
# Display splash image
splashimage=(hd0,2)/boot/grub/splashimage/skull.xpm.gz
foreground ffff00
background 000000
# splashimage doesn't work with color syntax
# Disable color syntax if there is any
# color green/black white/black
Below is a little shell script which I design to
check the splashimage support in GRUB.
SPLASHSUPPORT=0 IMAGE="splashimage" SETTING=0
# Check if stage2 has splashimage support
if [ -f /boot/grub/stage2 ]; then grep -ia $IMAGE /boot/grub/stage2 > /dev/null 2>&1
if [ "$?" -eq 0 ]; then SPLASHSUPPORT=1 echo "stage2 supports splashimage" fi fi
# Check menu.1st file for splashimage setting
if [ -f /boot/grub/menu.1st ]; then grep $IMAGE /boot/grub/menu.1st > /dev/null 2>&1
if [ "$?" -eq 0 ]; then SETTING=1 fi fi
# Display the result
if [ "$SPLASHSUPPORT" -eq 0 ]; then echo "Splashimage support...NO" else echo "Splashimage support...OK" # also check menu.lst if [ $SETTING -eq 1 ]; then echo "/boot/grub/menu.1st file has the splashimage setting" fi
fi
|
| Calling another boot-loader with
"chainloader" |
Chainloader command transfers control to another boot-loader. The OSes
which use their own boot-loader and don't
work with GRUB; can be booted with GRUB's chainloader facility.
Here is the configuration I use to boot WinXP
title Windows XP
root (hd0,0)
makeactive
chainloader +1
`+1' is the blocklist notation to point the first sector of the current
partition.
makeactive sets the active partition on the root disk to GRUB's root
device. This command is limited to primary PC partitions on a hard disk
| Virtual swapping of Hard Disk |
Windows is happy to see itself on the first partition
of the
first hard
disk.
chainloader might not work if windows is on a non first hard disk. This
problem can
be solved with disk swapping by "map" command. map exchanges BIOS
drives virtually. This method
makes windows to see as it is on the first sector of first drive
title Windows 95
root (hd1,0)
makeactive
# Here windows has been installed on hd1
map (hd0) (hd1)
map (hd1) (hd0)
chainloader +1
| Creating Submenu !!! Yes it is
possible :-) |
Suppose the submenu file is called submenu.lst and
located at
/boot/grub
We can call this submenu by placing the configuration below in menu.lst
# calling submenu
title Sub-menu
configfile (hd0,2)/boot/grub/submenu.lst
In submenu.lst file we must have the configuration to
come
back to the
main menu. Below is such
an example
# submenu.lst file
# Go to main menu
title Main-menu
configfile (hd0,2)/boot/grub/menu.lst
"hiddenmenu" command hides the GUI and boots the
default entry
after
the timeout expired. User can
call the GUI by pressing <Esc> before the timeout
expires. Add hiddenmenu at the beginning
of menu.lst
# Hide GUI
hiddenmenu
# Boot from Floppy
title Boot from Floppy
rootnoverify (fd0)
chainloader +1
boot
| Quickly create a PC specific boot
floppy with stage1 |
# Create Boot Floppy
title Install stage1 into floppy disk
pause Insert a formatted floppy disk and press enter.
root (hd0,2)
setup (fd0)
pause Press enter to continue
| Auto creating
menu.lst by "update-grub"
|
debian has update-grub utility which creates menu.lst
automatically.
The command searches vmlinuz
files in /boot and creates the required entries for every found
kernels.
After update-grub has been run for the first time, the user is required
to edit the generated menu.lst to fine tune the configuration.
GNU GRUB
GNU GRUB FAQ
GNU GRUB Manual 0.97
The list of command line and menu entry
commands
GNU GRUB on Wikipedia