There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming google gpu graphics hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry repair router security slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
How saving your MBR and using Ubuntu can restore your Grub to working order

Reply  
Thread Tools
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
10-Sep-2006, 11:34 AM #1
How saving your MBR and using Ubuntu can restore your Grub to working order
I run a system with Linux Fedora Core 3 (FC3) on one SATA disk with a RHPro7.2 slaved disk, and a WinXP Pro SP2 on another SATA disk with a Win98SE slaved disk, and I also use the Grub boot loader. I have an NTFS driver installed on Linux in order to mount and read the WinXP Pro SP2 disk. Recently, my WinXP Pro SP2 has had some difficulties that I attempted to solve with an XP Reinstall which I had successfully done before when things went south. Unfortuneately, it hangs at the Windows Progress bar screen just before the continuation of the XP Reinstall after reboot.

With the situation unresolved, I decided to investigate a WinXP Parallel Install, but kicked out of it when I became uncertain of whether certain folders in the original WinXP installation would survive when the Parallel install is done to another folder (e.g. C:\WinXP rather than C:\Windows) in the same partition as the faulty one.

One curious consequence of initiating the Parallel Install before I kicked out of it due to the uncertainties above was that it appears that the Parallel Install Process trashed my WinXP Pro SP2 disk drive Master Boot Record (MBR). This resulted in my Grub boot loader screen never displaying prior to defaulting to the WinXP bootup (i.e. grub.conf file contains: default=0 for the WinXP Reinstall), so as a consequence I could not also bootup my Linux FC3 system.

