SDB:All about GRUB

Jump to: navigation, search
This article or section refers to the version OpenSUSE 11.1 and it is now obsolete!
Please refer to this article's discussion page for more information.
This article was transferred from the old wiki and contains old information: All About Grub.

Managing Grub installations

If you need help with GRUB or Multi-Booting with Windows then read on. This is a long article, but be patient with this difficult subject. Take your time and read through it carefully. In here you can learn how to manage/repair a computer that uses Grub to boot Linux and Windows. Even if all appears lost and your computer doesn't boot – The probability is it's actually easily repaired.

If you have a Windows PC or Laptop and want to install openSUSE the first thing you should do is Backup anything you can't afford to loose. Then defragment your (C:\) drive. Scared? You should be. Microsoft make it pretty tricky for you to use other Operating Systems (OS). The pictures used in this tutorial are from a Virtual Machine and so the partitions are relatively small compared to what you would expect. But they serve to illustrate quite clearly how HD's are partitioned and how they can be manipulated. Some features of this tutorial include:

  • Viewing and managing partitions with Parted Magic
  • Installing Windows XP
  • Installing Windows 7
  • Installing openSUSE 11.1
  • Switching Boot Flags with Parted Magic
  • Repairing the Windows Boot Code
  • Repairing Grub with a Live CD

Understand your HD

Here is a picture showing a typical Windows HD (Yours may be different)


Occasionally your Windows PC will have 2 partitions, particularly OEM PC's. If you own a Windows install cd/dvd then 1 partition is usual. In this complete tutorial/guide you will see XP as a 2 partition setup and Win7 as a single. (Ignore the size of the partitions, the examples here are from a Virtual Machine for illustration only. In reality your partitions will be much bigger).



Notice the Boot Flag] is the same as the previous picture with just 1 important difference – The boot flag. Once windows is installed that flag will be present. Keep a mental note of that as it is important. Notice how Linux identifies partitions. In this case hda, or more likely sda. Partitions basically divide your Hard Drive in to sections (It's almost like you now have lots of Hard Drives, just smaller. This is a little over simplified but it's enough information for the layman.) Both partitions seen here are Primary, you can have a maximum of 4 Primary partitions on any one drive. Later we'll discuss how, with the use of an extended partition (which is itself a Primary Partition) you can have more than 4 partitions, they just won't all be Primary.

This: Windows_My_Computer is how Windows sees your Partitions. Even though Recovery D: is before XP Local Disk C: in the partition table. If you are a Windows user, stop thinking the Windows way about your Partitions. It is completely illogical and will confuse you in the installation process of Linux.

HD's are seen as sd or hd, e.g. sda1 or sdb1 or hda1

Take sda1: That's how it's seen from the desktop. But to Grub it is (hd0). (hd0,0) = the first partition of the first drive in the partition table.

The computer refers to the second partition of e.g. sda as sda2, But to Grub = (hd0,1)

Installing openSUSE 11.1

Let us say then, that we are now preparing to install a Linux distribution and want grub to manage booting of both Linux and Windows. Given the above and if you allow an installation to proceed as I have done in the following picture (openSUSE 11.1), Linux will typically offer the following proposal: NOTE: Parted Magic refers to the partitions as hda, but openSUSE as sda. Just remember in this tutorial e.g. sda1 and hda1 are one and the same.


If you are an experienced user ignore for a moment any feature of this proposal that you dislike or see as incorrect.

Notice in the section of the proposal 'Booting'. Grub is being placed in hda3 (The extended Partition).


This is good because it leaves the Windows boot code intact. However, in a moment you will see that the boot flag we mentioned earlier will be moved from hda2 and be on hda3. Sometimes though the installer doesn't get it quite right. In this test case I ran whilst writing this tutorial, the installer did get grub installed correctly in hda3 and also successfully included a Windows option in the boot menu. Here is a picture of the partitions after openSUSE completed installation. Notice the 'Boot' flag we mentioned earlier is now on hda3.


All the space of hda3 and the logical partitions it contains is achieved by shrinking hda2. Yes an extended partition is really just a container for logical partitions which is what hda5 and hda6 are. Logical partitions permit the use of many partitions above and beyond the 4 Primary limit. It's worth mentioning again that BEFORE any installation of Linux takes place, you should de-fragment Windows.

A corresponding picture from Windows shows things a little differently with the boot flag on hda2.


(Windows is not exactly correct is it.)

More about Grub installation - advanced users

This section also provides guidance that might be useful if grub does not boot properly.

We have already explained that in this example Grub had been placed in hda3 and the installer switched the boot flag over from hda2 to hda3. Which means, when the computer boots the first part it looks to is hda3 and as a consequence the Grub menu appears. Now, just to illustrate the advantage of Grub being installed this way, let me explain: Just for experiments sake – Or if you need to repair Grub: If you were to boot Parted Magic and change the boot flag back to hda2, when you reboot the machine Windows will boot, there will be no Grub Menu. Linux is still installed of course and you will be able to see the partitions in the Computer Management section of Windows. Switch the flag back to hda3 and either Grub Menu appears as before with the option to boot openSUSE or Windows. Or you need to repair grub like this:

If you have a Linux Live CD, boot from it and log in. Then open a console window and enter su and you will be at the command prompt with root powers and ready to proceed. If on the other hand you have the openSUSE install DVD, boot from it and on the first menu of options select the Rescue System option. That will start an elementary Linux Live operating system and bring you to the login prompt. Enter the username root and you will be at the command prompt with root powers and ready to proceed. Whichever way you started (the openSUSE install DVD or a Linux Live CD) when you are at the root command prompt, first you find the partition containing openSUSE's bootloader. Then you reinstall Grub with a pointer to that partition. First find the openSUSE installation:

You enter this ---------------- grub

Computer returns like this ---- grub>

You enter this ---------------- find /boot/grub/menu.lst

Computer returns like this ---- (hd0,5)

Here, (hd0,5) is Grub's pointer to my openSUSE installation. Your pointer will be different from my example (hd0,5). Substitute your values for my example (hd0,5). Now that you have the pointer, proceed like this:

You enter this ---------------- root (hd0,5)

Computer returns like this ---- Filesystem type is ext2fs, partition type 0x83

You enter this ---------------- setup (hd0)

You see several lines like this --- Checking if /boot/grub/stage1 exists ... yes Computer finally returns this-- Succeeded.......Done

You enter this ---------------- quit

You enter this ---------------- reboot

The computer should reboot and present you with the Grub boot menu, from which you can boot into openSUSE or Windows. pic8f.png

Multiple HD's and Grub

This scenario is most likely on a Desktop PC/Linux Box where it's not uncommon to have 2 or even 3 internal HD's. In fact there couldn't really be a more ideal set of circumstances than this, as it permits you the ability to dedicate the MBR of one of the drives to Grub. We have already touched on some slightly complex issues with Grub and we don't want to over complicate it here if we can help it. Writing about Grub is never simple because much more is involved: (Partitioning, Installation, Other Operating Systems.....). If you have 2 HD's and you intend to use a Windows OS, try and dedicate one of the drives to Windows or at the very least let Windows have the first part of the HD. Windows will install it's boot code to the MBR of that HD. Or if you have a Windows PC to which you add a new HD it's probably best to just leave the original HD alone and install everything else to the new HD/HD's. The key to this is in your BIOS. You need to adjust the BIOS so that the New HD is the first HD to boot. Install Linux, but in this case I would always recommend a customized installation, not taking any defaults, but manually partitioning the new HD, setting the mount points to your Windows drive and install Grub to the MBR of the new HD. It's possible the Linux installer will get the chainloader code wrong when it writes the menu for Windows in Grub. But don't panic, Windows is still bootable if necessary, by changing the BIOS settings to put the Windows HD back to first in boot order. But we don't want it this way, we want to use Grub, so we need to tweak the menu.lst file located usually at /boot/grub/menu.lst If there are 2 HD's it may need to something like this:

title WIN XP/Vista/7
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd1,0)
chainloader +1


title WIN XP/Vista/7
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd1,0)
chainloader (hd1,0)+1

The map function is used when the windows install was originally on a drive 1 and now it's been moved physivally to drive 2. Or an extra sata drive was added and drive 1 became drive 2 -- whatever. So in some cases and original drive 1 has a boot.ini for windows xp on it like this:

[boot loader]
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOW S
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

Now here's the reason why you need the map function. The fragment "rdisk(0)partition(1)" means partition 1 of disk 0 But a change has been made since then so it's now really partition 1 of disk 1. So you use the map function to trick the operating system into seeing the physical drive 1 as a fictitious drive 0. And only then xp will boot.

So that's why you need the map function with 98/2000/xp, because of the fragment like rdisk(x)partition(y).

Now here's the rub. Vista uses a different bootloader which doesn't contain the fragment rdisk(x)partiton(y). So it neither uses nor needs a map function. It ignores it. It boots -- it works fine without it because the change of location doesn't matter to the new loader in vista.

If you really want to verify which is the bootloader partition, then find the partition that contains the bootloader files: In Windows 2000/XP they are ntldr, and boot.ini. Vista's visible bootloader files are bootmgr and the directory boot. The map function is not required in Vista or Windows 7.

title Vista
rootnoverify (hd1,0)
chainloader (hd1,0)+1


title Vista
rootnoverify (hd1,0)
chainloader +1

Further detailed information can be found by typing: info grub in a konsole terminal. Or visiting:

You may also be interested in:


More on Windows Vista and Windows 7

Certainly with Vista I know that if you write grub to the MBR, Vista will not install Service Packs. I'm not certain but even if the MBR is untouched and it's just the boot flag that is missing from the Vista partition, Vista may not install Service Packs. If you repair the Windows boot sector with the Windows CD/DVD or if grub isn't on the MBR, just switch the boot flag back in favour of Windows, then you should be able to install Service Packs. If you are missing a Windows Vista DVD Vista Repair DVD Once done, you can re-install Grub as explained earlier. Windows 7 seems to be following the traits of Vista in multi-boot environments. It had the bootmgr file. But I have been unable to test Service Pack installation in Windows 7.

I ran a test case install of Windows 7 and then let openSUSE installer do it's stuff. As I expected openSUSE managed it perfectly. It shrank Windows, created an extended partition from the acquired space and created 3 partitions inside the extended space. Here are a sequence of screens:


In preparing this tutorial I have actually tried and tested all these steps. Personally I always setup my partitioning manually and use the MBR for Grub. But this guide focuses on what the installer will do if you let it do it's thing! Consistently, users report issues as a result of a default install. I have tried to be a complete 'Numpty' and get the whole install 'Borked' – But, honestly, SUSE is very good at getting it right.

Credits: @swerdna (snippets included from his tutorials)

Supplemental information for advanced users

You may or may not be aware that it is possible to install Windows (XP, Vista, 7) in a Logical Partition. But you must have a suitable primary partition where Windows can place it's boot code. The following is a copy of a test case I ran for one of the other moderators:

I started by creating the partitions with Parted Magic.
500MB NTFS Primary
19.7GB Extended

  • 500MB swap
  • 5.8GB root ext3
  • 1.2B /home ext3
  • 12GB NTFS for Windows 7

I then used a WIN XP disc to format the prepared Windows 7 partition to NTFS again. (This might not be necessary, but in previous tests I have found Windows, whilst it will see the NTFS partitions created by Parted Magic, there is something it does not like and so refused to install).

Then booting Windows 7 I get to the point where it reads and lists the partitions. You will notice it's rather inadequate presentation: 1initiallpartitionsasse.png

The install proceeded and completed eventually arriving at the W7 Desktop.

Next I boot Parted Magic see:


Windows 7 is installed and the boot flag is on hda1 just as expected. I mounted hda1, open it in a file browser and see this W7 Bootcode:


Now I boot openSUSE 11.1 DVD and manage the partitions manually as seen in this picture:


I set a mount point for Windows 7. The reason for the manual setup: the openSUSE installer made a Pigs Ear of the proposal so I went manual. The final proposal, including the 'Booting' info is in this Picture:


Notice that grub is shown in the proposal as going to hda2 (the extended partition) – I accept this and allow the install. The install and final config completes and we arrive at the openSUSE Desktop.

Post SUSE Install Parted View:


Reboot and from the unaltered menu which the openSUSE installer put in /boot/grub/menu.lst I select Windows and it works. The entry in menu.lst is:
rootnoverify (hd0,0)
chainloader +1

OK. So I'm thinking, what if grub were to MBR. So I manually do this, include a Windows entry in the menu the same as above. Reboot openSUSE is fine – Windows 7 is fine.

The conclusion then, is much the same as @swerdna (John) and I were finding with the tests we ran on XP. You can install Windows 7 in a logical partition – but you do need a suitable partition for Windows to place it's boot code. Windows 7 and Vista appear to be very similar in the way they install and manage booting, I can't be certain they are identical. I'm also not certain of one other aspect: When the MBR is not disturbed and grub is solely to the extended, whether Windows 7/Vista will allow service pack installs. But my suspicion is No. Because the boot flag is to extended. The way Windows now manages Service Pack installs it expects to find the boot flag on the Windows boot partition. An error occurs during the inevitable reboots that take place, which of course hands booting back to grub and whilst grub then loads Windows and the Service Pack resumes it errors out. In my tests I had no trouble restoring the MBR and Windows Boot Code, re-installing grub and changing boot flags. You can pretty much do what you like. My only concern is that this is all a little too complex for your average user. I have not pursued alternative booting methods that would better satisfy Windows limitations.