PDA

View Full Version : The multi-OS, multi-boot GRUB guide (Windows included!)


Firewing1
2007-01-22, 08:54 PM CST
Hello,

GRUB, short for GRand Unified Bootloader, is one of the best boot loaders I have ever encountered. Not only can it handle many kernels at once, but many distro's kernels, too!
One of the best features of all is that GRUB can "chainload" - pass control to other bootloaders - so if one OS isn't supported by grub (*cough* Windows *cough* :D ), you can use GRUB to pass over control to NTLDR (the Windows bootloader) and Naitively boot Windows from there.

GRUB configuration file

The secret to all this is the GRUB configuration file. It's always located at /boot/grub/grub.conf, but for your convince a symbolic link of that file is located at /etc/grub.conf (less typing by a few characters... :rolleyes: )

To take a look at or edit or your configuration, simply type:
su -
gedit /etc/grub.conf
If you don't like gedit, replace it for your favorite editor

GRUB & drive naming schemes.
Something one must keep in mind when dealing with GRUB is that it's naming scheme for drives is different. When running grub-install, the command to install GRUB onto a drive, a device map is generated located in /boot/grub/device.map. This file maps the GRUB drive names to their respective /dev paths in a format like this:
(hd#) /dev/hdx
the "#" starts at 0 and moves up by 1 for each drive added.

So for example if I had two hardrives, one IDE and one SATA their paths would be /dev/hda and /dev/sda respectively. So my file should look like:
(hd0) /dev/hda
(hd1) /dev/sda

Once the map is set up correctly, using (hd0) in GRUB is just like accessing the /dev node specified in the map file. To access individual partitions, add a comma followed by the partition number after the hard drive number:
(hd0,0)
Again, partition numbers start at 0. So using the same situation, (hd0,1) is like /dev/hda1 while (hd1,5) is like /dev/sda6.

Note that (hd#) entries don't actually have to be "real" hard drives - One could map /dev/fd0, the floppy node, to (hd2) for example or a CDROM to (hd3).

To edit the device map, run:
su -
gedit /boot/grub/device.map
Once you've done editing, you must commit changes to the map by re-installing GRUB
This will not erase your grub.conf
grub-install /dev/hdx
Where /dev/hdx is your root drive.

GRUB commands

root : Set the root to selected partition or disk.
Usually used in a format like this:root (hd#,#)
Note that plain (hd#) can be used to root into a whole disk - Useful for chainloading a MBR.
rootnoverify : Same as root but don't try to verify the partition. Useful for root'ing into NTFS drives to chainload them.
title : Start a menu title. Commands under it will be executed when selecting it from the GRUB menu at boot time. A name should specified after the title command.
Usually used in a format like this:title My Name Here
kernel : Use the provided kernel image (vmlinuz*) to boot. Any other arguments are passed to the kernel.
Usually used in a format like this:
kernel /vmlinuz-[version] root=/dev/hdx# option1 option2
One must set root= to their root path, or use LABEL=[root-partition-label].
initrd : Use the provided ramdisk image (initrd*.img)
Usually used in a format like this:
initrd /initrd-[version].img
chainloader +1 : This command will take the boot sector of the root and use it to boot. If the root in a whole disk, then it will load the MBR.


Examples
If /dev/hda1 is my Windows partition, and I've mapped /dev/hda to (hd0) in my device map like this:
(hd0) /dev/hda
This would pass control to NTLDR letting me boot Windows XP:
title Windows XP
rootnoverify(hd0,0)
chainloader +1

Use the same idea if you want to chainload to the MBR of a slave disk (assuming the slave is mapped to (hd1):
title Slave Disk
rootnoverify(hd1)
chainloader +1

Booting a custom kernel where the root partition's label is "/", passing 'quiet' and 'rhgb' as boot arguments:
title Fedora Core (2.6.19.2-custom)
root (hd0,0)
kernel /boot/vmlinuz-2.6.19.2 ro root=LABEL=/ rhgb quiet
initrd /boot/initrd-2.6.19.2.img

I know it's a little complicated for now, I will elaborate later :)

Firewing1

Firewing1
2007-01-22, 08:57 PM CST
Like always, this will more than likely grow to over 10,000 characters. So, second post is reserved for later editing :)
Firewing1

earlyspider
2007-01-22, 09:18 PM CST
Hi Firewing1,

Just started a similar thread in General Support, and was pointed in your direction.

Being fairly new to linux, i am still in the stages of needing to be in windows, but have setup my workplace laptop to dual boot to FC6 and Windows XP.

I want to be able to restart Windows and boot to FC6, but grub menu has Windows selected as the default OS.

I work from home 3 days a week and connect to my laptop using vpn and remote desktop. I want to be able to restart windows but choose FC6 as the OS.

Looked around for various windows 'restart' software, but none that quite do what i want.

I know how to change the boot order when in FC6, but dont want to set FC6 as default OS.

Can anyone help?

cheers
Earlyspider

mwette
2007-01-22, 11:03 PM CST
Can you explain the chainloader more? If my WinXP directive says
rootnoverify (hd0,0)
chainloader +1
where is the next stage to be executed to be stored? Is this in the
MBR + "DOS-compat" region (first cylinder) or in the first partition?

That is, does installation of GRUB move the original MBR to the second
sector of the first cylinder or something else?

Firewing1
2007-01-23, 02:47 PM CST
Hi Firewing1,

Just started a similar thread in General Support, and was pointed in your direction.

Being fairly new to linux, i am still in the stages of needing to be in windows, but have setup my workplace laptop to dual boot to FC6 and Windows XP.

I want to be able to restart Windows and boot to FC6, but grub menu has Windows selected as the default OS.

I work from home 3 days a week and connect to my laptop using vpn and remote desktop. I want to be able to restart windows but choose FC6 as the OS.

Looked around for various windows 'restart' software, but none that quite do what i want.

I know how to change the boot order when in FC6, but dont want to set FC6 as default OS.

Can anyone help?

cheers
Earlyspider
In your config file, there's a 'default' command. default=0 means the default boot is the first Title entry, default=1 is the second, etc... Just change that to the most recent Fedora title.

As for chainloader, it doesn't move your GRUB installation but just reads the boot sector or MBR of the root partition and boots that instead. That's why we chainload when the root is (hd0,0) - It effectively tells GRUB to take a look at the boot sector of the NTFS partition, ignoring that it can't read any actual contents of the NTFS partition. The boot sector has NTLDR, so GRUB passes control over to it and not NTLDR has control of the boot process.
Firewing1

mwette
2007-01-23, 04:20 PM CST
As for chainloader, it doesn't move your GRUB installation but just reads the boot sector or MBR of the root partition and boots that instead. That's why we chainload when the root is (hd0,0) - It effectively tells GRUB to take a look at the boot sector of the NTFS partition, ignoring that it can't read any actual contents of the NTFS partition. The boot sector has NTLDR, so GRUB passes control over to it and not NTLDR has control of the boot process.
Firewing1
Where is the partition specified? What if I have two WinXP installations on the disk?

Muneco
2007-02-10, 01:19 AM CST
Hi to All
First of all, thank you very much Firewing1, for taking the time to explain the process of mapping, setting up the config file and re-installing Grub to find the changes :) . I have read the forums for the last two months and I am extremely confused. :( Here's why...

I am fairly new to Fedora Linux Core 6 (I Love it) :) The complete install works perfect.
I am however, stuck :confused: because I don't know how to put together the code I need to multi-boot my personal configuration.

Please allow me to explain my systems hard drives (3 of them) and how I have them connected. Then allow me to explain how I prefer them to show up in the Grub boot loader.

Before I get to the drives, I have two Grub loaders installed. The first grub v1.5 was installed when I installed Suse 10.0 onto my existing Windows 2000 Professional Drive. (NTFS) file system. The second Grub v2.0 was installed when I installed Fedora Core 6 onto Drive number 3. (Which is a Stand alone Drive.) Grub 1.5 recognized the windows 2000 partion right away and also my 2nd Drive (windows data ) but not my Fedora Drive (drive #3). I want to be able to go to one boot screen and be able to select any one of the three Operating Systems.

So, I have 3 IDE Hard Drives :)
Primary Master, first partition: is Windows 2000 Professional.
I assume this will be (hd0,0) /dev/hda
Primary Master, second partition: is Suse 10.0
I assume this will be (hd0,1) /dev/hda
Secondary Master, Only 1 Partition: is My Windows Data (NTFS)
I assume this will be (hd1) /dev/hda
Lastly, Secondary Slave is: Fedora Core 6
I assume this will be (hd2) /dev/hda.

Can you please help me code this.. I am confused. :confused: Must I install Grub onto the MBR of my first drive where windows 2000 is residing, (hd0,0)? After I do this, How do I get my Suse 10 to be recognized?

Do I need to edit two files? One for the mapping, and one for the config after I install Grub to the MBR? or will that be sufficient.

I am trying to get a grip on the chainloader statement. (Do I need it, Where does this belong?)

You can't Imagine how much I appreciate everyone's help in getting me resolved on this... :) I also hope anyone else going through this with me will be helped by this request...

Thanks so much for your help..

slade17
2007-02-10, 01:52 PM CST
Firewing1,

i think you have a typo in your first post.

(hd0) /dev/hda
(hd1) /dev/hda

should be

(hd0) /dev/hda
(hd1) /dev/sda

mwette
2007-02-10, 03:12 PM CST
Can you show your grub.conf (menu.lst) files? I think you should be able to
copy a line from your grub.conf file to the menu.lst file, provided the disk numbering
is consistent.

ercanardal
2007-02-11, 03:42 PM CST
Hi,
I have just installed FC6 on my single hard drive in a seperate partion. Other main partion has Windows XP. I have NOT installed GRUB on Mbr. Instead used the boot area of FC6 install.
(This is my first Linux install = newbie)

I am planning to boot FC6 from rescue CD manually. (Since a boot diskette is not possible) Becasue I dont want to trouble my MBR. I tried the following,
Boot with Rescue CD. Go to the prompt.
then run GRUB.
At this point HOW can I boot FC6?

Or, is there any other method to boot FC6 installed at the hard drive, manually. ??

Tnx, ahead.

ercanardal
2007-02-11, 04:52 PM CST
I have loaded the Grub.conf file at grub prompt with;
configfile /grub/grub.conf
It worked and displayed the boot menu, where can i choose 2 os to boot from.
When I choose Fedora boot stops at initrd command giving,
Error16: Inconsistent filesystem structure...
and booting stops..

Please help. I am totally lost at this stage.

HalJordan
2007-02-19, 11:01 AM CST
Hi ALL,
I am a complete N00B at Linux/using GRUB. I know what each is, and somewhat how they work, I just don't know how to get them to do what I want.

I have 2 Drives
SATA Windows 1 partitioin
IDE FC6 1 partition

I am still trying to ween myself off of Windows, but there are still a few things in the aspect of games that are keeping me tied down, so I want Windows to be the first boot. How do I do this?

Please spare no expense, be as descriptive and specific as you possibly can, I can BARELY use the terminal, and thats only from a long lost memory of DOS :confused:

All help is and will be greatly appreciated
Thank you guys so much!

slade17
2007-02-19, 12:21 PM CST
Hi ALL,
I am a complete N00B at Linux/using GRUB. I know what each is, and somewhat how they work, I just don't know how to get them to do what I want.

I have 2 Drives
SATA Windows 1 partitioin
IDE FC6 1 partition

I am still trying to ween myself off of Windows, but there are still a few things in the aspect of games that are keeping me tied down, so I want Windows to be the first boot. How do I do this?

Please spare no expense, be as descriptive and specific as you possibly can, I can BARELY use the terminal, and thats only from a long lost memory of DOS :confused:

All help is and will be greatly appreciated
Thank you guys so much!
so to clarify, you have two hard drives, one is a SATA drive with Windows, and the other is an IDE drive with fedora?

first you need to set up your bios so it boots from the fedora IDE drive, if it isnt already doing that. you may need to edit the bios. then, you need to edit the file /etc/grub.conf. you need to be root to edit the file. the easiest way to do so is open a terminal, and type in:

su -
#enter your password
gedit /etc/grub.conf

you should see a number of commented lines, default and timeout lines, and then one or two lines that will boot fedora, such as:

title Fedora Core (2.6.19-1.2895.fc6)
root (hd0,0)
kernel /boot/vmlinuz-2.6.19-1.2895.fc6 ro root=/dev/sda1 rhgb quiet
initrd /boot/initrd-2.6.19-1.2895.fc6.img

if grub cannot currently boot windows, you need to add the following lines to the bottom of the file:

title Windows
map (hd0) (hd1)
map (hd1) (hd0)
rootnoverify (hd1,1)
chainloader +1
makeactive
boot

you should edit the file default=n, and change n to whichever operating system you want to boot first. n=0 is the first operating system, n=1 is the second, etc.
you can also edit the timeout line, which will specify how long grub will wait for you to select an operating system before booting into the default.

HalJordan
2007-02-19, 12:47 PM CST
Ok, so all I have to do is edit the file and save it. I don't have to run any other special commands?

HalJordan
2007-02-19, 12:57 PM CST
Sorry, I tried both ways
the default that showed up before you posted that thread hangs up when it displays the
rootnoverify ...
chainloader 1+

and then your way threw an error

give me what specific system specs you need, with my history there's something I need to tell you guys that I don't know about, its something small, insignificant, and stupid, but its the only thing holding me back and it does a wonderful job at that

I know my way around the hardware, and I know how Linux works, I just need more practice at getting what i want out of it

slade17
2007-02-19, 01:51 PM CST
Sorry, I tried both ways
the default that showed up before you posted that thread hangs up when it displays the
rootnoverify ...
chainloader 1+

and then your way threw an error

give me what specific system specs you need, with my history there's something I need to tell you guys that I don't know about, its something small, insignificant, and stupid, but its the only thing holding me back and it does a wonderful job at that

I know my way around the hardware, and I know how Linux works, I just need more practice at getting what i want out of it
is the master boot record on the windows drive unmodified? e.g. if you remove your fedora hard drive and boot from the windows hard drive, will it boot successfully?

look here for further information: http://www.gnu.org/software/grub/manual/grub.html

in the code i gave you, the map lines makes windows think that its drive is the primary drive, which is what it seems you need to do. grub will then chainload windows, meaning it "passes" loading the operating system to the windows boot loader. grub cannot boot windows directly, so if you did delete the windows boot loader, you should remove the fedora hard drive, and reinstall the windows boot loader. then put the fedora drive back, and boot up the system.

HalJordan
2007-02-19, 02:09 PM CST
I didn't mess with the windows ntldr, it is intact and unmodified

Windows boots fine as long as i choose to boot to that drive, but I want to be able to choose b/w FC6 and XP without using the bios

slade17
2007-02-19, 02:23 PM CST
I didn't mess with the windows ntldr, it is intact and unmodified

Windows boots fine as long as i choose to boot to that drive, but I want to be able to choose b/w FC6 and XP without using the bios
then what i posted should work.

the only thing i can think of is that there could be a problem with the fact that youre mixing a sata drive and an ide drive. but i dont know what you could do about that, besides just look through the grub manual i linked to.

Firewing1
2007-02-19, 03:51 PM CST
Recently kernel changes made /dev/hda become /dev/sda -- Maybe you have to remap your partitions.
Firewing1

slade17
2007-02-19, 04:55 PM CST
Recently kernel changes made /dev/hda become /dev/sda -- Maybe you have to remap your partitions.
Firewing1
hmm, im using sata drives and i havent changed the code for booting windows since i first set the computer up. and right now im (unfortunately) on windows.

HalJordan
2007-02-19, 06:01 PM CST
I have done all the updating possible, I have installed anything grub related i could find, and have installed all drivers(ALL this is from yum), Is there a command that would completely restore my grub.conf to its original automatically generated defaults? like
grub-reset

--or--

grub-default

Firewing1
2007-02-19, 07:18 PM CST
Hmm... Just realized, try replacing your existing 'rootnoverify' command for your Windows with this:
rootnoverify (hd1,0)
If that doesn't work, then
rootnoverify (hd1)
Firewing1

slade17
2007-02-19, 08:03 PM CST
nice catch firewing, sorry HalJordan.

my drive was preinstalled with windows, so theres a hidden partition with the install media. my windows OS is on the second partition, yours is probably on the first. firewing's first line of code should work.

HalJordan
2007-02-20, 08:48 AM CST
I appreciate all the help, I'm at work now, I'll let you know as soon as I try whether or not it works.

Firewing1
2007-02-20, 09:24 PM CST
How did it go?
Firewing1

HalJordan
2007-02-20, 09:32 PM CST
I just got out of class, I literaly just clicked save, I'll post as soon as I'm back whether or not it worked.

HalJordan
2007-02-20, 09:58 PM CST
Sorry guys, no dice, I've tried it all around. Is there anywhere else I could go, or anyone else I could turn to that might know what obscure thing is preventing it from happening?