Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screwed up my MBR!! 1

Status
Not open for further replies.

iceman95

Programmer
Oct 11, 2001
6
US
I hope someone can help me with this.

I recently upgraded my Redhat from 7.0 to 7.2 on a dual boot machine. I primarily use Win98. During the install, I mistakenly chose not to load GRUB. The old version of LILO would not work, and it was necessary to boot to Linux using a boot floppy. I went ahead and ran the grub-install, but installed it to the MBR rather than to the Linux root. (doh!) Before the upgrade, I was using Boot Magic which comes bundled with Partition Magic. LILO was then chainloaded if I chose to boot Linux.

Now, I'm unable to boot into Windows. I've been struggling with trying to get the right combination in grub.conf, but no luck as far as Windows is concerned. Redhat will now boot without the floppy, however.

Below is the result of fdisk -l /dev/hda and the current state of my grub.conf file.

Disk /dev/hda: 255 heads, 63 sectors, 3720 cylinders
Units = cylinders of 16065 * 512 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 991 7960176 b Win95 FAT32
/dev/hda2 992 3720 21920692+ f Win95 Ext'd (LBA)
/dev/hda5 992 994 24066 83 Linux
/dev/hda6 995 1027 265041 82 Linux swap
/dev/hda7 1028 1666 5132736 83 Linux
/dev/hda8 1667 2684 8177053+ b Win95 FAT32
/dev/hda9 2685 3720 8321638+ b Win95 FAT32


default=0
timeout=10
splashimage=(hd0,4)/grub/splash.xpm.gz
title Red Hat Linux (2.4.7-10)
root (hd0,4)
kernel /vmlinuz-2.4.7-10 ro root=/dev/hda7
initrd /initrd-2.4.7-10.img

title Windows 98
;map (hd0,0) (hd0,1)
;map (hd0,1) (hd0,0)
unhide (hd0,0)
;hide (hd0,4)
rootnoverify (hd0,0)
chainloader +1
makeactive
boot

title DOS Boot Disk
map (hd0,0) (hd0,1)
map (hd0,1) (hd0,0)
chainloader (fd0)+1


What do I need to change to get Windows back?

BTW, I tried FDISK /MBR from a Windows boot floppy, but no luck.

Thanks,

Andy
 
I haven't much experience of GRUB but having looked at the RedHat website, you may be able to recover the situation by changing the default=0 to default=Windows98.

The boot after the Windows Stanza should allow you to boot into Windows as far as I can tell from the documentation. Why they moved away from the simpicity of LILO is a mystery. Hope this helps.


e.g:

default linux
timeout 10
color green/black light-gray/blue

# section to load linux
title linux
root (hd0,1)
kernel /vmlinuz root=/dev/hda5
boot

# section to load Window 2000
title windows
rootnoverify (hd0,0)
chainloader +1


This file would tell GRUB to build a menu with Red Hat Linux as the default operating system, set to autoboot it after 10 seconds. Two sections are given, one for each operating system entry, with commands specific to this system's partition table.


Also found this:
STEP 3: Configuring GRUB
In this section we will see how to boot into various operating systems and build the menu.conf file.

Let's start with boot procedures supported by GRUB. Booting can be done in two ways:

A. Booting natively by calling the kernel.
B. Chain loading or giving control to another boot loader.
Boot procedure using method A:

Set the root device or tell GRUB your root file system.
Tell GRUB where your kernel image is and pass the parameters to the kernel.
Reboot and try it.
To boot Linux, I have my kernel in /boot/ as bzImage and my root file system as /dev/hda5, or (hd0,4) in GRUB. So my booting procedure is as follows:

root (hd0,4) [This sets the root partition]
kernel /boot/bzImage root=/dev/hda5 [This sets the kernel]
boot [This starts booting into Linux]
Boot procedure using method B (this method assumes that you have another boot manager such as LILO or NTLDR installed in the partition):

Set the root partition but do not mount it.
Make that partition active
Set the first sector of the device to which the control has to be transfered with command chain loader.
Reboot and try it.
Let's try another example with Windows installed in /dev/hda1 or (hd0,0). The procedure for booting with Windows is as follows:

rootnoverify (hd0,0)
makeactive
chainloader +1 [+1 sets the first sector of the current root partition]
boot [transfers the control and quits GRUB]
The menu.conf file: this is used for booting multiple operating systems and menu building. Building the menu.conf file is not difficult. It uses plain English, as you will see in this section.

