Question about dual-booting two versions of RedHat

Edward C. Bailey ed at redhat.com
Thu Oct 16 17:58:52 UTC 2003


>>>>> "Terry" == Terry R Linhardt <linhardt at swbell.net> writes:

Terry> I have a large disk drive with ample space. I've decided I would
Terry> like to install two versions of RedHat. One would be a "production"
Terry> version, the other a "test" version.

Terry> The documentation I've seen talks about Linux co-existing in a dual
Terry> boot with some version of Windows.

Terry> I've installed the "first" version of Linux in the first 25 GB of
Terry> disk space. Do I install the "2nd" version in a similar
Terry> manner?...that is, using a custom install and then selecting the
Terry> unused portion of the drive to install the 2nd version? GRUB will
Terry> see the two installs and allow me to select which one to boot?

No, unfortunately...

Terry> In a sense, this all seems fairly easy...is it pretty
Terry> straight-forward?

Nope, but you can *make* pretty straight-forward... :-)

Here's my situation, and how I set up dual-booting:

    I have a test machine that I use to do test installs of Fedora Core,
and Red Hat Enterprise Linux.  The system is configured with dual drives in
a software RAID 1 configuration, so every partition in my fstab is /dev/mdX
(this becomes important a bit later in my description).  I have configured
a shared swap partition, a shared /home partition, and separate /boot and /
partitions for each OS.

    Because I do many installs, and because the currently-available
install-time options are to either install a bootloader or not, it's easier
to just let the installs install a bootloader, and pick up the pieces
afterward.  However, I don't want to have to manually edit grub.conf files.
Anaconda creates a very nice grub.conf file, and the kernel rpms very
nicely add grub.conf entries whenever you install new kernels, and I don't
want to throw all that away.

    So, I decided on the following layout:

        o A master Grub configuration installed in the MBR, that chainloads
          to...

        o ...two distro-specific Grub configurations (installed in the
          first sector of the /boot partitions), one for each installed OS

This means that, when booting, I hit one grub screen asking me whether I
want to boot Fedora Core or RHEL, followed by another grub screen for the
OS I selected.  With appropriate default and timeout settings this can be
entirely automated.  However, in my case, I *don't* want the OS selection
grub to be automated, as I always seem to turn on the system, get
distracted, and then have the wrong OS booted before I notice... :-)

    Here's the grub.conf I use to do this:

########################################################################
title Red Hat Enterprise Linux
        root (hd0,1)
        chainloader +1
########################################################################
title Fedora Core
        root (hd0,0)
        chainloader +1

You could add "default" and "timeout" lines to automate the selection of
one OS over another; if you want to have it look pretty, you can add a
"splashimage" line as well.  You'll also need to upate the device
specifications on the "root" lines, as my device layout is almost certainly
not the same as yours...

    To make sure that this file isn't overwritten when I do an install, I
created a boot/grub/ directory tree on my /home partition (remember, it's
shared between both OSes), and populated it with the files located in the
grub directory from one of my installs:

[root at binger ed]# ls /home/boot/grub/
device.map     grub.conf       menu.lst    xfs_stage1_5
e2fs_stage1_5  minix_stage1_5     stage1   fat_stage1_5
grub.conf-save reiserfs_stage1_5  stage2   ffs_stage1_5
jfs_stage1_5   reset-grub      vstafs_stage1_5

(NOTE: This means you should *never* create a user called "boot", as this
will likely overwrite your boot configuration!! :-)

    You could probably get rid of the /boot directory (ie, just have
/home/grub), and get rid of all the unnecessary files in grub, but I didn't
feel like taking the time to pare things down to the bare minimums.  If
such warts offend you, feel free to clean things up as you see fit... :-)

    So, now we have a set of grub files that won't be touched during an
install (assuming /home is left untouched, of course).  However, we have a
few problems:

    o This grub configuration is currently not installed in the MBR,
      meaning that a reboot will just give us the grub screen for whichever
      OS was installed *last* (because each install overwrites the MBR)

    o The two OS-specific grub configurations are not installed in the
      first sector of their respective /boot partitions

And even if we solve these two problems, the next time we do an install,
it'll overwrite the MBR with its own grub configuration, so we're back to
square one.

    Well, the way to get around this is to have a script put everything
back after an install is done.  The more sharp-eyed of you out there may
have noticed a file called "reset-grub" in the directory listing above.
Here it is:

#!/bin/sh
#
# First, Fedora Core (which is in hd0,0/hd1,0)...
#
/sbin/grub --batch <<EOT
root (hd0,0)
setup (hd0,0)
root (hd1,0)
setup (hd1,0)
EOT
#
# Next, RHEL (which is in hd0,1/hd1,1)...
#
/sbin/grub --batch <<EOT
root (hd0,1)
setup (hd0,1)
root (hd1,1)
setup (hd1,1)
EOT
#
# Finally, the MBR (which is in hd0/hd1, with the root in )...
#
/sbin/grub --batch <<EOT
root (hd0,4)
setup (hd0)
root (hd1,4)
setup (hd1)
EOT

So, whenever I do a fresh install, I simply boot into the newly-installed
OS (which is the only thing I can boot into at that point -- and probably
the only thing I *want* to boot then, anyway) and rerun this script.  Once
it completes, my original boot setup is back the way I want it.

    A few notes about the script:

        o The script could probably do everything in one invocation of
          grub, but the testing started with one entry, and I just did a
          cut'n'paste, yadda, yadda...

        o Remember when I said that I had a software RAID configuration?
          That's why each grub invocation has two "root"/"setup" commands;
          this ensures that I can boot from either drive should the other
          one fail.  If you don't use RAID, you only need one "root" and
          one "setup" command for each OS.

        o The device specifications are almost certainly guaranteed *not*
          to be correct for your configuration.  (yeah, I know -- duh --
          but you wouldn't believe the stuff some people will blindly run)

    If anyone decides to play with this, I strongly suggest reading up on
grub device specification and make sure you understand it before
proceeding.  I also strongly suggest you make a boot diskette for at least
one of your operating systems before proceeding; that way, it'll be easier
to recover, should any problems arise.

    You can also do some experimenting before implementing the whole thing
by taking one of your OSes, manually installing its grub configuration in
the first sector of its /boot partition, and then booting from it.  To do
this, just run grub interactively, issue the appropriate "root" and "setup"
commands, and then reboot.  When you get to your regular grub screen (the
one started from the MBR), use the appropriate command (can't remember what
it is right now; it's mentioned in the text under the list of available
boot entries) to enter grub commands, and then enter the appropriate "root"
command, followed by a "boot" command.  You should see the grub screen for
the OS you just installed in the first sector of the /boot partition.  You
can then do this for the other OS, and then manually set up the new MBR
grub configuration.

                    Hope this helps,

                            Ed
-- 
Ed Bailey        Red Hat, Inc.          http://www.redhat.com/





More information about the test mailing list