LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Blogs > saikee
User Name
Password

Notices


Rate this Entry

Using Windows MBR to boot Linux ( or BSD or Solaris)

Posted 01-12-2006 at 08:13 AM by saikee

One line summary – Put Grub in a data-only Fat primary partition and switch on its booting flag. Windows MBR will faithfully load Grub into memory. Grub can then boot all systems installed in the PC

(A) Introduction

Windows MBR does not have a target to boot. It only searches from the 4 primary partitions of the specified bootable hard disk and loads the first one that has the booting flag switched on. One can make use of this behaviour to let it boot up GNU/Grub, a boot loader developed for Linux but can be installed without an operating system. If we put Grub into an “active” data-only Fat primary partition then Grub becomes available to multi boot other systems.

The write-up below is mainly for Linux as Grub is sourced from it. By expanding its booting menu Grub can be used boot over 100 systems. The booting of BSD and Solaris is not described here because it is identical to the case of Grub booting a Windows. More explanation is available in the above link.

(B) Theoretical explanations of why the scheme works

(1) Grub is a boot loader in binary form. It has no filing structure so it can be put into a Fat partition which Linux can read and write.

(2) A data-only primary partition has no operating system inside and its reserved boot sector is unused and empty. Putting Grub there does no harm and creates no inconvenience. The 3 files stage1, stage2 and menu.lst needed by a Grub implementation are tiny in size.

(3) Windows MBR always loads the active partition starting from the boot sector and couldn’t tell what is inside. The binary pattern of Grub is loadable and the partition ID of fat is the one MS has to support.

(4) All Windows versions provide a facility for marking another partition “active” and so it is possible to switch the booting alternative to a data-only primary partition. The data partition boots because Grub has been implanted there.

(5) Grub is a rare boot loader that can be installed without an operating system.

(6) Grub is widely available from free Linux Live CDs

(C) Necessary conditions

(1) The partition hosting Grub must be a primary type. Grub can be implemented in a logical partition by Windows MBR will not bother with logical partition.

(2) The partition hosting Grub must be in Fat12, Fat16 or a Fat32 format. Linux does not yet write on NTFS partition and does not write on it. Put Grub in a non-MS partition will not attract Windows MBR attention.

(D) Some known features

(1) For the purpose of hosting Grub the primary Fat partition can be very small as stage1 is 512 bytes, stage2 is less than 150 k bytes and menu.lst is a text file with only a few lines.

(2) For the hosting Grub only the fat partition is not subjected to the usual DOS restrictions, as a Dos system is needed. Thus the Fat data-only partition can be created in a Sata disk and at the end of a 300Gb disk, both of which I have tried out satisfactorily. Current Grub can reside anywhere in a hard disk.

(3) The menu.lst in the data-only partition if omitted will force Grub to boot to a Grub prompt whereby the user has to boot up each system manually. The menu.lst is just a script file to execute the same commands automatically.

(E) Application

This is really for the Windows users nervous of getting into Linux, BSD and Soloris as booting a non-MS system is tedious using NT version boot loader NTldr while using the non-MS system’s boot loader will result in Windows MBR being overwritten.

The method outlined here enable a Windows user access to Linux , BSD and Solaris systems without any alteration to the Windows MBR.

The method has been written to suit for PC without access to a floppy drive.

(F) Implementation

(1) Resize the hard disk to make available unallocated space for about 6Gb. For first-timer a 5Gb partition for Linux, 0.5 Gb for Swap partition and 0.5 Gb for a data-only primary Fat partition. The latter can be omitted if there is an existing data-only primary partition available. Both Linux and Swap can be in logical partitions. Linux comes in more than one CD or in a DVD may need 10Gb on its own. Solaris may need 15Gb. Partition for a BSD is similar to a Linux. Solaris and BSD systems needed to be installed in primary partitions only. The only exception I am aware of NetBSD which can be accommodated in a logical partition.

(2) Download a Linux Live CD iso image and burn it into a CD. Ideal one should have “Grub” and “Qtparted” inside. The one I would recommend is Kanotix or Knoppix but this can be used just as a tool and different to the one finally installed. The “Qtparted” can be used for resizing the hard disk and creating the necessary partitions. For the purpose of description I assume the disk is IDE type and so hda1 is the Windows, hda2 the data-only Fat partition, hda3 the Linux partition and hda4 the swap. Had the Linux and Swap been formed as logical partition it would be named automatically as hda5 and hda6, as the first 4 are reserved for primaries only. If the disk is a Sata type then all “hda” will have to change to “sda”. It is a good practice to reboot the system after partitions have been created. The other partitioning tools in Linux are the “fdisk” and “cfdisk” in command mode and they are more versatile in supporting Solaris and various BSD partition types.


(3) There is no need to format the two Linux partition as every Linux installer will want to do itself. Only the data-partition if created new will need to be formatted. This can either be done in Windows or in Linux Live CD. To format a Fat16 partition of hda2 in Linux terminal command is

Code:
mkdosfs –F16 /dev/hda2
(4) Install Grub into the data partition hda2. This is done by booting up with the Kantotix, which uses Grub as the boot loader, made a /mnt/hda2 directory, mount it and ask Kanotix to tell us where has it stored Grub’s stage1 (stage2 is always stored together with stage1).