All the menu entries start with "title TITLENAME" without commas. You can set your TITLENAME to whatever you want.

To make the menu for booting Linux:

Set the title.
Set the root partition .
Set the kernel with right kind of parameters.
Boot
To make a working menu:

title Debian GNU/Linux 2.2 kernel 2.4.1
root (hd0,4)
kernel /boot/bzImage.2.4.1
boot
#----

(Hash (#) in front of a line is a comment.)

To make a menu for Windows or DOS:

title Windoze
rootnoverify (hd0,0)
makeactive
chainloader +1
boot
#----

What if you want to have two verisons of Windows installed--say one for yourself and the other for your family--but the second one won't install because it says Windows is already installed?

There is an easy way install two versions by hiding one partition during boot and then using the other. You can even password-protect your option so that no one loads your partition by mistake. Here's how to create two installations of Windows, hda1 and hda2 or (hd0,0) and (hd0,1), using the commands lock, password, hide and unhide.

For Windows "My Entry":

title My Entry
lock
unhide (hd0,0)
hide (hd0,1)
rootnoverify (hd0,0)
makeactive
chainloader +1
boot
#----

To use the lock command effectively you need to specify the password command near the start of the configuration file. The syntax of password command is as follows: password secret ("secret" is the password). At any time you can enter the password by pressing p.

For Windows "Family Entry"

title Family Entry
unhide (hd0,1)
hide (hd0,0)
rootnoverify (hd0,1)
makeactive
chainloader +1
boot
----

Anyone will be able to boot this entry as a password is not required.

Here's another interesting trick in the using password command. To hide the entries in the default menu listing or configuration file, you can load a personal listing by using the following command:

password secret

/boot/grub/secret-list.conf In this command, "secret" is the password and /boot/grub/secret-list.conf is the password file. Before doing this you should set the root directive or give the full path. For example:

password secret (hd0,4)/boot/grub/secret-list.conf

One more important command is the "map" command, which you can use when you have two hard disks and an operating system such as Windows which doesn't like to be booted from the second hard disk. For example, you can map hd0 as hd1 and hd1 as hd0. In other words, you can virtually swap the two hard disks and load the desired operating system. The commands are as follows:

grub> map (hd0) (hd1)
grub> map (hd1) (hd0)

For Booting FreeBSD:

title FreeBSD 4.0
root (hd0,4,a)
kernel /boot/loader
boot
#----

Here we are calling FreeBSD's loader. You see that the root (hd0,4,a) has three arguments as FreeBSD does virtual slicing of a single partition. We call the root partition "a". If FreeBSD occupies a complete second disk on your system, this would be root (hd0,a). So instead of calling the kernel we are calling the FreeBSD loader, which is better to talk to than the kernel.

(NOTE: I recommend that before trying OpenBSD and GNU/Hurd, you keep working on doing chain loading.)

You have now completed basic GRUB compiling, installing and configuring. The more you get to know GRUB, the more you will find GRUB to be an easy and powerful way to control booting.

Miscellaneous GRUB commands:

default xx
where xx is the default entry to boot.
timeout yy
where yy is the time (in seconds) after which the default entry will boot.
fallback zz
where zz is the entry which will boot if, after the timeout, the first entry fails to boot.
color
This is used for colorising the menu. Its syntax is: color normal current_selection. Both the fields can have two values as foreground/background For example:
color green/black or light-gray/blue

You can also use corresponding numbers.
REMEMBER: all values start from 0, so 0 is the first entry.

In my next article, I plan to test Fire GNU/Hurd and OpenBSD and maybe some networking bootup. You'll have to wait for at least three or more months as I will be taking my exams in between. Keep watching.

Any comments or mistakes can be forwarded to me at jskohli@fig.org.

 
If anyone's curious, here's how I fixed this.

Booting to Linux allowed me to have access to all of my partitions. I had a FAT32 E: partition that was relatively empty and it had enough space to copy the entire contents of my C: partition to it. I then booted to a Win98 floppy and ran FDISK to remove the C: partition then recreate it. I then formatted the new C: partition and booted back to Linux to copy the original contents of the C: partition back. Worked like a charm and everything seems to be working as normal.

Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top