What is the Grub-Bootmanager?General
Grub is a bootmanager that can boot operating systems from different partitions. Grub does not rely on blocklists to find the needed files for a system to start up, and it can read a bunch of filesystems by default: ext2, ext3, reiserfs, ... (Linux), Fat32, Fat16 (Windows), UFS (BSD), Minix and many others.
Grub knows BIOS-extensions (meaning it can boot partitions above 8 GByte!) and knows no1024-cylinder-barrier. Grub doesn't really care, where the kernel physically lies, all it needs is the declaration of the partition and the path to the kernel it's supposed to boot (this can even be a symlink). After a change in the configuration (i.e. the menu.lst) it doesn't need a program-call like Lilo does, the new configuration is applied at next boot.
KANOTIX uses Grub to boot from CD, and when installing to harddisk, Grub is used by default. Nonetheless Grub can be installed afterwards without a problem. Grub is intalled to the MBR from a root-shell with the following command (for KANOTIX's version 2005-03 or older use mnt instead of media):
# grub-install --root-directory=/media/hdaX /dev/hdY
/media/hdaX stands for the readable-mounted partition, on which, in the directory "/boot/grub" the neccessary files (stage2, stage1_5xxx) will be placed. The configurationfile "menu.lst" must also be created in that directory. /dev/hdY is the harddisk, in whose MBR Grub will be installed, normaly /dev/hda.
Drivenames/Devicenames
Grub does not differentiate between SCSI- and IDE-Harddisks. (hd0) is always the first harddisk that is first in the bootsequence (setting in BIOS), no matter if IDE or SCSI. Unusual is the counting method; the first partitioin on the first hd is (hd0,0). Primary partitions are numbered from 0-3, logical partitions count from 4 on up.
Grub | Linux | Label |
(fd0) | /dev/fd0 | Floppy (under Windows) |
(hda0) | /dev/hda | first hd |
(hd0,0) | /dev/hda1 | Part.1 on hd1 |
(hd0,5) | /dev/hda6 | extended. part. on hd.1 |
All nominations for devices for Grub are to be put in brackets (). Be aware of the entries behind the Kernel-line though. In contrast to Grub the Kernel needs the data in the normal linux-way. The entries in the following example both point to the same partition, namely the fourth partition on the first hd. The first line is in Grub-notation, the second one in typical linux-notation:
root (hd0,3)
kernel /boot/vmlinuz root=/dev/hda4
Command-Mode (Grub-Shell)A very comfortable feature is the Command-Mode. It is accessed by "
c", and here comes the Grub-Shell. This enables you to find and boot different systems and files (i.e. Kernel) even with a faulty menu.lst.
To do a little bit of testing, you can even run Grub from a booted system from within a root-shell with
"grub". In the Grub-Shell you can see all possible commands with
"help". Detailed help for each command is obtained with
"help<command>
", back to the Linux-Shell you go with
"quit"( Grub-Shell is terminated). In the Grub-Shell the tab-key has a similar function as in the Linux-Shell, which is a great ease. Commands, Drivenames and Filenames can be auto-completed with the tab-key.
Grub gives you the opportunity to locate the Kernel and the initrd even before actual boot by "
find" , e.g.with the following command
find /boot/vmlinuzGrub shows the partitions, that have a Kernel with the name "vmlinuz" in the directory "/boot":
(hd0,3) (hd1,0)All available partitions can be found with "
geometry", e.g.
geometry (hd0)shows this:
"drive 0x80: C/H/S = 3648/255/63, The number of sectors = 58605120, /dev/hda Partition num: 0,
Filesystem type is fat, partition type 0xb Partition num: 1,
Filesystem type is fat, partition type 0xb Partition num: 2,
Filesystem type is fat, partition type 0xc Partition num: 4,
Filesystem type is ext2fs, partition type 0x83 Partition num: 5,
Filesystem type unknown, partition type 0x82 Partition num: 6,
Filesystem type is fat, partition type 0xb"After the Kernel or an existing initrd (or miniroot.gz) has been found, you can start with "boot".
Edit-Mode
This mode enables you to change entries in the "menu.lst" while booting. This works even when Grub is booted from CD an the menu.lst is write-protected . To do so you first hit
ESC, confirm with
Return and then hit "e". The parameters are then added to the end of the line or you move within the line with the Cursor-keys.
menu.lst (examples for possible entries)Lines with comments are started with # and dont interfere with the bootprocess, so they can stay in the file.
# Example /boot/grub/menu.lst
################################################
# setkey changes the keyboardlayout to german
setkey y z
setkey z y
setkey Y Z
setkey Z Y
setkey equal parenright
setkey parenright parenleft
setkey parenleft asterisk
setkey doublequote at
setkey plus bracketright
setkey minus slash
setkey slash ampersand
setkey ampersand percent
setkey percent caret
setkey underscore question
setkey question underscore
setkey semicolon less
setkey less numbersign
setkey numbersign backslash
setkey colon greater
setkey greater bar
setkey asterisk braceright
# sets time in seconds, after that automatic boot will be conducted.
# inbetween you can call Edit- or Commandmode with "e" or "c".
timeout 30
# sets the Default-System that is booted after the timeout
default 0
# remembers the partition that was booted last, if "savedefault" is set under Title
#default saved
# is booted, when booting of the default-entry fails
fallback 1
# set foreground/background colours
# options:flashes red background: blue
color white/blue blink-red/blue
# entry 1 is default 0 and boots e.a.. Windows 98
#################
title Windows 98 (partition 1 on disk 1)
rootnoverify (hd0,0)
makeactive
chainloader +1
# entry 2 is default 1 and boots e.a. Windows 2000
#################
title Windows 2000 (partition 2 on disk 1)
rootnoverify (hd0,1)
makeaktive
chainloader
/bootsect.dos
# entry 3 is default 2 and boots Suse
##################
title Suse-Linux
root (hd1,5)
kernel /boot/vmlinuz
root=/dev/hdb6 read-only
# other parameters are possible i.e.:
# kernel /boot/vmlinuz root=/dev/hdb6 single kernel /boot/vmlinuz root=/dev/hdb6 vga=ask
# entry 4 is default 3 and boots Debian
##################
title GNU/Debian (first extended partition on disk 2)
root (hd1,4)
kernel /boot/vmlinuz
root=/dev/hdb5 read-only
# entry 5 is default 4 und boots DOS from disk
##################
title DOS (partition 3 on disk 1)
root (hd0,2)
makeactive chainloader +1
# entry 6 is default 5 und boots from floppy
##################
title floppy
chainloader (fd0)+1
Booting from secondary disk:(e.g. several Windows-Installations)Some people need/want several Windows-Installations. Windows always wants to boot from disk 1. We will have to hide one partition and activate another. The following commands should be enterd in the
GRUB-Commandline and, if successfull, copied to the menu.lst. This should be done for every Windows-partition. Dont forget to do a Backup! ;-)
hide (hd0,0) # hidden partition 1 of disk 1
unhide (hd0,1) # makes partition 2 of disk 1 visible
rootnoverify (hd0,1) # makes partition 2 of disk 1 the Root-FS
makeactive # makes partition 2 of disk 1 aktiv
chainloader +1 # points to the first sector of the start-partition
boot # boots the operating systemIf you want to start a 2nd Windows from the 2nd disk, you virtually swap disk 1 and 2. Thereby Windows sees a simulated 1st disk:
map (hd0) (hd1)
map (hd1) (hd0)
Pitfalls Grub knows no 1024-cylinderbarrier and can boot systems above 1024 cylinders.
However, "/boot/grub/stage2" must be accessible by the bios (must be before 1024 cylinders). Stage2 may not be moved after installation (e.g. Defrag could try that). Setup data will get written that would't be congruent anymore. It is reasonable to make stage2 read-only (you must be in the current directory):
Dos:
attrib +r +s stage2LINUX:
# chmod a -w ./stage2
Have you gotten interested?... then get a Grub-Floppy-Image
here(ca. 580 kB) and play around a bit. On the floppy you also find a functioning FreeDOS and an editor. If you remove the write-protection from the disk, you can edit the menu.lst on the floppy to your needs.
The official FAQ for Grub is found
here.
If you have a supported network card, Grub can boot over the network. An appropriate Boot-Disk can be obtained
here (allthough with an older version of Grub).
nach oben