Learning to compile the kernel-a beginner's guide

Source: Internet
Author: User
Article Title: Learning to compile the kernel-A Beginner's Guide. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
In general, it is a little difficult for beginners to compile the kernel. it is also a test for beginners like me. After all, time and energy are limited. I don't have time to read all the documents of the kernel, and I can't fully understand it. If your reality is similar to me and you don't know much about Kernel Compilation, or you haven't compiled it. Let's take a look at the article I wrote;
  
In fact, the most time spent in compiling the kernel is not the compilation process, but the configuration and troubleshooting process. Therefore, we can use the slackware kernel configuration file to save the time for this process. What is the saving time ?? Do what you want to do. haha.
  
Use the Slackware kernel configuration file to compile your own kernel. you can use this method no matter what release version you use;
  
Why should I use the slackware kernel configuration file to compile the kernel suitable for my machine ??
  
The server load balancer kernel configuration files are all ready-made and have been configured. They also run extremely stably in server load balancer. It is the best teaching material for novice siblings who do not configure the kernel. In addition, the kernel compiled by the Slackware configuration file is not too large.
  
In fact, the purpose of writing this article is to allow new users to learn kernel configuration in the shortest time;
  
This article is suitable for beginners;
  
Note: the kernel version must correspond to the configuration kernel configuration file provided by Slackware. if you do not understand it or your expression is inaccurate, just do what I said;
  
Practice Environment: Fedora core 4.0
  
++ ++
Body:
++ ++
  
   1. download the source code of the official current testing kernel;
  
Address: http://www.slackware.com/getslack/
  
Find the image from the address above. Generally, the US and Japan are faster;
  
For example, we get the source code directory of testing kernel linux-2.6.12.3 through the address below;
  
Ftp://slackware.mirrors.tds.net/pub...linux-2.6.12.3/
  
We want to download the linux-2.6.12.3 under the linux-2.6.12.3.tar.bz2 directory, then download the config-2.6.12.3
  
The download is complete. let's proceed to the next step;
  
   II. use Slackware's official config-2.6.12.3 file to easily configure your own kernel configuration file. config;
  

1. decompress the kernel and perform some basic work;
  
Bash-3.00 # tar jxvf linux-2.6.12.3.tar.bz2
Bash-3.00 # mv linux-2.6.12.3/usr/src move the unzipped kernel to the/usr/src Directory
Bash-3.00 # cd/usr/src
  
Bash-3.00 # ls-lh
  
Drwxr-xr-x 3 root 4.0 K August 3 12:49 kernels
Drwxr-xr-x 19 root 4.0 K August 7 16:33 linux-2.6.12.3
Drwxr-xr-x 7 root 4.0 K August 3 12:27 redhat
  
Bash-3.00 # cd linux-2.6.12.3
Bash-3.00 # pwd
/Usr/src/linux-2.6.12.3
  
The next step is to copy the downloaded config-2.6.12.3 file to/usr/src/linux-2.6.12.3, and then copy it to the. config file.
Bash-3.00 # cp config-2.6.12.3. config replicate config-2.6.12.3 to. config
  
2. briefly configure the kernel;
  
Bash-3.00 # make menuconfig enters the kernel configuration mode;
  
There are two kernel configuration methods: one is directly placed into the kernel [*]; the other is compiled into a module [M]; the two methods have their own advantages; directly compiled into the kernel, for example, when a device starts, the module does not need to be loaded; when compiled into a module, the module supported by the kernel of the device needs to be loaded; however, it is not feasible to directly compile everything into the kernel. the kernel size will increase and the system load will be too heavy. When compiling the kernel, it is best to include the most important data into the kernel. if you do not understand anything else, you 'd better use the default value. Slackware kernel configuration file is the best tutorial;
  
1] move the keyboard, select the Load an Alternate Configuration File item, and call. config to facilitate our Configuration. because this Configuration File is configured by Slackware, we just need to modify it a little.
  
2] modify the existing problems of your machine. for example, we mentioned the large memory support problem in the previous article;
  
Select the CPU of your machine;
  
Move the keyboard to Processor type and features ---> and press ENTER;
  
Find Processor family (486) ---> press ENTER to ENTER;
  
After entering, we found that there are a lot of CPU models available; in general, according
  
Bash-3.00 # select the output information of cat/proc/cpuinfo. for example, if we are from the Celon (P4) generation, we should select the following, of course, the default 486 version can also run normally. since we re-compile the kernel, we have to select the corresponding model, which may improve the performance;
  
