Re: grub problem

From: Simon Kitching (simon_at_ecnetwork.co.nz)
Date: 07/08/04

  • Next message: ms419_at_freezone.co.uk: "network names, sortlist, & resolv.conf"
    To: Rodney Richison <rodney@rcrcomputing.com>
    Date: Thu, 08 Jul 2004 17:14:05 +1200
    
    

    On Thu, 2004-07-08 at 16:27, Rodney Richison wrote:
    > I attempted a repair floppy last night. It didn't work out real well.
    > Ahhh, for a command like sys a: :) Novel idea...
    >
    > Anyway here's what I did for future google searches. Maybe it'll help
    > someone someday.
    >
    > How to Repair Grub boot loader after debian ghost restore
    >
    > I booted with mepis (Any live-cd would probably do)
    > Open a terminal window
    > Mounted the drive (don't use the mepis icon as it mounts read only)
    > mount -rw /dev/hda1 /mnt/hda1
    > chroot /dev/hda1
    > grub-install /dev/hda
    >
    > Worked like a charm.. Am a bit confused what the drive is hda1 till I
    > get to the install part, but I'm guessing I'm mounting partition one on
    > hda, but the grub wants the "drive" to install to. Not the partition.

    Hi Rodney,

    The standard procedure for booting on the PC architecture is that the
    BIOS is configured with a list of boot devices and the order to scan
    them. It checks the MBR (master boot record, aka "boot sector") of each
    device in turn until it finds some executable code.

    Note: the BIOS does not care at all about the partitions on the drive,
    it only looks at the "boot sector" for the device.

    What grub-install does is write a small amount of code (512 bytes) into
    the MBR on a device, called the "stage1" code. This code is just smart
    enough to be able to read a sequence of hard-wired disk blocks (the
    "stage1.5" or "stage2" executable) into memory and jump to the loaded
    code. This data resides as a standard file in some kind of filesystem.
    Note that no filesystem knowledge is required - but the file being
    loaded had better not move on disk (eg defragmentation is a really bad
    idea) as the physical location of the blocks is wired into the MBR.

    That is why grub-install takes a "device" (hence /dev/hda) as a target,
    not a "partition"; it is installing the stage1 code into the MBR.

    And it needs to figure out the physical disk blocks which contain the
    executable which is the next "stage" of grub. So you can either mount
    the filesystem that will contain these files as the root partition
    (which you effectively did), or mount it elsewhere and pass the
    "--root-directory" option to grub-install. Of course here you are
    dealing with *filesystems* which reside on *partitions* (hence
    /dev/hda1).

    I hope this helps. I learnt much of this the hard way after having to
    fix unbootable systems just like you are doing now :-)

    The grub docs at http://www.gnu.org/software/grub/manual/grub.html are
    of course the ultimate source of info.

    NB: To confuse issues, each partition also has a "boot sector". The BIOS
    never looks at these, but a bootloader stored in the MBR of the device
    can be set up to delegate to the boot code in a partition's boot sector.

    BTW, there may be errors in the above - anyone who knows better is
    welcome to correct these.

    Regards,

    Simon

    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    

  • Next message: ms419_at_freezone.co.uk: "network names, sortlist, & resolv.conf"

    Relevant Pages

    • Re: Removing Linux from a dual boot system
      ... >>and each partition has a boot sector. ... and the usual choice seems to be the MBR. ... then loads that partition's bootsector and executes that. ...
      (comp.os.linux.misc)
    • Re: zeroing out HD
      ... When you're running through the filesystem layer, ... Since you're interested in preserving your boot sector, ... it up directly and restore it after you erase the partition. ...
      (comp.unix.programmer)
    • Re: GIDE interface kits
      ... Yes, looks like an MBR. ... it must have a master partition table at the correct ... load his boot sector and pass control to it. ... You must not write an MBR directly to the HD, you overwrite the partition ...
      (comp.os.cpm)
    • Re: Changing the system drive
      ... The boot sector on the partition marked "active" will get ... control from the MBR on that drive and then look for ntldr in ...
      (microsoft.public.windowsxp.general)
    • Re: Removing Linux from a dual boot system
      ... >sector on the disk) and each partition has a boot sector. ... >install GRUB's first stage to the MBR or to a partition bootsector, ... >and the usual choice seems to be the MBR. ...
      (comp.os.linux.misc)

    Loading