Both exercises have a range of possible solutions. You should be able to evaluate your own success, particularly for the first exercise, by determining whether you can boot from the modified entry you create. The second exercise is more open ended in nature, but you should take the time to familiarize yourself with the major GRUB boot-time options.
Solutions for exercise 1. Add a new kernel to a GRUB configuration
One good way to create a new GRUB entry is as follows:
- Load your existing GRUB configuration file (/boot/grub/grub.conf
or /boot/grub/menu.lst) into your favorite text editor.
Listing 1 shows a sample configuration file for reference.
Listing 1. An example GRUB legacy configuration file
default=0 timeout=60 splashimage=(hd0,0)/grub/splash.xpm.gz #hiddenmenu title Fedora (126.96.36.199-9.fc15.x86_64) root (hd0,0) kernel /vmlinuz-188.8.131.52-9.fc15.x86_64 ro root=/dev/sda3 rhgb quiet initrd /initramfs-184.108.40.206-9.fc15.x86_64.img
- If you're booting a new kernel such as one you've compiled yourself,
you could have installed it first by copying the kernel image to /boot
make modules_installin the kernel source directory to install the kernel modules.
Alternatively, to test your skill by booting your current kernel from a different location, you can copy it and its associated initial RAM disk file to another partition or hard disk.
Tip: Using a USB flash drive with an activity LED enables you to confirm visually that the kernel is loading from this location when you reboot.
- Using your text editor, select, copy, and duplicate the entry for a Linux
kernel, such as the last four lines of Listing 1.
Be sure you do not overwrite or replace any working entry you want to keep. You can then begin modifying your duplicated entry. The result might resemble the following:
title My Test Kernel root (hd1,0) kernel /bzImage-2.6.39 ro root=/dev/sda3 rhgb initrd /initramfs-2.6.39.img
This example has made several changes from the original:
titleline is different, so that you can distinguish between the original and the modified entries.
rootline is different: It refers to the first partition on the second disk rather than the first partition on the first disk. Such a change is only required if you're booting from a kernel that you've placed somewhere other than the same partition the original entry uses.
kernelline refers to a different kernel. This example might be appropriate if you had compiled your own kernel locally, because
bzImageis a file name that's often used for locally compiled kernels.
quietoption has been removed. This option has the effect of minimizing textual screen output, so by removing it, the boot produces more verbose output.
initrdline refers to a new file. This change is matched to the change to the kernel file.
Of course, your own changes are likely to be different from these in detail; this example
is meant to illustrate some of the things you can change, not those you
must change. One key point, though, is that you should ensure that
timeout value is large enough for you to have
time to use the GRUB menu when you reboot. You should also ensure that the
hiddenmenu option is not present in the
global options section. If it is, delete it or comment
it out by placing a hash mark (
#) at the start of its
line, as in Listing 1.
The real test is whether you can reboot the computer using your modified GRUB entry:
shutdown -r nowas root (or reboot using graphical user interface [GUI] options or an equivalent text-mode command).
When the computer restarts, you should see your modified GRUB menu, including the new entry you created.
- Select the new entry, and your computer should boot normally.
If your modified entry serves no real purpose, delete it when you're done with this exercise, lest it create confusion in the future.
Solutions for exercise 2: Modify GRUB options at boot time
Interacting with GRUB at boot time requires rebooting your computer, so you should have begun by doing so, just as you did to test your modified GRUB configuration. The resulting GRUB menu might resemble Figure 1. Note the prompts in the bottom half of the display, which tell you what actions you can take.
Figure 1. A typical GRUB legacy menu lets you select a kernel from a text-mode list.
Editing the kernel options is the simplest of the editing features you can use: Type
a to do this. Typing
produces an editor that enables you to edit any line of an entry (except for the
title line), so you can change initial RAM disk options,
if you like. Figure 2 shows this window.
Figure 2. GRUB's editor enables you to make one-boot changes to your GRUB configuration.
Experiment with the GRUB editor. Feel free to make changes that you know will not
work. The changes you make here will not be saved permanently. One
change you can make that's an easy test is adding
to the kernel options, which has the effect of booting the computer into single-user
mode and is easy to identify.