Luckily, I had previously saved the original MBRs of both hard drives on my Linux root account (for just such a situation) using the dd command, and so the problem of how to get back my Linux bootup capability presented itself. I had a Live CD boot disc CD of Ubuntu 6.0.6 which allowed me to capture the contents of both MBRs (as root using the sudo -i command after mounting the hard drives using Ubuntu's SysAdmin Disk Manager) and compare them with what I had saved originally via a hex dump using xxd command. I then successfully restored the MBR for the WinXP Pro SP2 hard drive by reversing the dd command's input and output files. Then the Grub bootup screen to select either Linux FC3 or WinXP Pro SP2 appeared on the next reboot of the system - thus allowing me to use my Linux FC3 (to create this thread).

-- Tom

P.S. For those of you who do not know how to save your MBRs, here is what I did:
To copy the entire MBR of the Linux FC3 disk to a file:
dd if=/dev/sdb of=/root/Mbrs/sdbmbr bs=512 count=1

To copy the entire MBR of the WinXP Pro SP2 disk to a file:
dd if=/dev/sda of=/root/Mbrs/sdambr bs=512 count=1

The new contents of the WinXP Pro SP2 MBR were simply saved to another file name from Ubuntu with the command:
dd if=/dev/sda of=/root/Mbrs/chk1sdambr bs=512 count=1

Then, I issued the following command to look at the contents of the saved vs new MBRs:
cat sdambr | xxd > sdambr.xxd; cat chk1sdambr | xxd > chk1sdambr.xxd

A diff command lets you view the textual dumps from the .xxd files

And finally, to restore the original WinXP Pro SP2 MBR contents:
dd if=/root/Mbrs/sdambr of=/dev/sda bs=512 count=1
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
saikee's Avatar
Senior Member with 3,409 posts.
 
Join Date: Jun 2004
Location: Newcastle
Experience: A Linux user gone nuts on multi-boot
10-Sep-2006, 07:00 PM #2
It sounds a bit over the top to keep a copy of the various MBRs.

All the Linux and MS systems MBRs can be generated from scratch and their systems will work as long as the original systems are not damaged.

The MS systems share a common MBR which can be restored by a Dos 6 or above floppy with the "fdisk /mbr" command or boot up any Win2k or xp installation CD and use "fixmbr" command in the recovery console. The MS MBR only restores into the first bootable disk.

Under normal operation all MS systems can be booted without using their MBRs. MS MBR is only used if one opts for booting several OSs by MS's NTLDR boot loader. When Grub is installed it overwrites MS's MBR and takes over the first 512 bytes of the first bootable disk.

As far as Grub or Lilo is concerned its boot loader can be re-activated any time by just a Live CD, boot it up, mount the relevant partition, chroot to it and you are right inside its BASH shell. In Bash shell one has access to
grub-install
grub
lilo
commands and Grub can be instructed to re-generate its MBR by
Code:
grub-install /dev/hda
in Lilo the equivalent is
Code:
lilo -b /dev/hda
I used to keep a copy of the MBR in a floppy by using the above commands but replacing the device hda with fd0. However as a Live CD is readily availble nowadays there is no need to keep a copy of the MBR any more.

I recommend any Linux user having a booting problem to use a Live CD. It is the most powerful tool. When one boots up a Live CD LInux one has access to its kernel. If one mounts the distressed Linux partition and "chroot" to it one is inside the distressed Linux. Technically one is using the Live CD's kernel in combination with the Bash shell of the distressed Linux. Many Distros, like Fedora for example, allow the user to rescue its own distressed Linux using the installation CD but a Live CD is just as good but capable of rescuing any Linux.

Last edited by saikee; 10-Sep-2006 at 07:07 PM..
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
11-Sep-2006, 08:13 AM #3
Hi saikee,

I appreciate your comments. However, since I do not have a working floppy drive (a replacement yet to install), and even if I had used fdisk /mbr, it would have only replaced the Windows MBR without the Grub boot loader - presenting a different problem via using the Live CD as you explained with which I was not familiar. I will keep approach that in mind for future reference.

By saving the MBRs for just the situation I was in and the tools I had available and felt comfortable using, it was, for me at this time, the best way (and probably only way) to proceed - not over the top - easier in concept and commands (with which I am familiar) for me to do, that's all.

The SAMS "RH Linux FC3" book has a 1/2 page paragraph on saving the MBR, and yes they probably recommend putting it onto a floppy, but that was not an option for me, and with the Grub bootup screen gone, I was left with little choice but to use a Live CD and attempt to do the restoration which I was not totally certain would work before attempting it.

I am not certain the Grub reconstitution method you cited would have been able to reconstitute my Grub information without more commands to direct the loader to either the Linux FC3 or WinSP Pro SP2 OSs to load. I am only certain that my saved MBRs worked, and perhaps I would need more practice at attempting your methods to feel confident enough in my abilities to make them work (as I am sure you are!).

Thanks again for your comments,

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein

Last edited by lotuseclat79; 11-Sep-2006 at 09:09 AM..
saikee's Avatar
Senior Member with 3,409 posts.
 
Join Date: Jun 2004
Location: Newcastle
Experience: A Linux user gone nuts on multi-boot
11-Sep-2006, 09:50 AM #4
lotuseclat79,

Just like you I used to save a copy of the boot loader for every installed Linux. I gave it up after learning how to get them via a Live CD.

The first 512 bytes you saved from the hard disk isn't a full boot loader but the stage1 of it only. The GRub's stage1 has embedded the stage2 address and so it can load the full boot loader. It is the same for Lilo and NTLDR but unlike Grub these boot loaders do not describe their operations.

The so-called reconstitution in fact is the full blown creation of Grub ( or Lilo) from the original installation. Grub stores everything in /boot/grub directory and the grub-install does nothing except duplicate its standard stage1 file with the address to load the stage2 stored inside /boot/grub.

The Bash grub-install command is identical to the Grub prompt commands of
"root" + "setup"
in it you tell Grub where the root of the Linux is stored and to setup the booting file in the specified bootable disk.

My point is whatever you are trying to save a copy of the MBR it is originally created from either the grub-install or root+setup statements.

I can confirm that you do not actually need Grub or Lilo installed in order to boot a Linux. All you need is to have the kernel installed. To boot a Linux the Grub commands comprise of only

(1) A title statement to show the name of the OS you are booting
(2) A root statement to tell Grub where is the root partition of the Linux
(3) A kernel statement to locate the location of the kernel
(4) An initrd statement, which can be optional for certain Linux, to locate the ramdisk file

All the above can be manually entered in a Grub prompt. To get a Grub prompt you can burn the standard stage1 and stage2 files into a CD. This is to install Grub without an operating system attached and is fully documented in the Grub Manual Section 3.1 No matter how hard I hard I haven't found an installed PC system that cannot be booted from a Grub prompt.

So why bother to keep a copy of the MBR when you can make one any time you want and boot the system without it?
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
11-Sep-2006, 03:25 PM #5
Hi saikee,

I did not know that!

Thanks for helping me to learn this,

-- Tom
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 06:24 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.