Guys, here is my first draft of the Grub micro howto. Please feel free to comment.
.................................................. ..
I wrote this as an aid to people who are having some problems getting started with Linux. It has not been written to replace the GRUB documentation, which can be found here :-
http://www.gnu.org/software/grub/manual/grub.html or by entering "info grub" on your Linux PC.
I have tried to address two common problems that users bump into with Grub, these are :-
1) I've just loaded / upgraded Windows and now I can't get into Linux!
And
2) I don't know why, but all I get now is a "grub>" prompt when I try and boot my PC!
The examples come from my PC, which runs Fedora Core 1 and has two separate IDE attached hard disks, but don't let any of this put you off, as you'll find that the commands will work just as well with your PC.
If your PC has SCSI hard disks, then replace the "hd" with "sd" in the commands below.
Windows has stopped me being able to boot into Linux
This problem (1) is caused by Uncle Bill's operating system deliberately overwriting an area of your hard disk known as the Master Boot Record (MBR). The MBR is the bit of your hard disk that holds the "where is the operating system" information. It is the MBR that your PC hands control over to, at boot up time, if it cant find an operating system in your floppy disk drive or your CD-ROM drive (The order that your PC looks for an operating system is set-up in the BIOS. Press either the Del or the F2 key to access your BIOS setup when you boot).
The easiest way out of this fix is to boot from the Linux rescue floppy diskette that you made when you installed Linux. If you remembered to create one, put it into your floppy diskette drive and boot your PC. When you get your Linux prompt, follow the instructions below in the section titled "re-installing GRUB".
If you 'forgot' to create a rescue diskette, read on.
What we have to do is get GRUB back onto the MBR, so that we can get the familiar GRUB menu of operating systems. To do this we must first wrest control away from Windows and back to GRUB. To do this we need two files which are available from one of our moderators (Dolda2000) web site.
http://www.dolda2000.com/~fredrik/grub.img http://www.dolda2000.com/~fredrik/rawrite.exe
Download these onto your PC (or any PC for that matter) and run the
rawrite program to copy the
grub.img file onto a pre-formatted floppy diskette (note, once this has been done, you will not be able to read that diskette. This is how it should be).
Now, boot your PC with this floppy diskette. You will get a text based screen looking something like this :-
Code:
GRUB version 0.92 (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>
Now we need to find out where your Grub files live. Do this by entering the "find /boot/grub/stage1" command.
Code:
grub> find /boot/grub/stage1
(hd0,1)
In the example above, you'll see that the diskette Grub has told us that this file (stage1) can be found on something called (hd0,1) . Put another way, on hard disk (hd) one (0) in partition two (1) there is a file called /boot/grub/stage1.
As you can see, the counting, here, is done starting at zero. So the first hard disk is "hd0" ,second "hd1" ,third "hd2" and so on. Your first partition is "0" , your second "1" , your third "2" and so on.
Why is this important? Well, we need to know where the Grub files live (and stage1 is one of these files) so that we can do the next command. If it helps you at all, you can think of (hd0,1) as being rather like "C:" in Windows.
Now that we know where grub lives - (hd0,1) in our example PC - we can get our normal Grub menu back by entering :-
Code:
grub> configfile (hd0,1)/boot/grub/grub.conf
Obviously you will put the hard disk and partition number (hd?,?) that you got from your 'find' command.
You will now be presented with your normal, familiar Grub menu. Select and boot into Linux, and then re-install Grub onto your MBR, using the following steps.
Re-installing Grub
Now that your safely back into Linux, you'll want to get Grub back onto your hard disk's MBR. This is simply done by opening a terminal window as root (or as your normal user and entering 'su -' to become the root/super user) and enter the "grub-install" command. This command takes a single parameter, which is the name of the hard disk that you want Grub to be installed on. Now that we are in Linux, the hard disk naming convention is no longer the (hd0,1) format that we used in grub, but the one that Linux uses. This starts with /dev/ and is followed by 'hd' and then a letter from 'a' to 'd' .
So, if you normally boot from your first (and perhaps only) hard disk, you will use "/dev/hda". If you normally boot off your second hard disk you will use either "/dev/hdb" or "/dev/hdc" or /dev/hdd" depending upon which IDE cable it is plugged into and whether it is the master or slave on that cable (a and b are master and slave on IDE1 ,while c and d are master and slave on IDE2).
Code:
[root@localhost nerderello]# /sbin/grub-install /dev/hda
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'.
# this device map was generated by anaconda
(fd0) /dev/fd0
(hd0) /dev/hda
(hd1) /dev/hdc
In the above example I have installed Grub on the MBR on my first hard disk. The messages generated also show that I have three write-able disks on my PC - "fd0" being my floppy diskette drive, "hd0" being hard disk number 1 (remember the counting starts at zero), and "hd1" being my second hard disk drive (which, we can see from the "c" in /dev/hdc is the master on the IDE2 cable).
And that's it. You now have Grub back where you want it. Now, create a Linux rescue diskette, so that you won't have to go through that little lot again (
use the "mkbootdisk" command to create one).
I just get a grub> prompt
This problem (2) is a little more worrying. You can try getting the usual Grub menu back up by doing the "find" and then the "configfile" commands (see above), but these may not work. So here is how to boot Linux from the "grub>" command.
First we need to find out where the kernel lives (find command again), then we need to set "root" to its proper device, then we need to tell Grub which kernel to use and then (optionally) which initrd to use (note. the word "root" here is used to mean the starting point, rather than anything to do with the root user).
The first bit uses the "find" command to find a file called /boot/vmlinuz :-
Code:
grub> find /boot/vmlinuz
(hd0,1)
The above example shows us that a file called /boot/vmlinuz is on the (hd0,1) hard disk partition (see above for explanation of the hard disk naming convention that Grub uses).
There are a couple of problems with this approach. One is that your PC may not have a file called vmlinuz, the other is that you may have a separate "boot" partition. For the first of these problems you'll have to use a trial and error technique to find the kernel - sometimes called vmlinuz - by using the "kernel" (see below) command with all of the permutations of your hard disk(s)and partition numbers, until you find the correct one. The second problem can be got around by trying "/vmlinuz" instead of "/boot/vmlinuz" .
Once you know the hard disk that your kernel lives on, you can go about setting your root hard disk.
There is no easy way of knowing what hard disk your root is on, although it is probably the same as where you Grub files(such as /boot/grub/stage1) live. So, in the examples we have been doing so far, the "root" (i.e. the hard disk that has the "/" on it) would be on (hd0,1). To set this we enter the root command :-
Code:
grub> root (hd0,1)
Filesystem type is ext2fs, partition type 0x83
In the above example we can see that Grub is happy with the command and is telling us that it found the Linux ext2 file system on that hard disk.
Now it's time to tell Grub what the kernel file is called and where it is. For this we use the "kernel" command. If you know what your kernel is called and where it is you can simply type it in. If you're not sure, and let's face it some of them have long names, we can type part of the kernel command and then press the Tab key, Grub will try and help out.
Code:
grub> kernel (hd0,1)/boot/
Possible files are: grub System.map-2.4.22-1.2115.nptl vmlinuz boot.b chain.b
os2_d.b System.map vmlinuz-2.4.22-1.2115.nptlcustom System.map-2.4.22-1.2115.np
tlcustom initrd-2.4.22-1.2115.nptlcustom.img module-info kernel.h vmlinuz-2.4.2
0-8custom System.map-2.4.20-8custom initrd-2.4.20-8custom.img vmlinuz-2.4.20-8c
ustom.old System.map-2.4.20-8custom.old initrd-2.4.22-1.2115.nptl.img config-2.
4.22-1.2115.nptl vmlinux-2.4.22-1.2115.nptl vmlinuz-2.4.22-1.2115.nptl initrd-2
.4.22-1.2149.nptl.img System.map-2.4.22-1.2149.nptl config-2.4.22-1.2149.nptl v
mlinux-2.4.22-1.2149.nptl vmlinuz-2.4.22-1.2149.nptl
grub> kernel (hd0,1)/boot/vmlinuz-2.4.22-1.2149.nptl
[Linux-bzImage, setup=0x1400, size=0x12c945]
As you can see from the above example I typed "kernel (hd0,1)/boot/" and then pressed the Tab key. Grub then gave me all of the files in the /boot/ directory on the second partition of the first hard disk (hd0,1). I then typed in the correct kernel file name for my Linux release. I could have entered "vmlinuz" instead of the long name (vmlinuz-2.4.22-1.2149.nptl) as this is a symbolic link to the latest kernel, but I know that I'll need the "-2.4.22-1.2149.nptl" information later on, as it's part of the initrd name that I need to use.
Now comes the optional part. Optional in as much as not every kernel is created needing an initrd. An initrd is used to allow Linux to load various modules that it needs to be able to boot correctly. You'll soon find out if your kernel needs an initrd, if you try and boot without one your kernel will "panic" (crash) complaining of INIT problems, and you'll have to press the reset button.
If you do need an initrd, you tell Grub by using the "initrd" command. The name of the initrd file
must match that of your kernel.
Code:
grub> initrd (hd1,0)/boot/
Possible files are: grub System.map-2.4.22-1.2115.nptl vmlinuz boot.b chain.b
os2_d.b System.map vmlinuz-2.4.22-1.2115.nptlcustom System.map-2.4.22-1.2115.np
tlcustom initrd-2.4.22-1.2115.nptlcustom.img module-info kernel.h vmlinuz-2.4.2
0-8custom System.map-2.4.20-8custom initrd-2.4.20-8custom.img vmlinuz-2.4.20-8c
ustom.old System.map-2.4.20-8custom.old initrd-2.4.22-1.2115.nptl.img config-2.
4.22-1.2115.nptl vmlinux-2.4.22-1.2115.nptl vmlinuz-2.4.22-1.2115.nptl initrd-2
.4.22-1.2149.nptl.img System.map-2.4.22-1.2149.nptl config-2.4.22-1.2149.nptl v
mlinux-2.4.22-1.2149.nptl vmlinuz-2.4.22-1.2149.nptl
grub> initrd (hd1,0)/boot/initrd-2.4.22-1.2149.nptl.img
[Linux-initrd @ 0x3c8000, 0x27dcb bytes]
In the above example, again using the Tab key to assist me, I used the same version number for my initrd as I did for my kernel (-2.4.22-1.2149.nptl).
If you mistype the name, all that happens is that Grub gives you an error message :-
Code:
grub> initrd (hd1,0)/boot/initrd-2.4.22-1.666.nptl.img
Error 15: File not found
We are now ready to boot, and so we use the boot command :-
With a little bit of luck Linux will appear and you'll be able to follow the configuration (youll need a /boot/grub/grub.conf file) and installation instructions for Grub (enter "info grub" at a Linux terminal prompt).
If you're still having problems here are a few tips
If your Grub config file is there, but not readable at boot up, you may still be able to find the names of your kernel and inird by looking at its contents. You do this with the "cat" command, like so :-
Code:
grub> cat (hd0,1)/boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,1)
# kernel /boot/vmlinuz-version ro root=/dev/hda2
# initrd /boot/initrd-version.img
#boot=/dev/hda
default=0
timeout=10
splashimage=(hd0,1)/boot/grub/splash.xpm.gz
title Fedora Core (2.4.22-1.2149.nptl)
root (hd0,1)
kernel /boot/vmlinuz-2.4.22-1.2149.nptl ro root=LABEL=/ rhgb
initrd /boot/initrd-2.4.22-1.2149.nptl.img
title Fedora Core (2.4.22-1.2115.nptlcustom)
root (hd0,1)
kernel /boot/vmlinuz-2.4.22-1.2115.nptlcustom ro root=LABEL=/ rhgb
initrd /boot/initrd-2.4.22-1.2115.nptlcustom.img
title Fedora Core (2.4.22-1.2115.nptl)
root (hd0,1)
kernel /boot/vmlinuz-2.4.22-1.2115.nptl ro root=LABEL=/ rhgb
initrd /boot/initrd-2.4.22-1.2115.nptl.img
title Windoze 98
rootnoverify (hd1,1)
chainloader +1
As an aside, the "rhgb" parameter on my kernel lines (above) is to run a pretty graphic screen that comes with Fedora, instead of the usual text list, while my PC boots Linux.
The only other Grub command that I'm going to mention here is the "help" command
Code:
grub> help
blocklist FILE boot
cat FILE chainloader [--force] FILE
clear color NORMAL [HIGHLIGHT]
configfile FILE device DRIVE DEVICE
displayapm displaymem
find FILENAME geometry DRIVE [CYLINDER HEAD SECTOR [
halt [--no-apm] help [--all] [PATTERN ...]
hide PARTITION initrd FILE [ARG ...]
kernel [--no-mem-option] [--type=TYPE] makeactive
map TO_DRIVE FROM_DRIVE md5crypt
module FILE [ARG ...] modulenounzip FILE [ARG ...]
pager [FLAG] partnew PART TYPE START LEN
parttype PART TYPE quit
reboot root [DEVICE [HDBIAS]]
rootnoverify [DEVICE [HDBIAS]] serial [--unit=UNIT] [--port=PORT] [--
setkey [TO_KEY FROM_KEY] setup [--prefix=DIR] [--stage2=STAGE2_
terminal [--dumb] [--no-echo] [--no-ed terminfo [--name=NAME --cursor-address
testvbe MODE unhide PARTITION
uppermem KBYTES vbeprobe [MODE]
I hope that you have found this of some use.
Have fun
Nerderello