Convert Microsoft to LINUX: Intro to GRUB (Multiboot)
Introduction to Multiboot (GRUB)
Here,
is a brief document I presented to the Bellevue Linux Users Group
introducing GRUB. It is a good starter for the technical information that
follows. Warning, do not mix Partition Magic, System commander or other
boot managers with GRUB. There should be only one boot manager, as in
only one boss.
This is an example of how to boot multiple Linux systems on one machine.
Start off by picking one system to install and taking all the default
options. In this case, I started with the Ubuntu Warty Hog GNOME version.
I simply let it do the formatting on a 60 Gigabyte hard drive.
It decided to put everything in one partiion of 60 Gigabytes and also
make this partition the primary boot partition. This is not the most ideal
way to do it. You could make this a lot stronger by having a partition for
the /boot directory, for the / (root) directory and for the
/home directory.
Since I am installing eight operating systems on this machine, I chose not to
do that. This was the menu.lst file that was created as a result of
this located in /boot/grub directory:
# grub.conf generated by anaconda
# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.
## default num
# Set the default entry to the entry number NUM. Numbering starts from 0
default 0
## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 10
## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu
# Pretty colours
#color cyan/blue white/blue
# This entry automatically added by the Debian installer for an existing
# linux installation on /dev/hda1.
title GNOME Warty Hog Ubuntu, kernel 2.6.8.1-3-386 (on /dev/hda1)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro quiet splash
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
# linux installation on /dev/hda1.
# This entry automatically added by the Debian installer for an existing
# linux installation on /dev/hda1.
title GNOME Warty Hog Ubuntu, kernel 2.6.8.1-3-386 (recovery mode) (on /dev/hda1)
root (hd0,0)
kernel /boot/vmlinuz-2.6.8.1-3-386 root=/dev/hda1 ro single
initrd /boot/initrd.img-2.6.8.1-3-386
savedefault
boot
To continue to install operating systems we must do the following:
- Allocate enough space for the next operating system. I used 8
Gigabyes and the
GNOME Partition Editor
. Note, all partitions were formatted using the ext3 native
Linux File system. I simply made the first partition of 8 Megabytes bootable
primary and continued adding more 8 Megabyte logical partitions. I did
not reformat the primary parition as it already had
Ubuntu Linux on it. However,
I did resize it to 8 Gigabytes. I also recreated a swap
partition of 1 Gigabyte on /dev/hda5 . This was done automatically
by the install of Ubuntu.
-
Next I installed the second operating system of Kubuntu ,
a newer version of Ubuntu using the KDE Desktop.
This only took 15 minutes. Do the custom partitioning and mount
the root (/) on the next logical partition.For me this was
partition /dev/hda6 as /dev/hda5 was the shared swap
partition for all the Linux operating systems.
-
Be sure to not overwrite the MBR (Master Boot Record) when you
are prompted for installing the boot loader using GRUB. However, if you do
you can always reboot into whatever operating system is current and
log in as root. Then type:
cd /boot/grub
vi menu.lst
You can then edit the menu.lst file using vi (Visual Editor)
to match the appropiate logical device for that version of Linux.
If you are not comfortable with vi , you can use something else.
-
The next step is to go back to the GNOME Partition Editor and make sure
the appropiate space is allocated in the next logical drive for the next
operating system. Click
here
to see a picture of how the hard drive was partitioned.
-
When you are all done you should have something like this:
menu.lst
for six different Linux Operating Systems, one Microsoft Windows XP
and one Solaris.
If eight is a little, much for you here is an example with just two operating sytems:
Windows XP and Suse Linux :
menu.lst
Here is a further example with seven Linuxes, one MS Windows XP and
NO Solaris:
menu.lst without Solaris
-
Note, the last system installed was Feisty Ubuntu
-
There is one last step here of creating a boot floppy with
GRUB on it and your menu.lst .
Put a disk in your floppy drive and type:
fdformat /dev/fd0
mke2fs /dev/fd0
in Red Hat or Centos type
grub-install '(fd0)'
cp /boot/grub/menu.lst /mnt/floppy/grub/menu.lst
Note for some systems the directory for the mounted floppy is:
/media/floppy instead of /mnt/floppy so change
the above line accordingly.
To test, reboot with the floppy and you should get the same menu you
are used to.
If you get the error 602 no disk boot record it means that the
mbr (Master Boot Record) was not created on the floppy.
-
Here is another way to create the boot GRUB floppy that should be
fool proof. As above type
fdformat /dev/fd0
mke2fs /dev/fd0
Now mount the floppy and create a directory called /boot
and /boot/grub .
Let us assume you are using Suse Linux .
mount /dev/fd0 /media/floppy
cd /media/floppy
mkdir boot
cd boot
mkdir grub
cd grub
You should now be in the directory of
/media/floppy/boot/grub
now type: cp /boot/grub/* .
Note, this is overkill, all you really need is the menu.lst
stage1 and stage2 files.
Finally type: grub to launch the grub program. Then type:
grub> root (fd0)
grub> setup (fd0)
grub> quit
You should see something saying sucessfully done .
-
Ok, to be totally fair with all this GRUB stuff,
you can even boot with Microsoft Windows operatings system too!
Let me defer to a colleague and friend Ivan Kanis, who can show you how
here.
-
I actually installed Microsoft Windows XP so the procedure was
slightly different. First I took the Ubuntu that was on
/dev/hda1 and moved it to /dev/hda2 using the
Gnome Editor mentioned earlier. I changed the menu.lst
file to reflect the new locattion for Ubuntu and all worked fine. I then
created two FAT-32 partitions, one on device /dev/hda1
the boot partition and one on /dev/hda12 which
will hold the Microsoft Windows XP. In order for the hard drive to boot
into this first primary petition, I needed to install DOS on it. I
installed
FREE DOS . I then typed:
sys c:
Microsoft Windows XP installed fine, thinking my machine had only two drives
of C: which is the primary boot drive containing the files to
launch Microsoft Windows XP and D: on /dev/hda12 where
Microsoft Windows XP is actually installed to. The last step is to
reinstall grub on the hard drive using:
grub-install /dev/hda
You may get an error saying /usr/lib/stage1 not found
In that case simply type this:
cp /boot/grub/sta* /usr/lib
Enjoy!
Lastly, for you MAC folks , there is a yaboot loader which works
almost identically to the GRUB bootloader . In order to use it, you have to:
- Go back to your MAC install disk and format two HFSPLUS partitions. The first
one will be for Linux (Ubuntu) and the second one will be for the MAC OSX operating
system. You can use the Partitioner on the MAC Install disk to do this.
-
Next install your MAC operating system.
-
Put the Ubuntu or other MAC PowerPC disk in the CD drive and reboot holding down the
'c' key to force a boot off the CD.
-
As part of the Linux Ubuntu install a GParted will appear very similar to the one used on the
PC. Format the usual Linux Swap partition, a partition of ext3 to install Ubuntu to, plus a small
partition of 1 Meg which will be converted to a Newworld Bootstrap
Partition. For now
just give this tiny 1 Megabyte partition an ext3 format.
-
Go to a terminal prompt, type sudo su and you should automatically be root. Then type:
mac-fdisk -l
You should see something like this:
/dev/hda
# type name length base ( size ) system
/dev/hda1 Apple_partition_map Apple 63 @ 1 ( 31.5k) Partition map
/dev/hda2 Apple_UNIX_SVR2 swap 1048577 @ 64 (512.0M) Linux swap
/dev/hda3 Apple_HFS MAC 100608968 @ 16622432 ( 48.0G) HFS
/dev/hda4 Apple_Bootstrap bootstrap 1600 @ 1048641 (800.0k) NewWorld bootblock
/dev/hda5 Apple_UNIX_SVR2 untitled 15572191 @ 1050241 ( 7.4G) Linux native
/dev/hda6 Apple_Free Extra 8 @ 117231400 ( 4.0k) Free space
Block size=512, Number of Blocks=117231408
DeviceType=0x0, DeviceId=0x0
Pay particular attention to /dev/hda4. Notice it now says
already NewWorld bootblock. Since
you have not yet done this, it will have a type of ext3 and will
actually be 1 Megabyte instead of 800 Kilobytes. You will have
200 Kilobytes extra when done, which can be deleted using the
mac-fdisk
as detailed below.
-
You can type now
mac-fdisk /dev/hda4 and then you will get a ? prompt.
Follow the steps as outlined in mac-fdisk devicename
here
to delete the partition that will become the NewWorld
Bootstrap partition using
the d at the ? prompt
and then create it
using the b at the ? prompt.
-
After installing Ubuntu edit the /etc/yaboot.conf file and type
defaultos=macosx
at the top.Then at a root prompt type:
ybin -v
This will install the yaboot bootloader.
Now you are done. Your yaboot.conf file should look something like
this.