Kernel Hacking Lesson: Boot Your New Kernel
Now that you've successfully
compiled your kernel, you need to boot your new kernel. We're going to cover
booting a new kernel on three different architectures: x86, PowerPC, and Alpha.
Some similarities exist between all three, so we'll start with those.Rule number one is never ever delete your current working kernel or bootloader configuration files. Never copy your new kernel over your original kernel. You don't need to keep every kernel you ever compile, but do pick one or more "safe" kernels and keep them and their configuration files intact.
Copy your new kernel to a safe location
First, copy the new kernel you
just compiled to a safe location. I suggest using /boot/mynewkernel as the destination. If you're on x86, you
want to copy the bzImage:# cp arch/i386/boot/bzImage /boot/mynewkernel
If you're on a PowerPC or Alpha, copy the vmlinux:
# cp vmlinux /boot/mynewkernel
Booting your new kernel with LILO on an x86
LILO is the most common boot
loader for x86 machines. You are running LILO if you see "LILO:" when
you boot. We'll just go over the bare minimum of information you need to boot a
new kernel in LILO. For more information on LILO, type man lilo and man lilo.conf. You will need to be root to edit /etc/lilo.conf and run LILO.The LILO configuration file is in /etc/lilo.conf. The basic idea here is to copy the chunk of your configuration file for your current kernel and then change the name of the kernel file to boot. Remember, you are copying the information for your current kernel and changing the copy, NOT editing the original. Say you have something like this in your/etc/lilo.conf:
image=/boot/vmlinuz-2.2.14-5.0
label=linux
initrd=/boot/initrd-2.2.14-5.0.img
read-only
root=/dev/sda1The image field tells LILO where to find the file containing your new kernel. The label field is what you type at the LILO prompt to boot that kernel. It's a good idea to make the label something short and easy to type. The initrdfield is optional and specifies an initial ramdisk to load before mounting the root filesystem. The read-only field says to initially mount the root filesystem read-only, rather than read-write. The root field tells LILO which device contains the root filesystem.
You'll copy this information and change the following fields:
image=<filename of your new kernel>
label=<choose whatever name you'd like here>Remove the initrd field if it exists:
initrd=/boot/initrd-2.2.14-5.0.imgThe reason you should remove the initrd field is because the initrd file does not contain anything that would be useful to your new kernel. In a normal Linux distribution, the initrd contains a lot of kernel modules which can only be loaded by the distribution kernel. We'll talk more about initrd's when we cover ramdisks later.
The new lines you just added to your configuration file should look something like this when you're done:
image=/boot/mynewkernel
label=new
read-only
root=/dev/sda1LILO does not know that you changed anything in /etc/lilo.conf until you run the lilo command. You will probably do this more than once: compile a new kernel, copy it to the new place, forget to run LILO, and reboot only to find that LILO doesn't know about the new kernel. So, after you change the /etc/lilo.conf file, always run LILO:
# lilo -vThe -v says to be verbose about what it's doing. LILO will complain if it can't find the files you told it to use.
Now, reboot, and you'll see the LILO prompt:
LILO:Type the label you chose (what you entered in the label field) for your new kernel. LILO will then try to boot that new kernel. To avoid typing a command line into LILO, run this just before you reboot:
# lilo -v -R "<LILO command line>"This tells LILO to use that command line the next time you reboot. It then erases that command line and goes back to normal behavior the next time you reboot. This is really useful for testing new kernels, since you can boot your new kernel, see it crash, reset the machine, and automatically boot your working kernel without ever typing anything.
Booting your new kernel with GRUB on an x86
GRUB is becoming a common boot
loader for x86 machines. You are running GRUB if you see a pretty graphical
menu which lets you select which image to boot with the arrow keys when you
boot. We'll just go over the bare minimum of information you need to boot a new
kernel in GRUB. For more information on GRUB, type info grub. You will need to be root to edit /etc/grub.conf.The GRUB configuration file is in /etc/grub.conf. The basic idea here is to copy the chunk of your configuration file for your current kernel and then change the name of the kernel file to boot. Remember, you are copying the information for your current kernel and changing the copy, NOT editing the original. Say you have something like this in your/etc/grub.conf:
title Linux (2.4.9-31)
root (hd0,0)
kernel /vmlinuz-2.4.9-31 ro root=/dev/hda3
initrd /initrd-2.4.9-31.imgThe title field is the title in the GRUB menu that corresponds to your new kernel. The root field tells GRUB where your root filesystem is (your root filesystem is what is mounted at /). The kernel field tells GRUB where to find the file containing your kernel and, after the kernel filename, it gives some options to pass the kernel when it boots. NOTE: The filename of the kernel is given relative to the boot partition, which usually means that you have to remove the/boot part from the filename. The initrd field is optional and specifies an initial ramdisk to load before mounting the root filesystem.
You'll copy this information and change the following fields:
title <choose whatever name you'd like here>
kernel <filename of your new kernel> ro root=/dev/hda3Remember, you should almost certainly remove the /boot part from the filename of the kernel, unless you know what you're doing.
Remove the initrd field if it exists:
initrd /initrd-2.4.9-31.imgThe reason you should remove the initrd field is because the initrd file does not contain anything that would be useful to your new kernel. In a normal Linux distribution, the initrd contains a lot of kernel modules which can only be loaded by the distribution kernel. We'll talk more about initrd's when we cover ramdisks later.
The new lines you just added to your configuration file should look something like this when you're done:
title new
root (hd0,0)
kernel /mynewkernel ro root=/dev/hda3Note again, that in this case my new kernel is in /boot/mynewkernel, but since I have a separate partition mounted on /boot, and since GRUB will only look inside that partition when I boot, I need to take off the mountpoint part of the name, which is /boot. If I had everything, including /boot, on one big partition, then I would tell GRUB that my kernel was named /boot/mynewkernel.
Now, reboot, and you'll see the GRUB menu. Select the title you chose earlier with the arrow keys and hit enter. GRUB will now try to boot your new kernel.
Booting your new kernel with yaboot and ybin on a PowerPC
Once again, we'll only cover the bare minimum to boot a new kernel under yaboot. For more information on yaboot and ybin, try man yaboot, man yaboot.conf, and man ybin. You will need to be root to edit/etc/yaboot.conf and run yaboot and ybin.The yaboot configuration file is in /etc/yaboot.conf and is very similar to the LILO configuration file. The basic idea here is to copy the chunk of your configuration file for your current kernel and then change the name of the kernel file to boot. Remember, you are copying the information for your current kernel and changing the copy, NOT editing the original. Say you have something like this in your /etc/yaboot.conf:
image=/boot/vmlinux-2.2.15-2.7.0
label=linux
root=/dev/hda10
novideoThe image field tells yaboot where to find the file containing your new kernel. The label field is what you type at the yaboot prompt to boot that kernel. It's a good idea to make the label something short and easy to type. The root field tells LILO which device contains the root filesystem. The novideo field works around a bug on some PowerMacs, and may or may not be necessary on your system. Just copy a yaboot entry that works for your particular machine.
After you copy this information, change the following fields:
image=<filename of your new kernel>
label=<choose whatever name you'd like here>The new lines you just added to your configuration file should look something like this when you're done:
image=/boot/mynewkernel
label=new
root=/dev/hda10
novideoNext, run ybin if you have it. Ybin is a helper program that takes care of copying all the necessary files to the bootable partition, running yaboot, and all the little details that Apple's schizophrenic Open Firmware requires for booting a kernel. If you don't have ybin, consult the yaboot man page, man yaboot, for information about what you need to do.
Booting your new kernel with SRM on an Alpha
Note: These instruction were
written without the benefit of an Alpha to test them on.SRM is the firmware installed on most Alpha's. SRM can boot a kernel from an ext2 filesystem as long as the disk has a BSD disklabel. All you really have to do is put your new kernel in the same directory as your current kernel (for simplicity), reboot, and boot substituting your new kernel name for the old kernel name.
You should already know how to boot your old kernel from the SRM prompt. All you need to do is change the name of the kernel file to the name of your new kernel file. The easiest way to do this is:
$ show boot_file
$ set boot_file <your new kernel filename>If your old kernel is in /boot/vmlinux, and your new kernel is in /boot/mynewkernel, and show boot_file says this:
2/boot/vmlinuxThen you would type:
set boot_file 2/boot/vmlinux(The "2" at the beginning of the filename tells SRM to look in the second partition of the boot device.)
Troubleshooting booting
At this point, if your kernel
doesn't boot, reboot into your old kernel (this is why you never overwrite your
old kernel or configuration) and try to figure out what's gone wrong.A good way to troubleshoot is to start out by copying the lines for your current kernel from your bootloader's configuration file and only changing the label or title of the entry. See if you can boot that kernel (and initrd, if it has one). Once you're sure that's working, then try substituting the name of your new kernel (and removing the initrdentry, if there is one). At this point, you can be fairly sure that it's your kernel that doesn't boot, rather than a problem in your bootloader configuration.
No comments:
Post a Comment