Processor family (Pentium-4/Celon (P4-based)/Pentium-4 M/Xeon)
  
Supports large memory. if the memory is 1 GB or above, but less than 4 GB, 4 GB is required. if the memory exceeds 4 GB, 64 GB is required;
  
High Memory Support (4 GB) --->
  
(X) 4 GB
() 64 GB
  
There are also hardware such as sound cards that need to be viewed step by step. if there is something unknown, we need to press [shift] +? To view the description. In general, the config file of slackware has been configured. you just need to check it.
  
Another example: for example, if I use intel ac97 sound card, how should I configure it?
  
First, you need to know the chipset of your sound card. we need to check it through lspci-v;
Bash-3.00 # lspci-v
  
To view only the sound card, use the following method:
Bash-3.00 # lspci-v | grep audio
00: 1f. 5 Multimedia audio controller: Intel Corp. 82801DB (ICH4) AC'97 Audio Controller (rev 03)
  
Through the above output, we know that this machine uses the intel AC97 sound card, so we should pay special attention to the AC97 configuration;
  
Find Device Drivers ---> Sound --->
   Sound card support. this must be selected;
   Advanced Linux Sound Architecture supports the ALSA driver supported by the Sound card. The OSS driver is provided below, which is only a part. If you want to use a more comprehensive OSS driver, you can buy it. for other options, see the following;
   Sequencer support
   Sequencer dummy client
   OSS Mixer API
   Oss pcm (digital audio) API [*] OSS Sequencer API
   RTC Timer support [*] Verbose printk
[] Debug
  
Then let's look down at
Generic devices ---> enter
   Dummy (/dev/null) soundcard
   Virtual MIDI soundcard
   MOTU MidiTimePiece AV multiport MIDI
   UART16550 serial MIDI driver
   Generic MPU-401 UART driver
ISA devices ---> select this option if you use the ISA sound card;
PCI devices ---> If you use the PCI sound card, select it here, and the integrated sound card is also here;
USB devices ---> This is an option supported by the USB sound card kernel. I have such a sound card, but I have not tried it;
PCMCIA devices ---> This is the option of PCMCIA sound card. I have not seen such a sound card yet. if you have one, click here.
  
Because I use an Intel integrated sound card, we can see two INTEL-related sound cards in PCI;
  
   Intel/SiS/nVidia/AMD/ALi AC97 Controller. this is the Intel AC97 sound card;
<> Intel/SiS/nVidia/AMD MC97 Modem (EXPERIMENTAL) is an INTEL cat buzzer integrated with machines;
  
I found that two conflicts may occur if the driver of the buzzer of the cat is selected. So you can only select the one above;
  
Let's go back to Open Sound System ---> and see if it is related to my Sound card?
   Open Sound System (DEPRECATED)
   Intel ICH (i8xx) audio support
   OSS sound modules
   Loopback MIDI device support
   Microsoft Sound System support
  
We can also see that there are also a lot of Sound card drivers in the Open Sound System. let's choose based on the previous lspci-v.
  
3] Support for the file system used by the operating system should be compiled into the kernel. it is best not to compile the file system into modules. (important)
  
For example, my Fedora core 4.0 file system uses ext3, so I want to compile it directly into the kernel. the advantage is that the system cannot be started without the loss or damage of modules; sometimes, when you compile the file system used by the system into a module, a VFS error occurs, it may be because you have not added ext3 to the configuration file of the corresponding loading module. therefore, to reduce the trouble and minimize the risk, you must directly place it in the internal model;
  
File systems --->
<*> Ext3 journalling file system support
[*] Ext3 extended attributes
[*] Ext3 POSIX Access Control Lists
[*] Ext3 Security Labels
  
If you have other hard disk partitions to read, such as reiserfs, ext2, fat, fat32, and ntfs, such partitions can be compiled into modules;
  
Another example: if your operating system uses the reiserfs file system, of course, you must directly compile the reiserfs file system into the kernel. other files can be compiled into modules for support;
  
4] hard disk and RAID support should be directly compiled into the kernel;
  
For example, ATA, SATA, SCSI, and RAID support are directly supported by the kernel. sometimes, after the kernel is compiled, the hard disk and RAID cannot be identified during startup. most of the work is here; some modules are supported in Slackware. we can Changed to <*>. if you do not understand it, use the default setting;
  
5] for devices we don't have, we can leave them out of the kernel, which makes perfect;
  
For example, if I do not have an ISDN device, I will remove the ISDN device;
ISDN subsystem --->
<> Linux telephony support
  
If you do not have a 1394 device, you can remove the 1394 support;
And so on .......
  
There are so many kernel configurations, too many. I cannot tell them clearly, and the level is limited;
  
Save the configuration
  
Save Configuration to an Alternate File
  
One
  
Enter a filename to which this configuration, shocould be saved as an alternate. Leave blank to abort.
. Config
  
Press enter to save it;
  
Then Exit <Exit>, and save the file;
  
If you want to save. config, you can copy it to a safe directory for later use;
  
3] compile the kernel
  
Bash-3.00 # make
Bash-3.00 # make modules_install
  
In this way, the compilation is completed, and the module is also installed in the/lib/modules Directory. please refer:
  
Bash-3.00 # ls/lib/modules/
  
2.6.11-1.1369 _ FC4 2.6.12.3
  
4] install the kernel for Fedora core 4.0;
  
Bash-3.00 # cp arch/i386/boot/bzImage/boot/vmlinuz-2.6.12.3
Bash-3.00 # cp System. map/boot/System. map-2.6.12.3
Bash-3.00 # cd/boot
Bash-3.00 #/sbin/mkinitrd initrd-2.6.12.3.img 2.6.12.3 this is used to innovate the initrd image, do not create this file, sometimes cannot start up, such as prompt VFS errors;
  
4. view the configuration file of grub or lilo in the system boot manager.
  
If you want the new Inner nuclear energy to be visible on the grub and lilo menus of the system boot manager, you must change grub. conf or lilo. conf, but we must keep the boot menu of the old kernel in grub and lilo. after all, we cannot make the kernel a hundred percent success, right ?? Security first;
  
I only talk about grub. I don't have lilo, and I won't use it. So let's go to GRUB.
  
View/etc/grub. conf;
  
For example, the content of my grub. conf is like this;
  
Code:
# Grub. conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a/boot partition. This means that
# All kernel and initrd paths are relative to/, eg.
# Root (hd0, 7)
# Kernel/boot/vmlinuz-version ro root =/dev/hda8
# Initrd/boot/initrd-version.img
# Boot =/dev/hda
Default = 0
Timeout = 5
# Splashimage = (hd0, 7)/boot/grub/splash.xpm.gz
# Hiddenmenu
Title Fedora Core (2.6.11-1.1369_FC4)
Root (hd0, 7)
Kernel/boot/vmlinuz-2.6.11-1.1369_FC4 ro root = LABEL =/rhgb quiet
Initrd/boot/initrd-2.6.11-1.1369_FC4.img
Title WinXP
Rootnoverify (hd0, 0)
Chainloader + 1
  
We need to keep the startup of the old kernel to prevent unexpected events. we only need to add the startup of the new kernel, so I will add such a paragraph;
  
Title Fedora Core (2.6.12.3)
Root (hd0, 7)
Kernel/boot/vmlinuz-2.6.12.3 ro root = LABEL =/rhgb quiet
Initrd/boot/initrd-2.6.12.3.img
  
Let's take a look at the modified configuration file;
  
Code:
# Grub. conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a/boot partition. This means that
# All kernel and initrd paths are relative to/, eg.
# Root (hd0, 7)
# Kernel/boot/vmlinuz-version ro root =/dev/hda8
# Initrd/boot/initrd-version.img
# Boot =/dev/hda
Default = 0
Timeout = 5
# Splashimage = (hd0, 7)/boot/grub/splash.xpm.gz
# Hiddenmenu
  
Title Fedora Core (2.6.12.3)
Root (hd0, 7)
Kernel/boot/vmlinuz-2.6.12.3 ro root = LABEL =/rhgb quiet
Initrd/boot/initrd-2.6.12.3.img
  
  
Title Fedora Core (2.6.11-1.1369_FC4)
Root (hd0, 7)
Kernel/boot/vmlinuz-2.6.11-1.1369_FC4 ro root = LABEL =/rhgb quiet
Initrd/boot/initrd-2.6.11-1.1369_FC4.img
Title WinXP
Rootnoverify (hd0, 0)
Chainloader + 1
  
Then restart the machine. if a VFS error occurs, it may be that an error occurs in the important part of my writing;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.