[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
slackbook:linux_kernel [2012/09/17 03:35 (UTC)] – [Working with Modules] Aded original text and formatting mfillpot | slackbook:linux_kernel [2014/10/20 04:13 (UTC)] – [Compiling A Kernel and Why to do So] nocturnal.slacker | ||
---|---|---|---|
Line 98: | Line 98: | ||
===== Compiling A Kernel and Why to do So ===== | ===== Compiling A Kernel and Why to do So ===== | ||
+ | Most Slackware users will never need to compile a kernel. The huge and | ||
+ | generic kernels contain virtually all the support you will need. | ||
+ | |||
+ | |||
+ | However, some users may need to compile a kernel. If your computer | ||
+ | contains bleeding edge hardware, a newer kernel may offer improved | ||
+ | support. Sometimes a kernel patch may be available that corrects a | ||
+ | problem you are experiencing. In these cases a kernel compile is | ||
+ | probably warranted. Users who simply want the latest and greatest | ||
+ | version or who believe using a custom compiled kernel will give them | ||
+ | greater performance can certainly upgrade, but are unlikely to | ||
+ | actually notice any major changes. | ||
+ | |||
+ | |||
+ | If you still think compiling your own kernel is something you want or | ||
+ | need to do, this section should walk you through the many steps. | ||
+ | Compiling and installing a kernel is not that difficult, but there are | ||
+ | a number of mistakes that can be made along the way, many of which can | ||
+ | prevent your computer from booting and cause major frustration. | ||
+ | |||
+ | |||
+ | The first step is ensuring you have the kernel source code installed | ||
+ | on your system. | ||
+ | //" | ||
+ | another version from [[ | ||
+ | http:// | ||
+ | Traditionally, | ||
+ | ''/ | ||
+ | points to the specific kernel release used, but this is by no means | ||
+ | set in stone. You can place the kernel source code virtually anywhere | ||
+ | without encountering any problems. | ||
+ | |||
+ | |||
+ | < | ||
+ | darkstar:~# ls -l /usr/src | ||
+ | lrwxrwxrwx | ||
+ | drwxr-xr-x 23 root root 4096 2010-03-17 19:00 linux-2.6.29.6/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | The most difficult part of any kernel compile is the kernel | ||
+ | configuration. There are hundreds of options, many of which can | ||
+ | optionally be compiled into modules. This means there are thousands of | ||
+ | ways to configure a kernel. Fortunately, | ||
+ | that can keep you from running into too much trouble. | ||
+ | configuration file is '' | ||
+ | brave, you can manually edit this file with a text editor, but I highly | ||
+ | recommend you use the kernel' | ||
+ | '' | ||
+ | |||
+ | |||
+ | Unless you are very familiar with configuring kernels, you should | ||
+ | always start with a solid base configuration and modify it. This | ||
+ | prevents you from skipping an important option that might force you to | ||
+ | compile the kernel again and again until you get it right. | ||
+ | kernel '' | ||
+ | by Slackware' | ||
+ | install disks or at your favorite mirror in the | ||
+ | '' | ||
+ | |||
+ | |||
+ | < | ||
+ | darkstar:~# mount /mnt/cdrom | ||
+ | darkstar:~# cd / | ||
+ | darkstar:/ | ||
+ | VERSIONS.TXT | ||
+ | darkstar:/ | ||
+ | System.map.gz | ||
+ | </ | ||
+ | |||
+ | |||
+ | You can replace the default '' | ||
+ | copying or downloading the '' | ||
+ | kernel you wish to use as a base. Here I am using Slackware' | ||
+ | recommended generic.s kernel for a base, but you may wish to use the | ||
+ | huge.s config file. The generic kernel builds more things as modules | ||
+ | and thus creates a smaller kernel image, but it usually requires the | ||
+ | use of an initrd. | ||
+ | |||
+ | |||
+ | < | ||
+ | darkstar:/ | ||
+ | </ | ||
+ | |||
+ | <note important> | ||
+ | |||
+ | The Slackware kernel file lacks the //" | ||
+ | includes it. If you forget, or simply copy the | ||
+ | '' | ||
+ | ''/ | ||
+ | '' | ||
+ | instead. | ||
+ | </ | ||
+ | |||
+ | If you want to use the configuration for the currently running kernel | ||
+ | as your base, you may be able to locate it at | ||
+ | ''/ | ||
+ | file that includes the entire kernel configuration in a compressed | ||
+ | format and requires that your kernel was built to support it. | ||
+ | |||
+ | |||
+ | < | ||
+ | darkstar:~# zcat / | ||
+ | </ | ||
+ | |||
+ | |||
+ | Now that we've created a solid base configuration, | ||
+ | any configuration changes we want. The entire kernel build process from | ||
+ | configuration to compilation is performed with the | ||
+ | **// | ||
+ | Each argument performs a different function. | ||
+ | |||
+ | |||
+ | If you are upgrading to a newer kernel release, you will definitely | ||
+ | want to use the // | ||
+ | your base '' | ||
+ | that usually indicates that the new kernel release contains additional | ||
+ | options. Since options are added at virtually every kernel release, | ||
+ | this is generally a good thing to do. | ||
+ | |||
+ | |||
+ | < | ||
+ | darkstar:/ | ||
+ | scripts/ | ||
+ | * | ||
+ | * Restart config... | ||
+ | * | ||
+ | * | ||
+ | * File systems | ||
+ | * | ||
+ | Second extended fs support (EXT2_FS) [M/n/y/?] m | ||
+ | Ext2 extended attributes (EXT2_FS_XATTR) [N/y/?] n | ||
+ | Ext2 execute in place support (EXT2_FS_XIP) [N/y/?] n | ||
+ | Ext3 journalling file system support (EXT3_FS) [M/n/y/?] m | ||
+ | Ext3 extended attributes (EXT3_FS_XATTR) [Y/n/?] y | ||
+ | Ext3 POSIX Access Control Lists (EXT3_FS_POSIX_ACL) [Y/n/?] y | ||
+ | Ext3 Security Labels (EXT3_FS_SECURITY) [Y/n/?] y | ||
+ | The Extended 4 (ext4) filesystem (EXT4_FS) [N/m/y/?] (NEW) m | ||
+ | </ | ||
+ | |||
+ | |||
+ | Here you can see that I the new kernel I am compiling has added support | ||
+ | for a new filesystem: ext4. // | ||
+ | original configuration, | ||
+ | set, and prompted me on what to do with new options. Typically it is | ||
+ | save to choose the default option, but you may wish change this. | ||
+ | // | ||
+ | new configuration options, making it ideal for users who simply have to | ||
+ | try out the latest kernel release. | ||
+ | |||
+ | |||
+ | For more serious configuration tasks, there are a multitude of options. | ||
+ | The linux kernel can be configured in three primary ways. The first is | ||
+ | //config//, which will step through each and every option one by | ||
+ | one and ask what you would like to do. This is so tedious that hardly | ||
+ | anyone ever uses it anymore. | ||
+ | |||
+ | |||
+ | < | ||
+ | darkstar:/ | ||
+ | scripts/ | ||
+ | * | ||
+ | * Linux Kernel Configuration | ||
+ | * | ||
+ | * | ||
+ | * General setup | ||
+ | * | ||
+ | Prompt for development and/or incomplete code/ | ||
+ | Local version - append to kernel release (LOCALVERSION) [] -test | ||
+ | Automatically append version information to the version string (LOCALVERSION_AUTO) [N/y/?] n | ||
+ | Support for paging of anonymous memory (swap) (SWAP) [Y/n/?] | ||
+ | </ | ||
+ | |||
+ | Fortunately, | ||
+ | // | ||
+ | menu-driven program that lets you select and de-select options without | ||
+ | having to step through each one. // | ||
+ | commonly used method, and the one I recommend. //xconfig// is | ||
+ | only useful if you are attempting to compile the kernel from a | ||
+ | graphical user interface within **//X//**. Both are | ||
+ | so similar however, that we are only going to document | ||
+ | // | ||
+ | |||
+ | |||
+ | Running make menuconfig from a terminal will | ||
+ | present you with the friendly curses-driven interface you see below. | ||
+ | Each kernel section is given its own submenu, and you can navigate with | ||
+ | the arrow keys. | ||
+ | |||
+ | |||
+ | {{ : | ||
+ | |||
+ | <note warning> | ||
+ | | ||
+ | If you are compiling a kernel that is the same release as the | ||
+ | stock Slackware kernel, you must set the //" | ||
+ | option. This is found on the //" | ||
+ | set this will result in your kernel compile over-writing all the | ||
+ | modules used by the stock kernels. This can quickly render your | ||
+ | system unbootable. | ||
+ | </ | ||
+ | |||
+ | Once you've finished configuring the kernel, it's time to begin | ||
+ | compiling it. There are many different methods for this, but the most | ||
+ | reliable is to use // | ||
+ | **// | ||
+ | you will see lots of data scroll through the terminal until either the | ||
+ | compile process is complete or a fatal error is encountered. | ||
+ | |||
+ | |||
+ | < | ||
+ | darkstar:/ | ||
+ | scripts/ | ||
+ | CHK | ||
+ | CHK | ||
+ | SYMLINK include/asm -> include/ | ||
+ | CALL scripts/ | ||
+ | CC scripts/ | ||
+ | HOSTCC | ||
+ | MKELF | ||
+ | HOSTCC | ||
+ | ... many hundreds of lines ommitted ... | ||
+ | </ | ||
+ | |||
+ | |||
+ | If the process ends in an error, you should check your kernel | ||
+ | configuration first. Compile errors are usually caused by a fault | ||
+ | '' | ||
+ | we're still not entirely finished, as we need to build the modules. | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | darkstar:/ | ||
+ | CHK | ||
+ | CHK | ||
+ | SYMLINK include/asm -> include/ | ||
+ | CALL scripts/ | ||
+ | HOSTCC | ||
+ | ... many thousands of lines omitted ... | ||
+ | </ | ||
+ | |||
+ | |||
+ | If both the kernel and the modules compiles finished sucessfully, | ||
+ | ready to install them. The kernel image needs to be copied into a safe | ||
+ | location, typically the ''/ | ||
+ | should give it a unique name to avoid overwriting any other kernel | ||
+ | images located there. Traditionaly kernel images are named | ||
+ | '' | ||
+ | appended. | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | darkstar:/ | ||
+ | darkstar:/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | Once these steps have been completed, you will have a new kernel image | ||
+ | located under ''/ | ||
+ | directory under ''/ | ||
+ | this new kernel, you will need to edit '' | ||
+ | create an initrd for it (only if you need to load one or more of this | ||
+ | kernel' | ||
+ | update the boot loader. When you reboot, if all went according to plan, | ||
+ | you should have an option to boot with your newly compiled kernel. If | ||
+ | something went wrong, you may be spending some time fixing the problem. | ||
====== Chapter Navigation ====== | ====== Chapter Navigation ====== | ||