Find the answer to your Linux question:
Results 1 to 1 of 1
NOTE : if you read the tutorial and are still experiencing difficulties and would like help, you are asked to start a new topic on the forums . Please do ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer Nerderello's Avatar
    Join Date
    Apr 2003
    Location
    North East England
    Posts
    1,190

    Howto solve boot problems with Grub


    NOTE: if you read the tutorial and are still experiencing difficulties and would like help, you are asked to start a new topic on the forums.
    Please do NOT reply to this thread to ask a technical question. Replies to THIS thread should be corrections and enhancements on the tutorial/howto only.
    Thanks in advance for your co-operation.
    LinuxForums.org

    ------------------------------------------


    Please note this document has been superceeded by Version 2 available here:

    http://www.linuxforums.org/forum/lin...d-edition.html

    ---------------------------------------------------------------------------



    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 :- GNU GRUB Manual 0.97 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 moderator's (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/grub/stage1 :-

    Code:
    grub> find /boot/grub/stage1
     (hd0,1)
    The above example shows us that a file called /boot/grub/stage1 is on the (hd0,1) hard disk partition (see above for explanation of the hard disk naming convention that Grub uses).

    Once you know the hard disk partition that your kernel lives on, you can go about setting your root hard disk.

    The root will be on the same hard disk and partition that we found the Grub file /boot/grub/stage1 on. So, in the examples we have been doing so far, the "root" (i.e. the hard disk that has the "/boot/" directory 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 partition. Note, it actually has ext3 on it, but Grub is happy saying that it has ext2.

    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.2115.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.2115.nptl) as this is a symbolic link to the latest kernel, but I know that I'll need the "-2.4.22-1.2115.nptl" information later on, as it's part of the initrd name that I need to use.

    NOTE Certain distributions (Mandrake 9.2 for one) require that you also enter the two parameters "ro" (read only) and "root=/dev/hd??" on the same line as the kernel command (where the question marks are the hard disk letter and the partion number. Here we are using the Linux naming convention, which is described above in the "re-installing Grub section"). So, if in our examples we had such a distribution we would have to enter :-

    Code:
    For Mandrake 9.2
    
    grub> kernel (hd0,1)/boot/vmlinuz-2.4.22-10mdk ro root=/dev/hda2
       [Linux-bzImage, setup=0x1400, size=0x12c945]
    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.2115.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 we were booting into Mandrake 9.2 we would have entered the name of the initrd for that distribution (initrd-2.4.22-10mdk.img).

    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.6666.nptl.img
    
    Error 15: File not found
    We are now ready to boot, and so we use the boot command :-

    Code:
    grub> boot
    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
    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
    Last edited by oz; 11-30-2007 at 01:53 AM. Reason: updated URL to version 2

    Use Suse 10.1 and occasionally play with Kubuntu
    Also have Windows 98SE and BeOS

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •