Life with Linux

January 30, 2006

Where should you install GRUB?

When you are installing Linux, regardless of which distribution you choose, one question is always the same. How do you boot your system?

You’ll invariably be presented with two options for installing GRUB, the Grand Unified Bootloader. This is the tiny piece of software responsible for starting up your computer and getting Linux — or Windows, if you dual-boot — loaded into memory. Because the PC architecture has undergone dramatic changes in the last 25 years, the boot process has become more complicated, and requires a small piece of software to handle getting your chosen operating system loaded into memory.

With Windows XP, this piece of software is called NTLDR. On Linux, it’s called GRUB. (There was also another bootloader called LILO, but it’s been obsolete for years and is not recommended for new installations, even if your distribution gives you the option.) Both of them do the same thing: they get the operating system loaded into memory, and optionally, present you a menu with different choices on how you would like to boot your system.

As I mentioned, there are two options for installing GRUB. First, you can install it to the Master Boot Record of your first hard drive. Second, you can install it to the boot sector of the active (bootable) hard drive partition. Which one is the right one? It depends.

If you intend to dual-boot Windows, then you should avoid installing GRUB to the MBR. The reason for this is that Windows occasionally overwrites the MBR, for instance, when you reinstall it, and that could be quite often. When that happens, your Linux system will seem to disappear as your system starts booting directly into Windows, bypassing the boot menu altogether. To avoid this, install GRUB to the boot sector of the active partition instead.

There’s an exception to that rule: If you are installing Linux to a secondary hard drive, and no part of it will be on your main hard drive, then you must install GRUB to the MBR, and take your chances with Windows overwriting the MBR with its own at some future date. If this happens, you’ll have to use a Linux rescue CD to get GRUB reinstalled. (I’ll cover this procedure in the future.)

If, however, Linux will be the only operating system on your computer, it’s perfectly safe to — and you must — install GRUB to the MBR.

Some special circumstance notes: If you run OS/2, you MUST NOT install GRUB to the MBR under any circumstances, or you won’t be able to boot OS/2! You will have to install it to the boot sector of the Linux /boot partition on your primary (first) hard drive. If you don’t have any free unpartitioned space on your first hard drive, you will have to use a resizing tool such as Partition Magic to create some space and have your Linux installation create the Linux /boot partition in that space. The space must be within the first 1024 cylinders of the hard drive. And it will have to be a primary partition as well, not a logical partition. Many computers can’t boot from logical partitions, only primary ones. The root (/) partition can be elsewhere, even on a secondary hard drive. You’ll then need to add the /boot partition to OS/2’s Boot Manager menu once you’ve completed the Linux installation.

If you have multiple Windows versions on your computer, and use a Windows boot menu to access them, you can add Linux to the Windows boot menu, but the process for this is somewhat complex, and I don’t intend to cover it here. Install GRUB to the boot sector instead, creating a /boot partition on the primary hard drive if necessary (see the OS/2 note above).

As you’ve probably gathered, the simple everyday act of booting up your PC is much more complex than you thought it was. This has a lot to do with the way your computer’s BIOS accesses internal hard drives. The BIOS is the very first bit of software which starts when you turn on your computer, and it’s located on a physical ROM chip inside the machine.

Twenty years ago, hard drives of 5 to 20 MB were common, and many PCs even shipped without a hard drive! Even as late as ten years ago, most computer BIOS software could not access more than the first 528 MB of a hard drive, creating booting problems. Eventually a solution called LBA (logical block addressing) raised this limit, first to 8 GB, and in more recent computers, to 137 GB. This is the range that the so-called first 1024 cylinders can access through the BIOS, before your operating system loads (using GRUB, NTLDR, or what have you). As hard drives exceed 137 GB now, and computers with 1TB of hard drive space are just now becoming available to consumers, the 20 year old BIOS design will again make trouble for the seemingly simple task of starting your computer.

Filed under: Distributions, GRUB, Linux, Software — Michael Hampton @ 7:13 am