Code:
mkdir /mnr/hda2
mount /dev/hda2 /mn/hda2
find / -name stage1
(4) Kanotix should report back the files found in /KNOPPIX/lib/grub/x86_64-pc, so made a /boot/grub directory in /mnt/hda2 and copied the two files across.

Code:
mkdir /mnt/hda2/boot
mkdir /mnt/hda2/boot/grub
cp /KNOPPIX/lib/grub/x86_64-pc/stage1 /mnt/hda2/boot/grub
cp /KNOPPIX/lib/grub/x86_64-pc/stage2 /mnt/hda2/boot/grub
if another Live CD is used just change the directory reported by your Live CD in the above two lines. It is essential that stage1 and stage2 to be stored only in the /boot/grub directory of hda2 because that is where Grub will look for them.

Now is the time to invoke a Grub shell inside Kanotix

Code:
grub
Grub can be formally set up inside hda2 by these commands in Grub shell

Code:
root (hd0,1)
setup (hd0,1)
makeactive
The last statement makes the PC boot hda2 instead of Windows in hda1.

(5) I recommend the system to be tested so that a user knows the basic steps to survive in booting. Reboot the system at this point will fire up Grub to a command prompt without any trace of Windows. Don’t panic this is precisely what it should be. You can get your Windows back immediately by booting it manually with these line in Grub prompt

Code:
root (hd0,0)
makeactive
chainloader +1
boot
Now you know how to boot up a Windows manually.

Since Windows partition becomes active rebooting the PC will always return back to Windows and not Grub in the data-only hda2 partition. If you want to boot to Grub in hda2 just do the following before you exit Windows

clicked My Computer/Manage/Storage/Disk Management and then right click hda2 to select “to make partition active”

When you boot to Grub there is no system to work available except the commands in Grub prompt. You can make Windows partition active any time by the commands

Code:
root (hd0,0)
makeactive
Having a look at what commands you can use in Grub by typing “help”. To view the partitioning scheme of your hard disk you type “geometry (hd0), to reboot just type “reboot”. To power down just type “halt”.

(6) Although not straightly necessary it would be a “cool” thing to do by writing a booting menu yourself and have it ready before you even install the Linux. You can do this in Windows, use notepad only as the booting menu must be a text file called menu.lst in the \boot\grub directory of hda2 which should be your drive “D”. So just create \boot\grub\menu.lst with the following lines
Code:
#My 1st attempt writing a booting menu

title Windows in hda1
root (hd0,0)
makeactive
chainloader +1

title Linux in hda3
root (hd0,2)
chainloader +1
This file should be in your “D” drive. If created it will be seen the next time when you boot up hda2. You can still use the Grub prompt by press “c”. Hda3 is not yet bootable because you have not yet installed a Linux inside hda3 yet.

(7) Now install a Linux (or Solaris or BSD) of your choice. Pay attention to the questions and instruct the installer to install the Linux into hda3. This is usually asking the installer using hda3 as the root “/” of the Linux. The installer should automatically know what to do with the swap partition. The critical issue in the Linux installation is to insist the boot loader to be installed in its root. Under no circumstance allow the boot loader go to the MBR. On completion of a full installation your Linux can be booted by the menu.lst you have created. Linux is born to multi boot. During installation it will check hda1 and hda2 and realise Windows MBR and Grub are inside and so it could build up a menu to both these two partitions inside hda3. Thus you may end up hooping between hda2 and hda3 partitions and able to fire up Windows from either of them.

(8) The Linux you choose can have any type of boot loader. It can be a BSD, a Solaris or a Darwin x86. As long as you deny the system to install its boot loader in the MBR it has no alternative but to put the boot loader inside its root partition. That makes the system “chainloadable” by Grub. A Linux partition does not need to be active in order to be booted up. Neither does a BSD or a Solaris need to be made active if it is booted by Grub. Windows is the only exception that needs its boot flag “switched on” when being booted.

(9) There is no harm done if you do make a mistake overwriting Windows MBR with a Linux (or another system’s) boot loader because you always can restore the Windows MBR either by a Windows installation CD (anyr one from Win2k or XP) or a Freedos CD downloadable from the Internet.
With the former you boot up the installation CD and wait until you can press R to opt for the Recovery Console where you just type

Code:
fixmbr
exit
The Freedos offers a CD ios image which you can burn and boot up the Dos 7.1 system. You can then use its fdisk.exe program

Code:
fdisk /mbr
Either method will get your Windows MBR back. If the user has an access to a bootable floppy drive the Windows MBR can also be restored using the command identical to the Freedos CD.

Posted in Uncategorized
Views 5603 Comments 2
« Prev     Main     Next »
Total Comments 2

Comments

  1. Old Comment
    I have three distros on my machine, as well as windows xp. I use grub, installed where the MBR was, and each time I add an OS I simply dedicate a new partition and make the appropriate entry into grub. It boots all of the systems quite easily. So, if I am correct, this simple addition to the GRUB config file is all that is needed. This idea seems to be quite a complicated way to achieve the same result.
    Posted 12-31-1969 at 07:00 PM by saikee saikee is offline
  2. Old Comment
    I have read some of your posts before and always come away impressed.
    Posted 12-31-1969 at 07:00 PM by saikee saikee is offline
 

  



All times are GMT -5. The time now is 09:40 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration