I’m going to reinstall the Windows partition for testing purposes. It will of course overwrite GRUB. How do I get it back in openSuse?
In Debian I’d do “dpkg-reconfigure grub”, in Gentoo I’d simply re-emerge it. What’s the openSuse way of doing this? I don’t want to download the whole installation DVD just to repair GRUB, I’m going to boot Gentoo CD, chroot and then repair it from within.
Will just grub-install do? Or is there any “better” way, like something in Yast?
I’m not expert, but I think this depends on where grub is located.
Is grub on the MBR? Or is it on the root partition?
My wife just re-installed MS-Windows on her PC that dual boots between WinXP and openSUSE-11.1. Prior to installing MS-Windows, I went into YaST > System > Boot Loader > Boot Loader Installation to check where grub was located on her PC. I noted it was in the root with a generic MBR.
Her MS-Windows was on /dev/sda1, and her openSUSE root on /dev/sda2. And hence grub was on /dev/sda2 and not on the MBR.
So prior to installing MS-Windows, I changed her active partition from /dev/sda2 to /dev/sda1, rebooted, and noted her PC booted direct to MS-Windows with no grub (note I have various utility CDs standing by in case things get messed up, so such experimentation on her PC is not a worry).
She is still (a day later) adding MS-Windows apps to her new winXP install, so it may be a day or two before I change her active partition back from /dev/sda1 to /dev/sda2. I anticipate when I change the active partition back to /dev/sda2 it should load grub, and things will work.
But note if openSUSE’s grub had been on the MBR it would not be this simple.
I think you should always have an installation CD reader, DVD reader, or floppy, to handle contingencies. Borrow an external one if need be. And ensure you have rescue/contingency CD, DVD, or floppy’s near by. Too many things can go wrong.
This is just what I wanted to avoid, downloading and burning anything (though this is much smaller than openSuse DVD). I hope there is an easier way, I have an installed Linux system after all.
I think you should always have an installation CD reader, DVD reader, or floppy, to handle contingencies. Borrow an external one if need be. And ensure you have rescue/contingency CD, DVD, or floppy’s near by. Too many things can go wrong.
Thanks for warning . I always keep Gentoo netinst CD handy, it’s very useful. SystemRescue CD is based on it IIRC. Anyway, I usually need it only only to chroot into unbootable system.
I’ll just try a shot in the dark: reinstall Windoze and then “grub-install /dev/sda” in chrooted openSuse. It works in Gentoo, so why shouldn’t it here, after all . Debian’s “dpkg-reconfigure grub” does more or less the same. It will (should) install GRUB into MBR, while it’s in root now, but what the heck, it should just work. Then I’ll try to uninstall and re-install GRUB with Yast if the first didn’t help, but I believe it will be just fine. I only fear that Yast won’t like what I did and it will not find GRUB after I install it manually, let’s hope it won’t cause problems (it seems to me that Yast usually adds work and complicates things, but I admit that I don’t understand it very well ).
I’ll keep you informed .
EDIT (new post appeared before I finished this one):
Also look at the comprehensive tutorial at:
HowTo Boot into openSUSE when it won’t Boot from the Grub Code on the Hard Drive
Lenwolf
I’ve found this article, but I don’t want to download the whole DVD as I have a slow connection. Besides, it seems to me like taking a cannon to shot a sparrow…
I assume you have Windows and SUSE on the same HD but in different partitions? And that this is the first HD (in bios boot sequence)? Can you confirm this?
After you reinstall Windows, you just need to run a grub shell as root from anywhere, typically a live CD. Then type two commands:
grub> root (hd0,x) - where x refers to the SuSE partition (probably 1 if Windows is at 0 - grub counts from 0)
grub> setup (hd0)
grub> quit
That ought to reinstate the grub in your MBR.
(you can confirm the address of the SuSE partition by using the grub command ‘find /boot/vmlinuz’)
What is going on is that when you originally installed SuSE alongside Windows, SuSE created a GRUB menu at /boot/grub/menu.lst. This file defines the Grub OS selections. This menu should still be ok even if you reinstall Windows. When you execute the grub setup command it reinstalls the bootloader based on the menu.lst.
If your HD is not the first HD in the bios boot sequence it gets more complicated. Let’s leave that on the assumption that this is not your situation.
I’m still getting to grips with some of this myself. My understanding is that the bios always runs the bootloader from the MBR which is always at the physical start of the HD before the first partition. I understand that Windows puts a bootloader here and that when SuSE is installed this bootloader is replaced by GRUB’s (stage 1). So although SuSE may be at (hd0,1) the GRUB bootloader is still instantiated at the MBR at the start of the disk.
So if your wife were to reinstall Windows I reckon you’d lose your GRUB and you wouldn’t be able to access SuSE in the second partition.
For the record rotfl! I imagine that to recover an overwritten GRUB you can use any live linux CD or USB. So you could probably use a Knoppix live CD or fedora USB stick to run linux, then open a command terminal, become root and run grub. IOW I don’t think you need to use a SuSE grub to fix your SuSE bootloader because the grub instructions are contained in menu.lst in your SuSE /boot/grub directory.
I’m still getting to grips with some of this myself. My understanding is that the bios always runs the bootloader from the MBR which is always at the physical start of the HD before the first partition. I understand that Windows puts a bootloader here and that when SuSE is installed this bootloader is replaced by GRUB’s (stage 1). So although SuSE may be at (hd0,1) the GRUB bootloader is still instantiated at the MBR at the start of the disk.
So if your wife were to reinstall Windows I reckon you’d lose your GRUB and you wouldn’t be able to access SuSE in the second partition.
See also: Master boot record - Wikipedia, the free encyclopedia[/QUOTE]My wife is a big winXP user, and not much of a Linux fan, although she does want Linux on her PC. I guess I’ll find out in a day or two about her MBR and grub (and what winXP did to the MBR), when she asks me to restore the Linux (grub) boot loader selection (upon boot) back on her PC.
Given the many recovery boot CDs I have, I’m not worried, and it should be a good learning experience to see what happens when I try different things.
Edit - for educational purposes (ie educate myself) the 1st thing I will try is simply change the active partition from /dev/sda1 to /dev/sda2.
Each hard drive also has one of its possible 4 partitions flagged as an active partition. The active partition is a special flag assigned to only one partition on a hard drive that the Master Boot Record (MBR) uses to boot your computer into an operating system. As only one partition may be set as the active partition, you may be wondering how people can have multiple operating systems installed on different partitions, and yet still be able to use them all. This is accomplished by installing a boot loader in the active partition. When the computer starts, it will read the MBR and determine the partition that is flagged as active. This partition is the one that contains the boot loader. When the operating system boots off of this partition the boot loader will start and allow you to choose which operating systems you would like to boot from.
The active “flag” in the MBR partition table tells the bios which partition to look in for a bootloader to run. Ok so it seems in the case of a dual-boot off the same HD, the MBR partition table is altered to define the new, second partition and make it active. The GRUB bootloader program is installed in the second partition. The Windows bootloader program in the first partition is unaffected.
This explains why, when you change the active flag, that Windows’ bootloader starts up and you don’t see a GRUB menu.
In the case of a dual boot system where Windows is on hd0 and SuSE is on hd1 and the system boots off hd0 the GRUB bootloader must replace the Windows bootloader on hd0. In this case, if Windows is reinstalled the GRUB bootloader gets overwritten.
If all this is true, then for a dual-boot off the same HD, all one needs to do is reset the active partition to the SuSE one after a Windows repair/reinstall.
But for a dual boot off different HDs where the Windows HD is the first boot device, one must reinstall the grub bootloader. This makes this configuration a pest and I think it should be avoided. The better approach is to make the SuSE HD the first boot device, have the GRUB bootloader on the SuSE HD and not touch the Windows HD at all.
The disk space can be used in a boot loader is very restricted because a MBR (see MBR) is only 512 bytes but it also contains a partition table (see Partition table) and a BPB. So the question is how to make a boot loader code enough small to be fit in a MBR.
However, GRUB is a very large program, so we break GRUB into 2 (or 3) distinct components, Stage 1 and Stage 2 (and optionally Stage 1.5). See Memory map, for more information.
We embed Stage 1 in a MBR or in the boot sector of a partition, and place Stage 2 in a filesystem. The optional Stage 1.5 can be installed in a filesystem, in the boot loader area in a FFS or a ReiserFS, and in the sectors right after a MBR, because Stage 1.5 is enough small and the sectors right after a MBR is normally an unused region. The size of this region is the number of sectors per head minus 1.
I think we are both right. The GNU GRUB manual (above) shows that the MBR is where stage 1 (and sometimes stage 1.5) is put. I assume stage 2 will reside, in your wife’s case, in the SuSE partition - although not entirely convinced yet.
I am still concerned as to whether reinstalling Windows will rewrite the MBR in such a way as to delete stage 1. I fear it will. In which case GRUB would need to be set up again.
I’ll find out in a day or two as to what exactly winXP did (when my wife re-installed winXP on her PC) when I go to restore the grub boot manager.
I do note before my wife re-installed winXP, that I went to YaST (after booting via grub to /dev/sda2 and obtained openSUSE-11.1) that grub reported a “generic MBR” with /dev/sda2 being active and /root being where grub was located. YaST indicated grub was NOT on the MBR.
My guess is that this “generic” MBR is what allowed winXP to boot directly when I changed the active partition from /dev/sda2 (linux root) to /dev/sda1 (winXP). I also suspect that this “generic” MBR may be over-written by a “windows” MBR, which may be different from the “generic” MBR, and that may mean simply changing the active partition to /dev/sda2 may not be enough for grub to boot again … I’ll find out in a day or two.
… but I suspect I may need to (1) make /dev/sda2 active and also (2) replace the “windows” MBR with a “generic” MBR code.
… however this is speculation (for when I did this before on other PCs I just launched the tools to fix the boot manager, and never tried to understand what the tools were doing).
I’m looking forward to learning some things when I restore her PC’s grub boot manager.
[as a further note - I do note I have installed grub ON the MBR in other PCs, and for those PCs where grub is ON the MBR (as opposed to just being on /root) one can not simply change the active partition to get windows to boot directly, but rather the MBR has to be changed via “fixmbr” to get windows to boot directly]
It’s all very funny - and easier than expected. For some reason, after running grub-install (it’s more or less the same as doing it manually as suggested above), Windoze started, though there should be GRUB in MBR now. Then I’ve tried to remove bootable flag from /dev/sda1 (windows boot) and added it to /dev/sda4 (linux root) and now it boots fine and I’m able to start Windows with chainloader +1.
I suppose I need to find more on what exactly resides in the MBR and what bootable flags do…
Thanks for your points!
EDIT: why can’t I edit the first post to add [SOLVED] in the title?
GRUB stage1 can be installed in 3 different places on hdd. Say we have hdd partitions below.
hdc1 07 XP
hdc2 83 Linux ‘SuSe’
hdc3 0f w95 Ext’d (lba)
hdc5 83 Linux ‘Simpy Mepis’
hdc6 82 swap
install stage1 in MBR (normal place)
install in hdc2 ‘linux root’
install in hdc3 ‘w95 Ext’d’ (normally not used)
can not install grub stage1 to hdc5 and have it boot, except via Suse boot menu.lst.
for 2&3 have XP’s boot code in MBR. Some generic mbr boot codes might work (?).
NEVER install grub to a MS partition.
1,a) will be overwritten during XP clean install, repair install might not be overwritten.
2,a) hdc2 must be made Active to use grub. Will not be overwritten by XP but to install XP may have to change hdc1 to Active, XP might do the change during install. Will have to change Active flag back to hdc2 for grub.
3a) hdc3 must be made Active to use grub, MS programs will not do this but linux ‘fdisk’ will. Same problems with active flag as above. Some linux’s install programs might not give this option. If you do not have a primary linux partition and do not want grub in MBR, this is your option.
Options 2 & 3 are good if XP will not install if grub is in MBR, some comp/XP has problems while others do not. I have no idea why.
I assume stage 2 will reside, in your wife’s case, in the SuSE partition - although not entirely convinced yet
The correct stage 1.5 and stage 2 will normally (always) be in /boot/grub of the linux root or dedicated boot partition.
If one uses a /boot partition , that is where /boot/grub files will be at. So to install grub manually it should be
root (hd0,1)
setup (hd0)
if stage1 is to be installed in the MBR.
‘root’ will point to where the /boot/grub files are at, ‘setup’ is location one wants stage1 put.
One would not normally use a ‘/boot/’ partition for only 1 linux install, unless the hdd ‘/’ partition was beyond the bios limits, I think.
Ok, so to put grub’s stage 1 code into the boot sector of the 4th partition (the /home one) the commands would be:
grub> root (hd0,1)
grub> setup (hd0,3)
This then requires a MBR code that will support booting from the bootloader code in the 4th partition.
My understanding is that the MBR contains a partition table, for up to 4 “primary” partitions, and that each partition has a “bootable flag”. My understanding is that setting this flag to “true” is what is meant by making that partition “active”. The bios will pass control to the first bootable partition’s boot sector in the partition table.
So. Grub can set a “bootable flag” to true by means of the “makeactive” command. To set the 4th partition as bootable in the MBR partition table, the command sequence would be:
grub> root (hd0,3)
grub> makeactive
Now, since only one partition is meant to be bootable at any one time, it follows that the makeactive command also deactivates (sets the bootable flags to false) all other partitions in the MBR partition table.
Ok?
I have read up on disk drive formats. The very first sector (512 bytes) on a disk is always the MBR and is what the bios reads. The first sector of EVERY partition is called the partition’s boot sector. Stage 1 can be put in either. I am not yet sure where stage 1.5 can be put and when it is needed (it seems to be sometimes needed and sometimes not), and I assume that stage 2 is always in the filesystem proper of the partition.
Another unknown is what is the difference between grub’s stage 1 and the MBR code that windows installs. Why are they different? Could it be that the windows stage 1 prevents booting partitions other than the first one? In theory, the MBR code should just transfer control to the boot sector code of the first partition in the partition table that has its “bootable” flag set and this should work ok for windows too.
You are mostly correct.
1st paragraph:
That would be the correct command, but one would normally not put it on /home, but you could. You would have to use some other program ‘fdisk’ to set the boot flag.
2nd)
The MBR does have 4 partition slots, 4 primary or 3 primary and 1 extended. The extended partition can have up to 20+ logical volumes.
3rd)
Little bit off, the bios will pass control of the boot to the MBR.
If the MBR code is MS type it will look for 1 and only 1 partition with a “boot flag” and if found will read the first sector of partition and turn the boot process to it.
Some boot codes in the MBR work differently , such as GRUB and other 3rd party boot managers.
4th)the ‘makeactive’ command is normally not needed and if you have a MS code in the MBR and it in turn calls GRUB , then using ‘makeactive’ on a partition that does not contain GRUB will result in not having GRUB on next boot. (hope you can understand what I’m saying)
5th) As for stage 1.5, I’m not sure, but think it is always used. Reading some sites it might not be. If you look in ‘/boot/grub’ you will notice several different stage1.5 files. The one that is used will depend on the file system type that stage 2 is on. (I think) Stage1.5 tells GRUB how to read the file system. Stage1 does not know how to read any types of file system and the start sector of 1.5 is embedded in its code during install.
MS boot code in the MBR will boot any partition with an Active boot flag, including an extended partition, but not logical volumes. The extended partition would need a boot code and MS will not write one there.
One main difference with MS and GRUB is that GRUB can boot extended volumes and has more user control.
In that case I don’t understand whay makeactive does. I thought it modified the MBR partition table flags.
The GRUB manual says:
Command: makeactive
Set the active partition on the root disk to GRUB's root device. This command is limited to primary PC partitions on a hard disk.
I must say that I find the GRUB manual very poorly written in many ways, not least its inconsistent use of terminology. In the example above, I think it is supposed to read “Set the active partition on GRUB’s root disk to be GRUB’s root partition.”
Eg:
grub> root (hd0,3) # set GRUB’s root as the 4th partition
grub> makeactive # modify the MBR partition table to make the 4th partition the only bootable (active) one
This may not be what makeactive does but if not I don’t know what it does.
to oldcpu:
What method did you use to change the active partition on your wife’s HD?