10 Comments »

  1. Let me update this by saying that some computers these days are shipping with special master boot records that do oddball things and don’t obey the bootable partition flag. The Gateway I just purchased is a good example.

    If you run into one of these, you’ll know it because if you installed GRUB to the bootable partition, instead of the master boot record, Linux won’t start; it’ll continue booting into Windows as if you hadn’t installed anything.

    The only way around this is to install GRUB to the master boot record. If you do this, though, you’ll lose the ability to start the system restore partition by pressing that special key. You can, however, add the system restore partition to your GRUB boot menu if you wish.

    Comment by Michael Hampton — March 10, 2006 @ 1:01 am

  2. Nice article. However this isn’t true about OS/2 and GRUB. Actually you can boot OS/2 from GRUB without problems. The bad thing is that LVM.EXE (partition manager in OS/2) will always overwrite MBR if it will contain unknown code.

    Comment by Well ... — June 14, 2006 @ 7:39 am

  3. It’s great to read to what had happenned some 5/10 years ago and what size of hard disk sizes were there!

    Where are the actual steps of installing grub!

    It would have been great if the author has given a step by step install instructions how to re/install GRUB.

    Comment by Ram — October 25, 2006 @ 11:21 pm

  4. How to install GRUB has been covered well elsewhere, including in its own manual; it’s pretty simple. The point here was to try to answer the question of where to install it.

    Comment by Michael Hampton — October 26, 2006 @ 2:09 am

  5. “If you are installing Linux to a secondary hard drive, and no part of it will be on your main hard drive, then you must install GRUB to the MBR”

    Not true at all! I have the Windows bootloader on my first hard drive and Linux on my third (physical!) drive.Just follow the steps on described in “How-To”s for using the NTLDR to jump into GRUB.(Installing GRUB on the boot partition) BUT you cannot use the grub-install script, you have to go into the grub “shell” and specify on which (physical) harddrive GRUB stage 2 is. First harddrive is apparently assumed otherwise.

    Comment by Jon Wickström — January 24, 2007 @ 6:11 pm

  6. Definitely would have been helpful to include commands to install Grub to partition only rather than overwrite MBR. I already know that’s what I need to do so that rEFIt Windows icon will work (without going through grub). But I have been scouring the web for the last 20 hours trying to find the commands to do so! Grub man pages and other how-tos (that you alluded to) are completely useless for this objective, as is trial and error at the grub prompt. Nobody–and I mean NOBODY–explains how to make Grub install only to the partition, at least after it has already overwritten the MBR. I appreciate the time and effort you went in to writing this, but without the actual commands (or at least a link to them), you’ve only succeeded in wasting my time. This is constructive criticism (that you can act on), not a flame, because you were generous enough to do this for free (or without payment from me at least).

    Comment by Jim — September 25, 2007 @ 11:25 am

  7. I believe what Jim is looking for is “howto configure grub”

    Comment by Love Music — February 3, 2008 @ 12:40 am

  8. Wow, I really like LILO (much better than GRUB), but I didn’t know it was obsolete. GRUB is just too GNU-ish: functional but cryptic and scary. But both tools remind me of Disney movies–Lilo & Stich and The Lion King–as sad as that might be.

    Comment by Keith Bowes — March 30, 2008 @ 6:05 pm

  9. Vista is a domineering monster, Xp is slightly better.

    You need to develop a Vsta accountable GRUB multi-boot.

    I am looking at the Open src code for this and it indicates

    a total isolation of the linux partition designed to fool the

    windows installation. A pre-cognitive Vista Bootloader.

    !OR! Make the linux or Unx boot a Vista Slave(2). So far,

    #2 is just not an option to date.

    Comment by haal12 — January 29, 2009 @ 10:37 pm

  10. grub4dos is a much better bootloader incase you wish to dual boot windows and linux.

    Comment by nikhil — July 24, 2009 @ 12:56 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

Bad Behavior has blocked 121 access attempts in the last 7 days.