LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How can i backup and install GRUB (https://www.linuxquestions.org/questions/linux-newbie-8/how-can-i-backup-and-install-grub-540942/)

styles24 03-27-2007 01:43 AM

How can i backup and install GRUB
 
I am fairly new to Linux. Im currently taking classes for Linux and have searched for this and cant find it.

I have XP installed on /dev/hdc1 and Fedora 6 on /dev/sda1. I installed grub to the XP partition, but my XP is acting up so i want to reinstall it. Problem is that grub is installed on this drive and i know that reinstalling windows would override the bootloader to get into Linux. I want to know step by step how to backup and reinstall grub to /dev/hdc1 after i have reinstalled XP. The instructions and answers im looking for are prolly right under my nose, but my nose cant see anything at the moment. Im sorry if this has been answered somewhere else, but i cant find it. Any help would be appreciated.

Jesse

Quakeboy02 03-27-2007 02:00 AM

To save the MBR, which is what I think you want, you do the following:
Code:

dd if=/dev/hdc of=MBR.image bs=446 count=1
To restore it, boot a liveCD and run:
Code:

dd if=MBR.image of=/dev/hdc bs=446 count=1
The MBR is the master boot record that searches for the grub components on your disk at boot time.

styles24 03-27-2007 02:16 AM

Thank you for your quick reply. Will this also work if XP and Fedora are installed on the same drive on my laptop and i want to do the same, just insert the correct partitions?

And can i just use a regular fc6 install disk or do i need to download a fc6 live cd? Thank you again.

pixellany 03-27-2007 07:42 AM

Quote:

Originally Posted by styles24
Thank you for your quick reply. Will this also work if XP and Fedora are installed on the same drive on my laptop and i want to do the same, just insert the correct partitions?

And can i just use a regular fc6 install disk or do i need to download a fc6 live cd? Thank you again.

Copying and restoring the mbr is independent of what is on the drive. By definition, the mbr is on the 1st sector of the drive which the BIOS sees as #1.

Don't understand the question about the Fedora disk...You can do the dd thing from any Linux--eg what is already installed, live CD, etc.

Final nit: When you are talking about the mbr, there are no partitions involved.

styles24 03-27-2007 10:13 PM

Quakeboy02 and pixellany, thank you very much for your help.

Junior Hacker 03-27-2007 11:53 PM

If you want to put it in a specific place, like your home directory, the command should include that directory:

dd if=/dev/hdc of=/home/<user>/MBR.img bs=512 count=1

jschiwal 03-28-2007 12:06 AM

You might want to read the Wikipedia article on the MBR:
http://en.wikipedia.org/wiki/Master_boot_record

Notice that Quakeboy02 used the first 446 bytes. Some howto's use 512 bytes. The first 446 bytes contain just the bootstrap loader code. So you would be backing up part of the MBR and not the entire MBR.

If XP uses the NTFS filesystem and you don't have NTFS write support in Linux, then you may want to copy the MBR backup image to a usb device instead and copy it to C:/ (/dev/hdc) when using XP before reinstalling.

Quakeboy02 03-28-2007 12:31 AM

jschiwal,

I'm glad you made me look that up. I had though that the first 446 bytes contained only the boot code. But, apparently, it's even more complicated than that. But, if you backup the whole sector (512 bytes) be aware that that MBR is not transferable to any other disk, as it contains the partition table.

For more info: http://en.wikipedia.org/wiki/Partition_table

Junior Hacker 03-28-2007 01:00 AM

The thread starter did not mention using another disc, only backup the MBR to put it back after re-building Windows.

Junior Hacker 03-28-2007 01:11 AM

I do welcome any "constructive criticism" here, but if I remember correctly, there are some "reserved" bytes in the MBR, which is probably why Awesome uses 446 excluding the reserved bytes, which contain nothing.

jschiwal 03-28-2007 02:57 AM

The partition table starts above 466. The entire MBR is 512 bytes long. The Wikipedia article has a table showing this.

If you really want to feel nerdy:
dd if=/dev/hdc of=MBR.image bs=446 count=1
objdump -D -b binary -mi386 -Maddr16,data16 MBR.image

Junior Hacker 03-28-2007 03:09 AM

A quick look at that spells "fat 16 floppy"

wpn146 03-28-2007 12:40 PM

Windows XP "assumes" it is the only operating system in existence in the Galaxy and can wipe your dual boot mbr.

I have found "Smart Boot Manager" to be useful to have around (Google for it). If Windows XP wipes your mbr on /dev/hdc1 the "Smart Boot Manager" should let you boot to Fedora 6 on /dev/sda1. Once booted, you should be able to reinstall grub as a dual boot system with:
Code:

grub-install /dev/sda
On the other hand, if you wish Windows XP to "fix" what Windows XP considers a corrupt mbr:
Code:

1.  Boot from the Windows XP cdrom. 
2.  Run the "fixmbr" command.


styles24 03-28-2007 11:17 PM

Ok, just so im understanding right. If i reinstall windows on /dev/hdc, i can install "smart boot manager" and then boot to Fedora 6 on /dev/sda1. From there i install grub to /dev/sda, and if i wanted, instead install grub to /dev/hdc since i want it to boot from the first hard drive. I dont mean to be a PITA, i just got alot of conflicting info and want to get it right.

wpn146 03-29-2007 09:21 AM

Quote:

Originally Posted by styles24
Ok, just so im understanding right. If i reinstall windows on /dev/hdc, i can install "smart boot manager" and then boot to Fedora 6 on /dev/sda1. From there i install grub to /dev/sda, and if i wanted, instead install grub to /dev/hdc since i want it to boot from the first hard drive. I dont mean to be a PITA, i just got alot of conflicting info and want to get it right.

"Smart Boot Manager" fits on a 3.5" floppy and is operating system independent. I find it useful just to have around. It allows you to boot from devices that otherwise not be bootable. If you have an internal 3.5" drive that can be selected as the boot device in the BIOS, you boot from the floppy and it allows you to boot from its menu, effectively bypassing a bad or unbootable mbr.


All times are GMT -5. The time now is 03:05 AM.