How to switch a Windows MBR to Grub2
Keyword in a nutshell : Grub2 can be placed inside any MS Windows to enhance the booting power.
What is the switch all about?
There is no necessity to change. The alteration is merely adding a more powerful and easier boot loader Grub2 as an additional tool.
The original boot loader is untouched and is still the one that boots the MS Windows.
What version of MS Windows does the switching applied?
Done it with Win2k, Xp, Vista and Win7 before writing this Howto.
Why is it possible?
Grub2 has been engineered to read NTFS partitions. Therefore Grub2 can be installed inside a MS Windows partition that has a NTFS filing system. Linux may or may not be present elsewhere in the computer. In any case the switching is for Grub2 to work as a stand alone boot loader. Linux is only required to put it there.
What actually are the changes in my Windows system?
Only two items are involved.
(1) The MBR, which is exactly 512 bytes long and is the first sector of the first boot disk, is replaced by Grub2's own version. Every Windows system can be booted without its MBR.
(2) A new directory \boot is added to the "C" drive. Inside it \boot\grub has Grub2's system files. Win2k and Xp do not use a \boot partition at all. Vista and Win7 do have a \Boot partition which can be used to house a subdirectory for grub. Please note the \boot in Windows appears as /boot in Linux. The slash changes angle.
How much hard disk space do I lose to get Grub2 in my Windows?
The \boot\grub directory can have about 180 items with a total storage of 1Mb or 1000kb. All versions of Grub can be put inside a floppy and Grub2 is no different.
Why Grub2? what's wrong with Grub1? what are their differences
Grub1 cannot read a NTFS partition so It cannot be installed inside a MS Windows. Grub1 can be added if a separate partition is made available for its residence.
As Grub2 can read NTFS partitions it is more useful. For example the \Boot is a hidden directory invisible to the Windows users but with Grub2 every hidden file and folder is visible.
Grub1 is up to version 0.97 and Grub2 started from version 1.9x. Grub1 is fully mature, totally capable but difficult to maintain and expand. It maintainers decided it was better to re-write everything and called it Grub2. Grub1 has not been maintained for a few years already.
What do I need to get Grub2 into my Windows?
Just a Linux Live CD that has Grub2 inside. Currently Ubuntu and LinuxMint are shipped with Grub2 as their default boot loader. Grub2 can be downloaded directly from GNU/Grub but to use it one has to build it into a Linux so the easy way is just boot up a Linux Live CD that has Grub2.
Is it safe and can I reverse the process?
It is perfectly safe as the MS system MBR (remember it is only 512 bytes long) can be restored using the Windows installation CD or DVD thereby overwriting the Grub2. The command with a Win2k/Xp in Recovery Console is "fixmbr" whereas for a Vista/Win7 the command prompt off an installation DVD is "bootrec /fixmbr".
To remove Grub2 folder is no different from removing any folder.
What happen if I don't have the original installation CD or DVD?
It is always the installation CD or DVD that provide the utility to alter the MBR. Any Windows installation CD or DVD of the similar Windows version will do as only one utility program is run.
OK so what are the steps?
Step 1 - Boot up a Linux Live CD that has Grub2. I assume Ubuntu above V9.04 is used.
Step 2 - Select a terminal as the work is safer to be executed in a terminal. Become a Super user (equivalent to Admin in a MS Windows) with these terminal command
Step 3 - Do a sanity check with the hard disk partitions by command
It is vital to identify the partition that boots a MS Windows in Linux.
Generally two conditions would have to be satisfied;
(i) The partition must have been marked "active". This is shown normally with a "*" in Linux terminal
(ii) The boot partition of any MS Windows must be a primary partition. In Linux terms only the first 4 partitions, from sda1 to sda4, are reserved primaries.
Here is an output from command "fdisk -l" of my own PC as an example
Code:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 1500.3 GB, 1500300828160 bytes
255 heads, 63 sectors/track, 182401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xdb426a9c
Device Boot Start End Blocks Id System
/dev/sda1 * 1 30394 244139773+ 7 HPFS/NTFS
/dev/sda2 30395 42553 97667167+ 83 Linux
/dev/sda3 42554 48633 48837600 83 Linux
/dev/sda4 48634 182401 1074491460 5 Extended
/dev/sda5 48634 48756 987966 82 Linux swap / Solaris
/dev/sda6 48757 73072 195318238+ 83 Linux
/dev/sda7 73073 85231 97667136 7 HPFS/NTFS
/dev/sda8 85232 97390 97667136 7 HPFS/NTFS
/dev/sda9 97391 109549 97667136 7 HPFS/NTFS
/dev/sda10 109550 170338 488287611 83 Linux
/dev/sda11 170339 172771 19543041 83 Linux
/dev/sda12 172772 175204 19543041 83 Linux
/dev/sda13 175205 177637 19543041 83 Linux
/dev/sda14 177638 180070 19543041 83 Linux
/dev/sda15 180071 182401 18723726 83 Linux
The two colored code condition are highlighted confirming my sda1 is the partition that boots a MS Windows.
Step 4 - Create a mounting point in /mnt of the booted up Linux, mount the Windows partition on it. The commands are
Code:
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
ls /mnt/sda1
The last command is optional for viewing the content of the Windows partition. As a sanity check Win2k or Xp always has boot.ini, NTLDR and ntdetect.com inside whereas for a Vista or Win7 there should always be a file called bootmgr and the /Boot directory present.
Step 5 - Install Grub2. This is just by a simply Linux command
Code:
grub-install --root-directory=/mnt/sda1 /dev/sda
Only this command implement the change. The consequence is the MBR, denoted by /dev/sda, will be allowed Grub2 to occupy. In so doing Grub2 will create a /boot/grub and populate it with the system files. At this stage Grub2 only boots to a Grub prompt and the user has to boot each operating system manually. To arrange the Windows automatically booted with a selectable menu a configuration file /boot/grub/grub.cfg must be created as per Step 6.
Step 6 - Use an editor to create /boot/grub/grub.cfg in the mounted Windows paritition /mnt/sda1 by command
Code:
nano /mnt/sda1/boot/grub/grub.cfg
with the following entries
Code:
menuentry 'My Windows in sda1 now booted by Grub2' {
set root=(hd0,1)
chainloader +1
}
The above entries can boot Windows in any partition by declaring the relevant partition in the statement "set root=". Grub2 counts disk from 0 and partitions from1 (same as a MS Windows) therefore (hd0,1) is the first partition of the first hard disk. Anything shown in menuentry only get displayed and not acted on.
The above steps work perfectly for Win2k and Xp.
For Vista and Win7 there is a small complication that /Boot and not /boot could be used in some versions of these two MS Windows. The /boot/grub therefore must be duplicated in /Boot, if it exists, by this command in the Linux terminal
Step 7 - To duplicate /boot/grub into /Boot if it exists
Code:
cp -r /mnt/sda1/boot/grub /mnt/sda1/Boot
OK now I have Grub2, what does it do for me?The commands in a Grub prompt below have been colored in blue.
This is difficult to answer as it depends how much you use it. The power of Grub2 is that you can talk to it directly and instruct it to do things. You do this in a Grub prompt which is available if instead of booting a system you press the "c" key. You will then see a blank screen with "Sh: Grub" and a blinking cursor. This is a Grub prompt that you can use to boot manually every installed operating system in a PC.
You can go back to the hard disk booting menu by this Grub2 command
Code:
set root=(hd0)
chainloader +1
boot
If you want to see the partitions in your PC the Grub2 command is
You can see all the hidden files in your Windows partition. For example if your Xp Windows is in (hd0,1) you can list its directories by
and view the contents of the hidden file boot.ini by
Code:
cat (hd0,1)/boot.ini
If you want to boot an operating system say in a USB flash drive (hd1,1) and it has a Grub2 you can do so by command
Code:
set root=(hd1,1)
configfile /boot/grub/grub.cfg
What Grub2 can do for you is how much use the commands available to you. These commands can be viewed by