-
December 2nd, 2005, 16:35 PM
#22
Old and Cranky
Super Moderator
CONTINUED
Appendix B: changing the Linux kernel
Most users will never have to mess with their kernel configuration. If you're curious about the Linux kernel and want to learn more about it, or if you need to make custom changes to the kernel for some reason, there are a few basic things you need to know.
First of all, your kernel source code is usually located in the /usr/src directory, although some distributions don't install the kernel source by default. If that's the case, you'll have to visit the distribution's Web site to get the kernel source. Alternatively you can visit kernel.org to get the source code for the Vanilla kernel. Some distributions depend on their own custom kernel modifications, so it's best to try to get the source code from your distribution's Web site rather than use the Vanilla kernel. Having the source code on your computer allows you to make the changes you want in the kernel and then rebuild it (compile it) into your operating system.
Editing and Compiling the Kernel
Once you've obtained kernel source code, unzip and untar the directory into /usr/src. The directory that is untarred should have a name like linux-2.6.11-r6 or something similar. Next, create a symbolic link from that directory to /usr/src/linux as in this example:
ln -sf /usr/src/linux-2.6.11-r6 /usr/src/linux
You can cd to /usr/src/linux or to the longer directory name. Either way, you'll end up in the same place - the symlink automatically brings you to the directory it is linked with.
Having already entered the /linux directory, to enter the kernel configuration menu, type in the following command and press enter:
make menuconfig
A graphical menu will come up with all of the options for the kernel. Use the arrow keys, space bar, and esc key to navigate it. Most commercial distributions have fairly large kernels with most (or all) of the options already selected and installed (or built as external kernel modules which are loaded when needed). This is good because it can accommodate almost any hardware you throw at it; on the other hand, more kernel options means a longer boot time and a larger kernel. If a fast boot time isn't terribly important to you, then you should leave everything alone. If you know what hardware you have and are going to use, you can experiment with disabling some of the kernel options. If you're going to be installing a new kernel from scratch, you have to take an extra step before you go into the kernel menu:
make mrproper
This command will reset your kernel options to their defaults and clean out old files from important directories. Now type in the menuconfig command as listed above, and you'll go into the kernel menu.
If you want to switch from the older 2.4 kernel to the 2.6 kernel series, there are many more steps to take. There is an excellent resource for performing this migration at this address.
There are two ways of installing an option in the kernel: you can build it as a module (denoted by an [M] to the left of the option) or build it directly into the kernel (denoted by a[*] to the left of the option). There are some options that must be built into the kernel, like support for some kinds of file systems, but for the most part you have a choice as to how you would like to build the kernel. Some experts recommend installing most things as modules because it's easier to update or remove them if necessary. If you build something into the kernel, you cannot remove it without rebuilding the kernel and rebooting the system. We recommend building everything into the kernel at first; the possible exceptions are your video and sound drivers, which you may have to obtain patches or modules for anyway. Once you become more experienced with using the Linux kernel you might find that building most options as external modules will be better suited for your situation. When you're done configuring the kernel it might be a good idea to save the configuration in case you need to build the kernel again in the future. The last option in the kernel menu is the option to save the configuration to a file. Type in a location and a name like /usr/src/backup and hit enter. This saves the configuration as a file called ``backup'' in the /usr/src/ directory. Exit the kernel menu (you'll be asked if you want to save the kernel configuration before you exit; the answer is yes) and usually you'll be told what to type in from there. The command is:
make all && make install && make modules_install
The ``&SPMamp;'' allows you to stack commands in one line. After the first command is executed, the second will immediately follow, and so on down the line. If you prefer, you can run the above commands separately rather than having them execute automatically.
By running these commands, the kernel will be built and all of the modules (if there are any) will be installed to the proper directories. Depending on the speed of your computer and how large you've made the kernel, the compile time can be anywhere from a few minutes to more than an hour.
The kernel image is automatically copied to your /boot directory upon successful compilation. If you're using the GRUB boot loader, you may have to add a menu entry for the new kernel in your /boot/grub/grub.conf configuration file, but this depends on how you have GRUB configured. If you have it configured to boot /boot/bzImage or /boot/vmlinuz or /boot/vmlinux, you won't have to change anything. If you have it set to boot specific versions of the kernel, you'll have to add your own line to grub.conf.
If you're using LILO for your boot loader, you'll need to run this command:
/sbin/lilo
This re-initializes LILO for the new kernel.
When your boot loader is reconfigured, go ahead and restart the system. To safely reboot from the command line, type this in and press enter:
reboot -n
When the system boots up again, you'll be using your new kernel.
Last edited by rik; December 2nd, 2005 at 16:52 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks