Building a Kernel

After you finish configuring the kernel with make xconfig or some other command, it's time to build the kernel. Wth 2.4.x kernels, you should first type make dep. This command tells the system to search through the kernel configuration and files to locate dependencies—files that depend on other files to compile or link. If you fail to perform this step, the kernel may not compile completely. Most 2.5.x and later kernels don't need this step, though. Kernels sometimes also fail to compile if old files from previous failed compilations exist. You can rid yourself of such files by typing make clean, which removes these files. This command deletes intermediate compilation files, which can be helpful if you need to clear some space on the partition that holds the Linux kernel source code tree.

You actually compile the kernel by typing make followed by a name for the kernel. Several names are available, and they produce distinct results:

vmlinux This make target is in many respects the simplest; it creates a kernel file called vmlinux in the kernel source root directory. This is the preferred target for some non-IA-32 platforms.

zlmage This target used to be common, but it is now rare. It creates a compressed kernel image for IA-32 systems, known as zlmage and stored in arch/i386/boot. This kernel relies on a series of tricky operations during the boot process, though, and as a result there's a maximum size limit for such kernels. Most 2.4.x and later kernels are too large for these operations, so make zlmage isn't used much any more.

bzlmage This target is the preferred one for IA-32 systems. It creates a compressed kernel image, called bzlmage and stored in arch/i386/boot.

bzdisk This target creates a bootable IA-32 floppy disk. The disk is formatted using the File Allocation Table (FAT) filesystem and uses the Idlinux.sys boot loader to boot Linux from floppy. To use this command, you should first insert a blank floppy disk in your floppy drive and type make bzdisk.

rpm This target creates an RPM Package Manager (RPM) file containing the kernel, its modules, and a few support files. The resulting RPM file is stored in your RPM package directory, /usr/src/distname/RPMS/arch, where distname is a distribution-specific name and arch is an architecture code, such as ¡386 or ppc. The main kernel file in this package is called /boot/vmlinuz-a.£>.c. You can treat it like a vmlinux or bzlmage kernel file. The rpm target is most useful if you want to build a kernel that you plan to install on several other RPM-based computers.

The most typical method of building Linux is to type make bzlmage or, on some platforms, make vmlinux. You can then build the kernel's modules, as described in the next section, "Building Kernel Modules," and install the kernel and its modules, as described in the upcoming section, "Installing a Kernel."

When you use any of these methods, the make utility runs a series of commands to compile the kernel, link it, and possibly process it further. You'll see a series of compilation commands, most of which use gcc, scroll past on your display. If all goes well, these commands will complete with lines that describe where the kernel file has been stored. This process may take anywhere from a few minutes to many hours, depending on the speed of your CPU and the options you've picked. On modern computers, compilation is likely to take well under an hour.

Occasionally, compilation fails. If this happens, you'll see an error message. Such problems can be hard to track down. They're sometimes caused by errors in the source code itself, particularly if you're compiling a development kernel. More often, your configuration is strange—for instance, you might have added options without adding other options upon which the first depends. The configuration tools are designed to prevent such things from happening, but sometimes they fail. Another potential source of problems, at least with 2.4.x kernels, is the failure to type make dep before making the kernel. Missing development tools can also cause problems. Whatever the cause, sometimes typing make clean and then trying again will correct the problem, but sometimes you'll have to examine the error message and hope it presents a clue. You may have luck by removing a driver that's mentioned in the error message (assuming it's not really necessary for basic system functionality) or by reconfiguring how that module is compiled (setting it to compile into the kernel rather than as a module, for instance).

Note An ordinary user can compile a kernel if the user has full write access to the kernel source directory tree. Installing the kernel normally requires root access, though.

0 0

Post a comment