
GRUB in Debian HOWTO, Version 1.0 Published by LinuxOrbit.com, October 18, 2002
by Dan "overridex" McCombs
Introduction
Why use GRUB instead of LILO? Well, if you're reading this HOWTO, you're likely to already have your reasons for switching. But to give a couple quick reasons, you only install GRUB in your MBR once, it doesn't need to be reinstalled each kernel change like LILO, and you can also edit the boot entries, etc. from GRUB itself without having to boot first and change the config file. These are just some of my reasons, you can find more for yourself - but how do you set it up the Debian way? This HOWTO will show you how to install the GRUB bootloader, configure it, create GRUB boot floppies and keep your GRUB configuration up to date with your latest installed kernels easily. Here are a few pre-requisites you should already have before you continue:
- Internet connection (dialup or lan) for apt-get'ing packages
- floppy(s) for boot floppy (optional)
- Know your system partition info (for example, knowing /dev/hda1 is
Debian, /dev/hda2 is Red Hat, /dev/hda3 is your Windows install)
- Debian 3.0 (woody) or newer
- rescue disk in case anything goes wrong!
Installation
First, you need to install the grub package and then install it to your MBR.
apt-get install grub
Now, assuming your boot device is /dev/hda:
grub-install /dev/hda
or if /boot is a separate partition:
grub-install --root-directory=/boot /dev/hda
*Please note you'll need to re-run the grub-install command when you upgrade the grub package in order to install the new GRUB on your MBR.
This command will create your initial menu.lst for you if it doesn't exist:
update-grub
Configuring GRUB
Now that GRUB is installed you need to edit your /boot/grub/menu.lst (or if /boot is a separate partition /boot/boot/grub/menu.lst). You'll need to change groot to the root device, where your /boot directory is stored - so your root partition or your /boot partition if it's separate:
# groot=(hd0,0)
GRUB has a little different way of specifying devices, hd0,0 would be hda1, hd1,1 would be hdb2, it's not too hard, you can figure this out.
You'll also want to edit kopt, which sets default kernel options for all kernel entries that update-grub generates, like:
# kopt=root=/dev/hda1 ro
or
# kopt=vga=791 ro hdb=ide-scsi hdd=ide-scsi
The first kopt shown here specifies the root partition and that it should be mounted in read-only mode. The Second line would set your framebuffer console to 1024x769 resolution and enable scsi-emualtion on devices hdb and hdd. Please note that these options that are commented out like groot and kopt are used by the Debian script update-grub to generate the real menu entries, they are not used by GRUB directly and need to be left commented.
If you have Windows or another distro on another partition, you can add them to menu.lst yourself, just make sure the entries are either before the line:
### BEGIN AUTOMAGIC KERNELS LIST
or after the line:
### END DEBIAN AUTOMAGIC KERNELS LIST
Doing this protects the entries from being overwritten by the update-grub script, putting them before the begin line would have them before your debian entries in your menu, putting them after would make them show up after. In this next section, wer'll show you some possible extra entries that you might want to add.
This one's a pretty obvious one for windows, set the root partition to whatever partition your windows install is on:
title Windows 95/98/NT/2000
root (hd0,0)
makeactive
chainloader +1
This entry is for a Red Hat Linux install on hdb2 without a separate boot partition for it:
title Red Hat Linux Linux
root (hd1,1)
kernel /boot/vmlinuz root=/dev/hdb2 ro
This is an entry for the memtest86 ram tester:
title Memtest86 - Memory Tester
root (hd0,0)
kernel /memtest86.bin
If you want some security you can specify a password towards the top of the menu.lst file:
password fishsticks
or
password -md5 $1$lNeeW/$j3hvuNRTIPYOzJB1nB5Li0
*Note you can get this encrypted password by typing the grub command as root, then typing md5crypt, putting in a password and it will give you the crypted string to use.
If you do this, the password will need to be put in to get a prompt from GRUB, also you can lock certain entries so they can't be booted without the password - for your extra entries add the word lock on a separate line right under the title like this:
title Red Hat Linux Linux
lock
root (hd1,1)
kernel /boot/vmlinuz root=/dev/hdb2 ro
Also, setting the Debian script option:
# lockalternative=true
will cause the update-grub script to lock an alternate entries it generates, by default the alternatives are your kernels in single mode, which you might want to keep people from using without a password. Feel free to edit other options in the file how you like, such as the timeout option which specifies how many seconds to wait before booting the default entry, after you're finished run update-grub to update the entries in menu.lst
Creating a GRUB boot floppy
If you want to create a boot floppy that uses GRUB you can do so like this:
cat /boot/grub/stage1 /boot/grub/stage2 > /dev/fd0
or if you have a separate boot partition:
cat /boot/boot/grub/stage1 /boot/boot/grub/stage2 > /dev/fd0
When you boot from this floppy it'll give you a GRUB prompt, which you can use to boot a kernel off your hard drive:
root (hd0,0)
This is the device that has the kernel you want to boot - in my case it's my /boot partition /dev/hda1, which GRUB sees as hd0,0.
kernel /vmlinuz-2.4.19-jp14 root=/dev/hda3 vga=791
This line sets where the kernel is located - /boot/vmlinuz-2.4.19-jp14 on my file system, but since /boot is a separate partition, and that's set as root in GRUB, it's just /vmlinuz-2.4.19-jp14. If /boot wasn't a separate partition, your image would be more like /boot/vmlinuz-2.4.19-jp14. It also sets some kernel options, in this case I set the root partition and vga=791 which gives a 1024x768 framebuffer console.
boot
The boot command is what boots you up using the options you set in the commands above. If you want to boot using a kernel off a floppy:
root (fd0)
kernel /vmlinuz-2.4.19-jp14 root=/dev/hda3 vga=791
boot?
*Note that you can hit tab after typing kernel / and it will auto complete the filename for you, in case you don't know the exact filename of the kernel.
Kernels
If you install a new kernel from a Debian package you can run update-grub to update your grub menu entries to point at the right kernel, if you build your own kernel debs with make-kpkg you can edit /etc/kernel-img.conf and add these lines:
postinst_hook = /sbin/update-grub
postrm_hook = /sbin/update-grub
do_bootloader = no
Then build your kernel deb and it'll automatically run update-grub for you when you install/remove that package.
If you install your kernel from source, I'd suggest you take a look at the make-kpkg command in the Debian package kernel-package, it's a nice way to build your kernel and keep things neat and organized, but if you symlink your kernel that you installed from source to /vmlinuz, then running the update-grub script should work for you.
ln -s /path/to/kernel /vmlinuz
Gripes
As far as I know you can't use GRUB yet with a /boot RAID partition, so with my RAID-0 using linux's software RAID I have a separate /boot partition that is not RAIDed. grub-install fails to probe the bios drives for me when using devfs, using the devfs=nomount kernel option at boot time will work around this problem, install after booting with that option, then you can reboot again without it back into your devfs setup. If you need to run the grub command while using devfs, you can do this with something like:
grub -device-map=/boot/grub/device.map
or if you have a separate /boot partition
grub -device-map=/boot/boot/grub/device.map
This will use the device map made by grub-install when you ran it with devfs disabled and avoid the probing. This might also work for grub-install when you run it to upgrade your grub (grub-install -device-map=/boot/grub/device.map /dev/hda) but I haven't tried it myself yet.
Conclusion
So, there you have it, now you can install GRUB the debian way, configure it to boot multiple linux distros and/or windows partitions, create and boot from GRUB boot floppies, and keep it's menu entries up to date with your kernels with the update-grub command, happy booting!
|