Why doesn't reinstalling GRUB always work?


Page 1 of 2 12 LastLast
Results 1 to 15 of 29

Thread: Why doesn't reinstalling GRUB always work?

  1. #1
    Join Date
    Jan 2003
    Location
    Zurich, Switzerland
    Posts
    2,657

    Why doesn't reinstalling GRUB always work?

    So, there I have Kubuntu on hdb and Windows on hda with the need to reinstall Windows. No problem, I thought, I will just reinstall GRUB with a liveCD as I had already done earlier. After all, it's quite easy:

    1. mount /dev/hdb1
    2. chroot into hdb1
    3. grub
    4. root (hd1,0)
    5. setup (hd0)


    However, once I had finished reinstalling Windows and my Knoppix 3.2 CD booted, GRUB kept saying it either can't find the files or partitions, yet Knoppix displayed them nicely. Thus I restarted my computer, booting from a Kubuntu liveCD this time, and (tadaaa!) everything worked like a charm. When I started GRUB with the Kubuntu liveCD loaded, GRUB probed my BIOS/drives, but when I had Knoppix running, it didn't do that. What's the explanation for this phenomenon? AFAIK know, both Knoppix 3.2 and Kubuntu 5.10 use GRUB 0.95, plus since I'm in a chrooted environment, the liveCD shouldn't matter at all, should it?

    "What can be said at all can be said clearly, and what we cannot talk about we must pass over in silence."

    Tractatus Logico-Philosophicus by Ludwig Wittgenstein (1889-1951)

  2. #2
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    The way I understand it is in reinstalling Windows the MBR will be taken over by the Windows own version. Therefore Grub should only installed after you finish the Windows installation/reinstallation.

    In involking a Grub shell, either with Knoppix or Kubuntu, I believe the steps 1, 2 and 3 can be omitted. These steps are necessary only if you use
    Code:
    grub-install /dev/hda
    The step 4 and 5 should effectively source the Grub's stage1, stage2 and stage1.5 from the (hd1,0) partition and setup Grub to table over the MBR of (hd0). From that point onward there should be no necessity of booting to any CD.

    From my experience reinstalling Grub always works. It is possible that the "grub-install" could fail in Linux but "root+setup" in a Grub shell seems pretty robust in practice.

    Should try to boot up the hard disk without the CD as that is what "root+setup" supposed to do it for us-->To boot via the MBR of the first disk (hd0).
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  3. #3
    Join Date
    Jan 2003
    Location
    Zurich, Switzerland
    Posts
    2,657
    Quote Originally Posted by saikee
    The way I understand it is in reinstalling Windows the MBR will be taken over by the Windows own version. Therefore Grub should only installed after you finish the Windows installation/reinstallation.
    Right, that's what I did. I unplugged my Linux drives, installed Windows on hda, so the only task left was to write back GRUB into the MBR of hda.

    Quote Originally Posted by saikee
    From my experience reinstalling Grub always works. It is possible that the "grub-install" could fail in Linux but "root+setup" in a Grub shell seems pretty robust in practice.
    Well, from my experience that's not the case, although I'm not nearly the GRUB expert as you are. However, that's why I am so curious about what could make it fail. As I said in my previous post, the crucial point is when I call up the grub shell with the grub command; sometimes grub immediately starts to scan my computer for my drives, and in those cases the root and setup command work just fine. On other occasions, GRUB doesn't do any probing and simply refuses to see any drives, although the liveCD correctly writes them into fstab.

    So far I have successfully reinstalled GRUB twice:

    1. With a Knoppix 3.2 CD chrooting into Debian Sarge
    2. With a Kubuntu LiveCD chrooting into Kubuntu Breezy


    All other attempts that failed were about installing directly from the liveCD (without chrooting) or with the Knoppix CD on a non-Debian distro. So what's the matter? The liveCD? The GRUB version? My hardware?

    "What can be said at all can be said clearly, and what we cannot talk about we must pass over in silence."

    Tractatus Logico-Philosophicus by Ludwig Wittgenstein (1889-1951)

  4. #4
    Join Date
    Apr 2003
    Location
    Buenos Aires, Argentina
    Posts
    4,219
    /me hates boot problems.

    I've experienced problems like you, Parcival. I wish I had all the answers to your questions

    Fscking machines
    djserz.com.ar
    "All the drugs in this world won't save you from yourself..."

  5. #5
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    I think I beginning to see the light here.

    The problem could be to do with the chroot command.

    If you use a Live CD with Grub support you don't need to change root as you would have access to the Grub shell from the booted up Live CD.

    I myself isn't absolutely certain on the behaviour of the chroot command but it is supposed to put you inside the a Linux "other" than the one you have booted to with the Live CD.

    It is possible that in using a Live CD with Grub inside you could be using another version of Grub from the "chrooted" Linux. From memory I believe you can't invoke a Grub shell in a "chrooted" Linux that is servred by Lilo only, although this isn't your case.

    There has been talks and speculations that after a chroot command the available kernel is the one that booted up originally and not the one "chrooted" to but I cannot substantiate this. However it looks increasing likely that your claimed misbehaviour of Grub could be chroot-related.

    I did not notice Knoppix supports Grub before before Version 4 or 3.9 as it always uses Lilo as the boot loader. I was surprised to find it in Version 4. Is it possible that the failure to install Grub without chrooting is due to the no Grub support in the chosen Live CD? It is quite rare for a distro to support both Grub and Lilo simultaneously.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  6. #6
    Join Date
    Jan 2003
    Location
    Zurich, Switzerland
    Posts
    2,657
    Quote Originally Posted by saikee
    If you use a Live CD with Grub support you don't need to change root as you would have access to the Grub shell from the booted up Live CD.
    Yes, that makes sense, so indicating the correct root and do the setup should be sufficient in those cases.

    Quote Originally Posted by saikee
    I myself isn't absolutely certain on the behaviour of the chroot command but it is supposed to put you inside the a Linux "other" than the one you have booted to with the Live CD.
    This is partially true:

    'chroot' runs a command with a specified root directory. On many systems, only the super-user can do this. If COMMAND is not specified, the default is the value of the `SHELL' environment variable or `/bin/sh' if not set, invoked with the `-i' option.
    In other words, the system with the kernel and everything is still the same, it's just the shell that does the switch. From this point onward, every command that is called from inside the chrooted environment will load from the mounted partition and not from the liveCD's set of applications anymore. Yet the kernel, memory allocation, etc. is still being done by what the liveCD booted with, so I wonder if this could be a conflict? If GRUB required a certain functionality of the kernel that isn't provided by Knoppix 3.2, this would explain why Kubuntu's GRUB wouldn't work even when chrooted into it.

    "What can be said at all can be said clearly, and what we cannot talk about we must pass over in silence."

    Tractatus Logico-Philosophicus by Ludwig Wittgenstein (1889-1951)

  7. #7
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    I did a trial with an installed Damn Small Linux 2.1 that has a 2.4.31 kernel and Grub 0.91. On my current mobo the DSL 2.1 does not recognise my two Sata disks (hd2) and (hd3). In other word when invoking a Grub shell the commands
    Code:
    geometry (hd2)
    geometry (hd3)
    return an error saying "disk does not exist". I had this check done first.

    I then booted up Kanotix 2005-04 Live CD, which has a modern 2.6.14 kernel plus Grub 0.96. It has no problem of seeing the geometry of (hd2) and (hd3).

    I then chrooted to hdc16 which holds DSL 2.1 and invoked its Grub 0.91. Suddenly I could see the geometry of (hd2) and (hd3).

    Thus you are correct in suggesting the booted kernel and the memory map are same as the booted up Kanotix. When invoking the chrooted DSL's 0.91 Grub the two Sata disks suddenly become available because they were recognised by the 2.6.14 Kernel of Kanotix.

    I tried to do a reverse test of using an old Knoppix 3.3 Live CD to change root a new installed distro like FC5 or Kubuntu Dapper but the operations were successful as the old Knoppix 3.3 could neither load a partition higher than 20 nor chroot to a distro significantly newer than itself.

    It does look the chroot operation could have introduced some uncertainties into the Grub re-installation. The newly installed Grub is no longer identical to the previously one generated from the original distro because it has been created under a different kernel.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  8. #8
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    It may be related to either grub's (hdX,Y)-to-/dev/hdXY mapping, or the lack of block device files when you're inside chroot.

    The grub shell does not access the drives directly (i.e. via BIOS interrupt calls); the Linux kernel doesn't let it. So the grub shell has to map its (hdX,Y) values to something that it can access, i.e. /dev/hdXY. If that mapping isn't correct for some reason, that might cause the issues you're seeing. (I'm not sure where the mapping comes from. I thought there was a config file for it, but it might be hardcoded into grub.) Or if the /dev/hdXY file that grub is trying to probe doesn't exist, that might also cause the issue you're seeing.

    (Some distros don't put any files in their /dev directory, but plan on udev populating it for them. If that's what Kubuntu does, then when you chroot, you won't have any /dev/hdXY devices, so grub won't be able to probe or write to them. In order to get it to do that, you'll probably have to run Kubuntu's udev-startup script. This would explain why it works from the livecd: the livecd has device files available.)

  9. #9
    Join Date
    Jan 2003
    Location
    Zurich, Switzerland
    Posts
    2,657
    bwkaz, when I chroot into a new environment, are the devices still accessed according to how they are defined from the liveCD or is the shell using the definitions as they appear oon the mounted/chrooted partition?

    Either way, I don't feel comfortable anymore suggesting to a newbie to just throw in a liveCD and reinstall GRUB when they can't access their Linux anymore since this doesn't seem to be a 100% reliable strategy as saikee's experiment has confirmed. What advice could be given to a newbie to make sure it's gonna work? Always use the same version of the liveCD like the one of the installed system?

    Is in the age of modern storage solutions a 1.44MB diskette holding GRUB the only thing that reliably works? I wouldn't know since I am too lazy to have ever made one.
    Last edited by Parcival; 03-15-2006 at 01:49 AM.

    "What can be said at all can be said clearly, and what we cannot talk about we must pass over in silence."

    Tractatus Logico-Philosophicus by Ludwig Wittgenstein (1889-1951)

  10. #10
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    Parcival,

    I have been getting reliable response from Grub using Live CD.

    My approach differs from you as I either

    (1) Use a Live CD (or any installed Linux) and chroot to the new Linux and use only "grub-install" command to install Grub.

    or

    (2) Use Live CD Grub shell directly if I issue "root+setup" commands. In this case no "chroot" and no "grub-install" is involved.

    Since Grub was working before so restalling it even with the assistance of a different kerent should not matter at all, as we can freely change the kernel when coming to booting.

    It appears the reliability issue is more to do with using an older LiveCD distro to reinstall a newer Linux.

    It so happen I always use the current version LiveCDs while you are using a Knoppix 3.2 which is older than the oldest Knoppix 3.3 I got, when I first started Linux in June 2004.

    Using a bootable Grub floppy, to obtain a Grub prompt instead of a Grub shell, does simplify the situation considerably because no kernel is involved and Grub gets everything directly from the Bios.

    I have been selling hard to my fellow newbies to use the bootable Grub floppy because a Grub prompt seldom hangs and so one can repeatedly try various ways to get the system booted. I certainly benefitted enormously from learning to boot a system manually.

    I am still of the opinion that there is no PC system that cannot be booted by a Grub floppy. The system has to be of course originally a working system before. What a Live CD can offer that a bootable Grub floppy can are

    (a) A Live CD can restore Lilo too whereas a Grub floppy can't. It can only boot the same Linux using Grub (after "cat" its /etc/lilo.conf and then use the kernel and initrd information). The Grub floppy can restore Grub of course.

    (b) A Grub floppy can't list the directory (or I do not know how yet) and can't boot the Linux if it has no /etc/lilo.conf or /boot/grub/menu.lst because the names of the kernel and initrd are not available. A LiveCD can provide that information.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  11. #11
    Join Date
    Apr 2001
    Location
    SF Bay Area, CA
    Posts
    14,936
    Quote Originally Posted by Parcival
    bwkaz, when I chroot into a new environment, are the devices still accessed according to how they are defined from the liveCD or is the shell using the definitions as they appear oon the mounted/chrooted partition?
    Depends on what you mean by "definitions". Grub must use the device files stored on the chrooted partition (those are the only files it has access to), so if these files don't exist, that will be a problem. But the only parts of those files that matter are the device type (block), the major number (which determines hd[ab] or hd[cd] or hd[ef] or hd[gh], etc.), and the minor number (which determines both which disk of the pair above it is, and which partition on that disk).

    When grub accesses (e.g.) /dev/hda, and the chrooted partition's /dev/hda exists and is correct (type block, major 3, minor 0), the LiveCD kernel says "I have a request coming in on block-major-3-minor-0; what driver handles that?", then passes it off to the IDE driver. The IDE driver sees that it's block major 3 and minor 0, which means it's hda, so it does the appropriate read, write, or seek on the entire primary master drive.

    So the answer is really "it uses both": it uses the type, major, and minor numbers found on the chrooted partition, but it uses the kernel driver from the LiveCD.

    Quote Originally Posted by saikee
    (b) A Grub floppy can't list the directory (or I do not know how yet)
    Use the tab key, it's your friend.

    For instance:

    kernel (hd0,0)/boot/bzImag<TAB>

    might produce something like:

    kernel (hd0,0)/boot/bzImage-2.6.1
    (hd0,0)/boot/bzImage-2.6.11.5 (hd0,0)/boot/bzImage-2.6.14 (hd0,0)/boot/bzImage-2.6.15.5
    kernel (hd0,0)/boot/bzImage-2.6.1

    (where you need to type in 1, 4, or 5 and then use tab to finish off the filename). It scans through the boot directory and tries to do filename completion on each possible file. (This is mostly similar to what bash does.)

  12. #12
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    bwkaz,

    Thanks for the tip. It works like a treat!

    Just booted up my FC4 from a Grub prompt without referring to my notes for the first time.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  13. #13
    Join Date
    Jan 2003
    Location
    Zurich, Switzerland
    Posts
    2,657
    bwkaz, thanks for the clarification. I figure the reason why it worked with the Kubuntu liveCD but not with Knoppix must be somewhere in the kernel since neither the chrooted partition or the commands I typed were changed at all. That would also explain why my Knoppix 3.2 worked with Debian Sarge. I am tempted to say that one can see what a legacy type of system Debian stable is by how it works with a four year old liveCD.

    "What can be said at all can be said clearly, and what we cannot talk about we must pass over in silence."

    Tractatus Logico-Philosophicus by Ludwig Wittgenstein (1889-1951)

  14. #14
    Join Date
    Jun 2004
    Location
    Newcastle upon Tyne
    Posts
    2,978
    bwkaz's description of mapping the drives/partitions and the use of hda, hdb etc is stretching my knowledge a bit.

    OK in a Grub shell with a Linux kernel installed that could well be what is happening. It is also true the file /boot/grub/device.map does show how (hd0) is mapped with /dev/hda and so on.

    I frequently use a Grub floppy, which has only stage1 and stage2 files inside, and when it is booted I have a Grub prompt which for all intent and purpose does everything as a Grub shell.

    My point is Grub doesn't seem to use the Linux's notation of hda, hdb, hdc... at all. There is no need to map the drive until a kernel is required to be booted. Grub always call a disk and partition by a numbering system like (hd0,2).

    In a Grub prompt Grub has no access to a kernel and so command like "root" and "setup" should be operable without the need of a kernel. I have used a Grub floppy to restore Grub countness times this way using the just "root" + "setup" commands.

    The hda, hdb and hdc... etc is only used to point to the real root of the kernel partition but that would be in the stage where the kernel statement is activated. Grub can do a lot of other tasks too without booting up a kernel.

    I have just done a test using DSL 2.1. It has Grub 0.91 and kernel 2.4.31. I have previously confirmed that when its Live Cd booted both its kernel and Grub shell do not recognise my 3rd and 4th disks where are both Sata type.

    What I have just did is to boot the Live CD up, use Linux Bash shell to report the storing location of Grub's stage1 and stage2 which is /KNOPPIX/usr/grub/i386-pc. I then "dd" the stage1 and stage2 into a floppy to make a bootable Grub floppy.

    When the floppy boots it shows correctly it is a Grub 0.91 but the commands
    Code:
    geometry (hd2)
    geometry (hd3)
    ,which has been heretofore failed to work in the booted up DSL, suddenly fire up and report the partitioning details of my two 200Gb Sata disks.

    The above shows that the Grub 0.91 can recognise Sata and it is the 2.4.31 kernel that stops it from access them! More accurately I think Grub 0.91 can interpret the Bios information correctly when it is "NOT colored" by the kernel with the second-hand hardware information.

    Grub 0.91 is the oldest version of Grub in my possession and it has showed up accurately all the 60 partitions in my 300Gb IDE (hd0) and 57 partitions in the second 300Gb IDE (hd1). This fact is at variant with some forum members commenting older Grubs cannot recognise/access disk larger than 137Gb and so Grub needs to be placed lower down, like in a devoted /boot partition below the first 1024 cylinders.

    My point is to suggest Grub can access the disks and partitions directly with the Bios information when there is no kernel around. If a kernel has been installed then Grub is forced to use the "processed" hardware information by the kernel.

    Therefore "chrooting" to yet another Linux is "NOT" conducive to improve Grub's reliability at all.
    Last edited by saikee; 03-16-2006 at 08:19 PM.
    Linux user started Jun 2004 - No. 361921
    Using a Linux live CD to clone XP
    To install Linux and keep Windows MBR untouched
    Adding extra Linux & Doing it in a lazy way
    A Grub menu booting 100+ systems & A "Howto" to install and boot 145 systems
    Just cloning tips Just booting tips A collection of booting tips

    Judge asked Linux "You are being charged murdering Windoze by stabbing its heart with a weapon, what was it?" Replied Linux "A Live CD"

  15. #15
    Join Date
    Jan 2003
    Location
    Zurich, Switzerland
    Posts
    2,657
    ...and therefore using a GRUB disk is definitely the better advice for anybody than doing the same task with a liveCD.

    "What can be said at all can be said clearly, and what we cannot talk about we must pass over in silence."

    Tractatus Logico-Philosophicus by Ludwig Wittgenstein (1889-1951)

Posting Permissions

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