Author Topic: Question about GRUB logic  (Read 1963 times)

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11587
  • ----IOFLU----
Re: Question about GRUB logic
« Reply #15 on: February 15, 2011, 01:44:39 PM »
All good points. I preferred not to touch the windows mbr/bcd. And on the XP box I intend on adding 7 later on, and I'd prefer to work with the boot via EasyBCD. Now I will have to deal with grub, which I know little about.

I'm probably in the minority. But I think a way to install linux without touching the Win install would be a plus for many people.

The way to install Linux without touching Windows in any manner is to install it to its own hard drive, install grub to the MBR of the Linux drive, and make that hard drive the boot drive. You had that opportunity when you first started the installation, but muffed it when not correctly answering the "where do you want to boot from" question.

I'm writing this from an external drive that has been designated the boot drive in BIOS. Grub is written to the MBR of this drive, and boots 12-15 different Linux installations, on three hard drives; two external and one internal. I can unplug this drive and move it to any other computer capable of USB or eSATA booting, set it as the boot drive in BIOS, then reboot. On first boot, as different hardware is discovered, I am asked if I want it configured, to which I answer yes. From then on, as long as the drive is connected to the same machine, my Linux installations act as if they were originally installed on that hardware. When moved to another machine, the process repeats the "new" hardware discovery, and configuration, on the first boot of each installation, then runs as if each installation was originally done on that machine, from then on.

I don't currently have any Windows installations directly on the hardware, but do have Win2K VMs installed on VirtualBox. When I did have Windows on its own hard drive, I left it intact, and used grub from the Linux drives to boot Windows from the second, third, or fourth installed hard drive. If I removed all the Linux drives, then Windows would boot from its own boot code on that drive's MBR.

I have at least one Linux installation on each of my hard drives, and grub installed on each drives MBR, so, being self contained, I can designate any of my hard drives as the boot drive, should I remove any of the other drives, and move them to another machine. Grub is very flexible in this respect, while Windows boot code is very limited, as well as susceptible to Windows malware. I would never trust Windows to handle booting any Linux installation, while grub can handle booting Windows from any drive location with ease.
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline paul1149

  • Full Member
  • ***
  • Posts: 51
Re: Question about GRUB logic
« Reply #16 on: February 15, 2011, 02:05:11 PM »
Thank you, old-polack, that makes a lot of sense. That's what I did last year when I installed PCL, and it was good because if the external drive wasn't on when I booted, I defaulted to Win7; if it was, I defaulted to PCL. And actually, my attempt yesterday did go to the mbr of sdb, but for some reason nothing worked.

What you've outlined sounds like a very good scheme. It seems that grub picks up all other installs, so losing installs is not a problem. That was one of my concerns.

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11587
  • ----IOFLU----
Re: Question about GRUB logic
« Reply #17 on: February 15, 2011, 03:21:59 PM »
Thank you, old-polack, that makes a lot of sense. That's what I did last year when I installed PCL, and it was good because if the external drive wasn't on when I booted, I defaulted to Win7; if it was, I defaulted to PCL. And actually, my attempt yesterday did go to the mbr of sdb, but for some reason nothing worked.

What you've outlined sounds like a very good scheme. It seems that grub picks up all other installs, so losing installs is not a problem. That was one of my concerns.

To some degree grub will pick up other installations, but legacy grub won't pick up grub2 installations, as the files it looks for do not exist in grub2. Windows is another story, and will get a menu.lst boot stanza something like;

title Windows
rootnoveriry (hd1,0)
map (hd0) (hd1)
map (hd1) (hd0)
makeactive
chainloader +1


This will vary in detail, depending on which drive and partition Windows is actually on, but the pattern will not vary. Stanzas for new Linux installations can be copied from the new menu.lst to the master, or can be hand written, using the existing stanzas as a pattern. I use the menu.lst from the first installation as my master menu.lst, and install grub from all newer installations to the new / partition. From there, I can simply ignore it after copying the first new boot stanza to the master menu.lst, or write a chainloader stanza for that partition, such as;

title sda7 Linux
root (hd0,6)
chainloader +1


This works well if one changes the installations fairly often, as in when testing different distributions, in that it does not need to be changed for each new installation. That stanza will bring up whichever grub boot menu is currently present on that partition.
« Last Edit: February 15, 2011, 03:24:02 PM by old-polack »
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline paul1149

  • Full Member
  • ***
  • Posts: 51
Re: Question about GRUB logic
« Reply #18 on: February 15, 2011, 03:40:58 PM »
Thanks again, OP. In the case of the new install, including when using the generic chainloader command, I can install the grub menu to the new root, and only edit the "master" menu. This is the kind of insight I'm looking for. Do I forgo writing the bootloader again? Because a new bootloader would point to the new, rather than "master", menu, correct?

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11587
  • ----IOFLU----
Re: Question about GRUB logic
« Reply #19 on: February 15, 2011, 04:11:48 PM »
Thanks again, OP. In the case of the new install, including when using the generic chainloader command, I can install the grub menu to the new root, and only edit the "master" menu. This is the kind of insight I'm looking for. Do I forgo writing the bootloader again? Because a new bootloader would point to the new, rather than "master", menu, correct?

The new bootloader is installed to the new / partition's boot sector. This still gives you a usable boot stanza to copy to the master menu.lst, which is what I mostly do, or allows a chainloader option. The original bootloader remains in the MBR and does not need to be reinstalled. On the next boot, it will read the master menu.lst and display a boot entry for each stanza it finds there.

I once kept the same grub installation for 4 years, through dozens of new installations, and even survived the removal of the installation that installed it, because it was on a separate boot partition. Grub is both very flexible and resilient.  ;D
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline paul1149

  • Full Member
  • ***
  • Posts: 51
