« Take That! WinXPpro Installer | Main | 64bit Dual-head 3D »

March 9, 2005

Rescue Mode, grub-install & udev

Fedora Core 3 is the first release from Red Hat that uses udev for managing the /dev filesystem. This new system offers some great advantages. I will be posting a new GuruGuide soon, introducing the basics of udev configuration.

However, this post is not about udev, per se.

I recently installed WindowsXP Professional on my notebook as part of a dual-boot configuration. There were issues getting Windows to install originally so I ended up installing Linux first, which is not how I usually do things. In this case, I was heading out of town the next day and needed Linux with me on that notebook.

After finally working out the issues with Windows, the only thing I needed to do to complete my dual-boot configuration was to get GRUB reinstalled to the Master Boot Record (MBR) on the hard drive. This way, GRUB comes along first and I can select Linux or Windows from it's menu.

One way to install GRUB to the MBR when the MBR has been clobbered (like happens when installing Windows, though Windows does not use the MBR in order to boot) is to boot using a Linux CD that provides a so-called "rescue" environment (sometimes referred to as a "LiveCD"). From there, you simply mount your hard drives partitions, chroot into the path where you mounted the hard drive and run the grub-install program.

So, I placed the Fedora Core 3 CD1 into the DVD drive on the notebook and booted up. At the CD's "boot:" prompt, I typed:

boot: linux rescue

Once the rescue environment was up and running, I typed:

# chroot /mnt/sysimage
# grub-install /dev/hda

Nothing happened; it just sat there, never reporting any errors. As it was about midnight last night when this happened, I went to bed and took another crack when I arrived at the office the next morning. The same thing, again.

I tried using a RHEL4 CD1 rescue environment, as well as RHEL3 & FC1 (all of which I had handy). Same problem. Then it dawned on me: udev. Device nodes for the hard drive do not exist in the chroot'ed environment. From the chroot'ed environment, I next ran:

# mknod /dev/hda b 3 0
# grub-install /dev/hda

This produced an error message telling me that grub-install could not find /dev/hda1, which it needed in order to finish setting things up. I created the appropriate device node and tried once more:

# mknod /dev/hda1 b 3 1
# grub-install /dev/hda

It worked! It is probably a good idea to delete the device nodes just created, before rebooting:

# rm /dev/hda*

After rebooting, GRUB did it's job and I can now boot to either Linux or Windows whenever I want.

Posted by lamontp at March 9, 2005 8:06 PM

Trackback Pings

TrackBack URL for this entry:
http://blogs.gurulabs.com/cgi-bin/mt-tb.cgi/76

Comments

Sorry, I can't seem to get any whitespace added in here... It doesn't seem to like using html or anything like that... Well, at least it's still in test, right? . . . . . . .


Anyway, I'm not sure that you actually have to use grub-install to get things working again after installing windows. I actually found that grub-install was less than helpful on my gentoo system last weekend when I was working with a similar situation.

Up until this past week, Gentoo was the only operating system on my laptop --- I wasn't dual-booting at all. However, I needed to prove to Toshiba that I had bad memory on my system, and they wouldn't believe it unless I ran their utility on WinXP. So, I resized my partition (I do not recommend this... Somehow, I managed to come out of that alive), and then installed WinXP on a tiny little partition that I had created.

I now had the trouble of figuring out how to get Grub to work as my boot-loader again, and I wasn't sure what to do. So, I booted into knoppix, and used fdisk to change which partition my computer booted from:

#fdisk /dev/hda

Now, I used a, and then selected my /boot partition (1). After that, things seemed to work fine.

In doing this, I did not actually attempt to set things up so that windows can boot as well. I'm sure that it would just be a matter of modifying the grub.conf, but I didn't do it. I only installed Windows for that single utility, and ran it the moment it booted for the first time.... I don't really have any desire to return to Windows again unless absolutely necessary.

~Maquis

Posted by: Maquis at March 12, 2005 9:45 PM

Ah, yes; there are ocassions when grub-install is not needed.

However, in my situation (which is also based off of the default installation configuration for the boot loader), GRUB was originally installed to /dev/hda. When I installed Windows, it zeroed out the first 446 bytes on the disk.

In your situation, GRUB was installed on /dev/hda1 (or whatever partition /boot lives on). By changing the bootable marks on the partitions, you selected which boot loader installed to the boot sector (first 512 bytes) of the partition to use.

On x86-type systems, the BIOS will try to load and execute the MBR. If that fails, then it looks at the partition table (the last 66 bytes of the first 512 bytes on the hard drive) and tries to load and execute the boot sector of a partition marked as bootable.

Windows (all versions of NT and Win95 and up) simply zero out the MBR boot sector (making it non-executable) and install their boot loader on the partition of the system drive (usually C:\). This is because they just can not fit their boot loader into 446 bytes. They needed the full 512 for the code.

Lamont R. Peterson

Posted by: Lamont R. Peterson at March 13, 2005 6:05 PM

Post a comment




Remember Me?

(you may use HTML tags for style)