Re: Question about GRUB logic
« Reply #20 on: February 15, 2011, 04:41:23 PM »
Thanks again. That clears that up. Using a boot partition would solve the problem of abandoning the bootloader when wiping a drive. That's one reason I had gravitated toward using the Win7 BCD. Sounds like a good system.
bw,
p.

Offline The Chief

  • Hero Member
  • *****
  • Posts: 2250
Re: Question about GRUB logic
« Reply #21 on: February 15, 2011, 04:46:50 PM »
You seem to be correct about sdb. I chose it to boot, via the BIOS ad hoc boot menu, and first a line came up saying no grub file, but then the grub menu came up properly.

Now here's the problem, and I don't know where this came from.

You should be able to determine that by disconencting the external drive and rebooting.  It you see it again, it's on your internal drive, if not, it's on your external drive.

But, the way you appear to have it setup, there is no need for grub at all.  Just set the bios to boot from the external drive first, and it will if it's connected, but will boot from the internal drive if it isn't.

Retired Senior Chief, Retired Software Engineer, Active GrandPa

Offline paul1149

  • Full Member
  • ***
  • Posts: 51
Re: Question about GRUB logic
« Reply #22 on: February 16, 2011, 05:19:50 AM »
I did have the external drive set to priority in the boot order. But without grub out there, what would act as the bootloader?

Offline TerryN

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 723
Re: Question about GRUB logic
« Reply #23 on: February 16, 2011, 07:54:37 AM »
I seem to remember that changing the boot device in BIOS can lead to confusion.
This happens because the device that the BIOS reads the bootloader from gets reported to GRUB as (hd0) regardless of where it is on the bus.
So, for example, if you have IDE with a primary master and slave and you set the BIOS to boot from the slave, then GRUB sees the slave as (hd0) and the master as (hd1) which is the opposite of what you might expect.

Hope that makes sense  :)

Terry
« Last Edit: February 16, 2011, 08:48:17 AM by TerryN »
Dell E521 - AMD 64 X2 5000+, 4GB RAM, ATI X1300 graphics
PCLinuxOS 2013 (KDE)
|Twitter|

Offline paul1149

  • Full Member
  • ***
  • Posts: 51
Re: Question about GRUB logic
« Reply #24 on: February 16, 2011, 08:05:24 AM »
Wow, that is explosive. I already was concerned about how adding a usb stick to the mix might shift things off the map. I would call this a downside.

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11587
  • ----IOFLU----
Re: Question about GRUB logic
« Reply #25 on: February 16, 2011, 08:44:46 AM »
Wow, that is explosive. I already was concerned about how adding a usb stick to the mix might shift things off the map. I would call this a downside.

The boot drive is always (hd0) but that isn't a particular concern if the boot stanzas reflect that. That is the reason for the map entries in a Windows stanza, when Windows is on the second drive.

There's nothing explosive about this, it's a basic part of BIOS terminology, which grub properly takes note of and respects. Whichever device you boot from becomes (hd0) whenever you boot from it, including USB sticks, and other devices are then designated (hd1), (hd2), etc in relationship to whatever is currently (hd0). This applies to non optical drives only.
« Last Edit: February 16, 2011, 08:47:03 AM by old-polack »
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline paul1149

  • Full Member
  • ***
  • Posts: 51
Re: Question about GRUB logic
« Reply #26 on: February 16, 2011, 08:56:44 AM »
Then is there a problem if the boot priorities are changed, or if a usb stick is added, after the grub menu is composed?

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11587
  • ----IOFLU----
Re: Question about GRUB logic
« Reply #27 on: February 16, 2011, 09:21:39 AM »
Then is there a problem if the boot priorities are changed, or if a usb stick is added, after the grub menu is composed?

If grub is on (hd0) then all installations on that drive are referred to by (hd0,n) with n being the partition number, with counting starting at 0.

When you boot from a USB stick, it becomes (hd0) and the menu.lst from whatever is installed on it is used. Same for whichever hard drive is designated as the boot drive. Each drive with Linux installations can have it's own master grub and menu.lst, for when it's the only drive present, or the one designated as the boot drive. Problems only arise when one installs to one drive and puts grub in the MBR of a different drive. Obviously, one should not do this.
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...

Offline paul1149

  • Full Member
  • ***
  • Posts: 51
Re: Question about GRUB logic
« Reply #28 on: February 16, 2011, 09:32:19 AM »
Thanks, I appreciate your patience. That sounds like good sound policy. I think what I've got thus far is to place all sticks in the computer so that grub picks them up, and in their correct order, and then to keep each install indigenous to its own drive.

Offline Old-Polack

  • Administrator
  • Super Villain
  • *****
  • Posts: 11587
  • ----IOFLU----
Re: Question about GRUB logic
« Reply #29 on: February 16, 2011, 10:02:39 AM »
Thanks, I appreciate your patience. That sounds like good sound policy. I think what I've got thus far is to place all sticks in the computer so that grub picks them up, and in their correct order, and then to keep each install indigenous to its own drive.

Why would you want to do that? You can only boot to one USB stick at a time, and having more than one inserted at boot time will only confuse BIOS as to which is desired to be (hd0). If you have boot from USB before boot from hard drive, then all you need to do is insert the USB stick you want to boot to before turning the computer on, the rest is automatic.

When you create a bootable USB stick, you install grub to the MBR of that stick, so it's always an independent drive. Why are you trying to complicate a simple activity?
Old-Polack

Of what use be there for joy, if not for the sharing thereof?



Lest we forget...