Linux kernel compilation

xiaoxiao2021-03-06  69

================ Part 1: Preparation before installation =================

1. Backup Important Document Backup The following files can recover the original state in the system when errors or crashes in the system.

1. Backup kernel and launch file # cd / # tar cvzf boot.tar.gz boot 2, backup system function number header file # cd / usr / include # tar cvzf linux.tar.gz Linux 3, library file in the backup module # CD / lib / modules # tar cvzf 2.4.7-10.tar.gz 2.4.7-10 # tar cvzf 2.4.7-10debug.tar.gz 2.4.7-10Debug 4, backup Linux source # CD / USR / SRC # TAR CVZF Linux-2.4.7-10.tar.gz Linux-2.4.7-10 # tar cvzf Linux-2.4.7-10debug.tar.gz Linux-2.4.7-10debug 5, Backup Important Configuration Directory # CD / # tar cvzf etc.tar.gz etc

Second, check the hardware model Before the compilation begins, it is recommended to use the relevant software in Windows to make a detailed statistics on the hardware, including hardware types, manufacturers, chip versions, etc., especially notebooks and brands, because many parts are OEM Other manufacturers, it is recommended to record it for use by the core.

The difficulty here is that PCI, if your hard drive is the IDE, you must choose your motherboard on the South Bridge chip. If SCSI is to choose your SCSI card model. There is also a network card, the sound card chip model, their model you can use LSPCI to find something such as mine.

# /Sbin/lspci00:00.0 Host bridge: ServerWorks CNB20LE Host Bridge (rev 05) 00: 00.1 Host bridge: ServerWorks CNB20LE Host Bridge (rev 05) 00: 02.0 PCI bridge: Intel Corp. 80960RP [i960 RP Microprocessor / Bridge] ( rev 01) 00: 02.1 I2O: Intel Corp. 80960RP [i960RP Microprocessor] (rev 01) 00: 04.0 Ethernet controller: 3Com Corporation 3c985 1000BaseSX (SX / TX) (rev 01) 00: 08.0 PCI bridge: Digital Equipment Corporation DECchip 21152 (REV 03) 00: 0E.0 VGA Compatible Controller: ATI TECHNOLOGIES INC 3D Rage Iic (REV 7A) 00: 0F.0 isa bridge: ServerWorks OSB4 South Bridge (Rev 4f) 00: 0f.1 IDE interface: ServerWorks OSB4 IDE Controller02: 04.0 Ethernet Controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (REV 05) 02: 05.0 Ethernet Controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (REV 05) 03: 02.0 PCI Bridge: Intel Corp. 80960RM [I960RM Bridge] (REV 01) 03: 08.0 Ethernet Controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (REV 08) Third, download the kernel file and version check first to www.kernel Download a kernel file in .org, I downloaded version 2.4.27

1. Download the kernel file will use the kernel source package Linux-2.4.27.tar.bz2 COPY to / usr / src directory: #CP Linux-2.4.27.tar.bz2 / usr / src # CD / USR / SRC

2. Check the compiler version If you download the pre-compiled version is higher than the current version of the system, please check the version of your various compilers to see if they can correctly compile the new version of the kernel. ??????????????? how to know the version required to compile the new kernel ??????????????

* GNU C should be at least 2.91.66 or above, and can be checked by executing the "GCC --Version" command. * Gnu Make should be at least 3.77 or later, and can be checked by executing the "Make -Version" command. * binutils should be at least 2.9.1.0.25 or above, and can be checked by executing the "LD -V" command. * util-linux should be at least 2.10O or later, and can be checked by executing the "fdFormat -" command. * MODUTILS should at least 2.4.0 or later, and can be checked by executing the "Insmod -V" command. * E2FSProgs should be at least 1.19 or more, and can be checked by executing the "Tune2FS --Version" command. * PCMCIA-CS should be at least 3.1.21 or above, and can be checked by executing the "Cardmgr -V" command. * PPP should be at least. 4.0 or above, can be checked by executing the "PPPD -Version" command. * ISDN4K-Utils should be at least 3.1beta7 or above, and can be checked by executing the "ISDNCTRL 2> & 1 | Grep Version" command.

If you find that any software is lower than the required version, you will need to download a new version of http://www.freshmeat.net to install, in general, if the current system is 2.2.x, it can meet the demand except for MODUTILS.

Fourth, configure the correct file and directory relationship 1. Remove the old file If you have the original Linux system / usr / src / down exist of Linux source file directory (usually Linux-2.4.20-8) and a point to this source file directory Link (usually Linux-2.4), if all, please delete them first, if you can't bear them, you can also back up them again.

Delete links and file directory: # rm -f /usr/src/linux-2.4# rm -rf /usr/src/linux-2.4.20.8

Backup files can view the Backup Files section

2. Using the following command until the compressed package # bzip2 -d linux-2.4.27.tar.bz2 # tar -xvf Linux-2.4.27.tar can of course decline to decline with Gzip and other decompression software under xwindows, used Winzip or WinRAR is almost almost. This is the sorrow of Windows without learning.

3, delete the ASM, Linux, SCSI directory (if any) under usr / include. # cd / usr / include / # rm -rf asm Linux SCSI

4. Create a real ASM, Linux, and SCSI directory under / usr / include. Make sure that "/ usr / include / asm", "/ usr / include / linux", and "/ usr / include / scsi" are the link to the kernel source code. Both the subdirectories ASM, Linux, and SCSI are the true Include subdirectory required by the computer architecture in the chain code directory. Such as: ASM points to "/usr/src/linux-2.4.27/include/ASM-i386", etc.. If there is no such link, you need to manually create, follow the steps below.

# ln -s /usr/src/linux/include-2.4.27/ASM-i386 / usr / include / asm # ln -s /usr/src/linux/include-2.4.27/linux / usr / include / linux # ln -s /usr/src/linux/include-2.4.27/scsi / usr / include / SCSI

5. Enter the working directory used in later compile: #CD /USR/SRC/LINUX-2.4.27

V. Modify the core parameters (PGC2000 needs) 1. Modify the core parameters related to shared memory # CD / usr / include / linux # vi shm.h put #define shmmax 0x2000000 / * max shared seg size (bytes) * / change #define shmmax 0xa0000000 / * max shared seg size (bytes) * / 2, modify and signal related core parameters # cd / usr / include / linux # VI sem.h put #define Semopm 32 / * <= 1 100 max Num of ops per semop call * / change to #define Semopm 900 / * <= 1 100 Max Num of Ops Per Semop Call * / 3, Core Parameters related to Message Queuing # CD / USR / include / Linux # VI MSG .h found the following three lines (Note ignored): #define msgmni 16 #define msgmax 8192 #define msgmnb 16384 to modify it: #define msgmni 128 #define msgmax 131072 #define msgmnb 20000000 4, according to the above method, modify / usr / SHM.H, Sem.h and Msg.h files under SRC / Linux-2.4.27 / include / linux. =================== The second part begins to compile the kernel ==================

First, clear legacy files

#MAKE MRPROPER This command guarantees that there is no incorrect .o file in the source code directory (ie the object file, which is generated when compiling C language, the purpose is to compile the use of the LINK when compiled into an executable code) and the mutual relying on the file. For the first time, you don't have to use this command, but if you use these source code multiple times, you must first run this command.

Second, configuring the kernel Linux kernel configuration program provides a series of configuration options. For each configuration option, the user can answer "Y", "M" or "N". "Y" indicates the support or device driver of the corresponding characteristics into the kernel; "M" represents the support or device driver of the corresponding characteristics into the loadable module, which can be added by the system or user from the kernel by the system or user. Go; "N" means that the kernel does not provide the support of the corresponding characteristics or drivers. The unreasonable configuration may cause the kernel compilation to fail.

There are four ways to configure the kernel configuration:

1. Configuring the kernel in the command line # make configmake config is a one-on-answer question, the command line method, if you answer one, you can't correct it.

2. Compile the kernel under x WINDOW to provide beautiful X-Window-based GUI interface to configure various options for the kernel, need TK package support

3. Configuring the kernel # make metronfigmake menueconfig provides a beautiful text-based color menu system to configure the kernel, requires NCURSES libraries (NCurses is a function key definition (shortcut), screen draw, and text terminal Dynamic library of graphical interaction function.)

4. Using the current configuration # make oldconfigmake oldconfig is the default value by means of the current settings (.config).

If you compile in text mode: #make menuconfig

When selecting the corresponding configuration, there are three options, which represent the meaning of the representation as follows: Y - Compile this function into the kernel N-- Do not compile the function into the kernel M - compile this function to be dynamically inserted during need Modules in the kernel   If you use Make XConfig, you can select the corresponding options using the mouse. If you use Make MenuConfig, you need to use the space bar to choose. You will find that there is a bracket before every option, but some are a bracket, and there is a parenthery. When you use the space bar to choose, you can find that in the middle brackets, either "*", and the angle of "*" and "m" indicate that the former corresponds to the kernel, either compile into the kernel The latter is more choice, and can be compiled into a module. The content of parentheses is to select an item in several options provided. When using "make metronfig", a "<>" option appears on the left can be compiled into a module. When the option is selected, press the space bar to loop the selection option is selected or unchecked, ("<*>") indicates that it will be compiled into a kernel image (""

") Indicates that it will be compiled into a module.

If we can't know the function of the kernel when we configure the option, use the built-in help function built into the. There are at least some descriptions per option, and each usually has a line "If you don't know the meaning of this option, enter Y. (or n)". These tips can help you when you don't know the meaning of a specific option. To use help, select the option you have questions and press "?".

View the kernel profile in this directory: http://blog.9cbs.net/loef/archive/2004/09/01/91602.aspx

After this step is completed, the system will remind you, Next Step You Should Run "Make DEP"

4. Establish the dependency file required to compile, generate dependencies, ensure that the key file is to read the configuration file generated by the configuration process in the correct position # make DEP to create a dependency tree corresponding to the configuration, which is required to compile. Those don't need it. 2.5. * - 2.6.0 is not needed. In fact, 2.4. * Some kernels are not needed.

5. Make sure all relevant documents are in the latest version status # make clean clear all existing target files, if you forget to do this, the built kernel will be very large, if not deleted, it is also easy in the future compilation process. .

6. Really compiled kernel # make zimage or # make bzimage # make zdisk # make Zlilomake Zimage and make bzimage Implement full compile kernel, the core generated is compressed using Gzip, as long as one is used, the difference The use of Make Bzimage can generate a large number of kernels, such as using the make zimage command when compiling 2.4.0 version, then the error prompt of System TOO BIG will appear. It is recommended to use the make bzimage command. If you want to make a startup disk, use Make ZDisk, don't forget to insert a floppy disk in A:. Make Zlilo Adds the generated kernel to LILO, but do not use this in the first few compiled kernels to avoid failure of the system due to the generated cores.

???????????? When the kernel is greater than 1m, it is still 640K ???????????????????????????????????????

If you select "Loadable Module Support" when you configure the kernel, you will need the following steps: Compilation Module and Deployment Module. The kernel module is residing in the / lib / modules directory, and each module has one ".o". Use command #lsmod to list the modules of the current kernel. Turn the module into the kernel using INSMOD and MODPROBE. 7. Compilation Select Module # Make Modules Compile Module Save in /usr/src/linux-2.4.20-8 / Directory

8. Deploy Module # Make ModeS_Install installed compiled modules to /lib/modules/x.y.z.

9. Check the Symbol # depmod -a of the kernel, this command and the compilation process do not have a relationship. He checks that there is no resolved Symbol in the kernel. It is the dependency between the module so you start the new kernel. You can correct the module when you use the ModProbe command to load the module. If you can't see any return information, you can't see any return information, then you have succeeded in the compilation process.

=================== Part 3 is newly changed =====================1, update BZIMAGE # CP / USR / SRC / Linux / Arch / I386 / Boot / Bzimage / Boot/VMLinuz-2.4.3 Copy New Line File "/ USR / SRC / Linux / Arch / I386 / Boot / Bzimage" to the launch directory, and change For the right name:

Second, update system.map # cp /usr/src/linux/system.map /boot/system.map-2.4.3 Copy "/usr/src/linux/system.map" to the startup directory, and set the appropriate Name, it is a description of the FUCTIONS that is currently running kernel

Third, establish a new link to enter the launch directory, point to the link file VMLinuz and System.map in the directory to the new kernel: # cd / boot # ln -fs vmlinuz-kernel.version.Number VMLinuz # ln -fs system.map- Kernel.2.4.3 systemv.map

The link file VMLinuz and System.map points to the relevant files of the new kernel, because if there is no new link, the LILO program automatically uses the old kernel by default.

Note that if you use the SCSI hard drive and use the ext3 partition format, please note that you must make initrd.img (because the SCSI card is included in this), if you are using the IDE hard drive, you can Skip this step, of course, if you have patience, there is no harm in learning.

Mkinitrd can make initrd.img, usually use, if you want to know, you can man mkinitrd, if you just want to make an initrd.img, then mkinitrd /boot/initrd-custom.img 2.4.22 is In the / boot directory created an initial-custom.img file, which mainly has some drives in the initial mirror ... (inTILALED RAMDISK) ... It is mainly driving, because it is too large in the kernel, so compiling into initrd.img, in the startup Release ... and this 2.4.22 represents the 2.4.22 directory below / lib / modules ... IV, delete the useless files in the launch directory: # rm -f module-info # rm -f initd-2.2.12-20 .img

Module-Info links the module directory of the old kernel of the system. Since the new kernel is now installed, we do not need to keep this file. File / "initrd-2.2.12-2 "is included in the RAM disk image required to initialize the system before the disk can be used. This file is only generated when the system is installed in the system of SCSI devices. Since it is generated here, it is a single (non-modular) new kernel. So even if the system has a SCSI device, this file can still be deleted safely.

5. Generate a new start-up directory: generate the initrd img file under / boot: # cd / boot # mkinitrd initrd-2.4.22.img 2.4.22

============== The fourth part is ready to prepare ================ 1, LILO configuration To configure LILO to use the new kernel You have two options. The first is to override your existing kernel - this is a dangerous method unless there is some emergency starts on your hand, such as the boot disk of this kernel.

A more secure choice is to configure LILO to be guided from new or old kernels. LILO can be configured to start from the new kernel default, but it still provides a way to get the old core when you encounter problems. This is a recommended approach, and it is also the method we will later.

Edit /etc/lilo.conf file PromptTimeout = 50DEFAULT = LinuxBoot = / dev / sdamap = / boot / mapinstall = / boot / boot.bmessage = / boot / messageelinerroot = / dev / sda6read-only

Image = / boot / vmlinuz-2.4.18-3smplabel = linuxinitrd = / boot / initrd-2.4.18-3smp.img

/ / The following is added to add some image = / boot / vmlinuz-2.6.0-test2Label = Linux-2.6.0-test2initrd = / boot / initrd-2.6.0-test2.img

After these modifications, you will need to run "Lilo" as root. # ilo is very important! If you do not perform this step, the start-up process cannot continue. Running "LILO" will give LILO a chance to update its startup mapping.

Second, GRUB configuration

Configure a grub.conf file

Default = 0 Timeout = 10 splashImage = (hd0, 6) /grub/splash.xpm.gz

Title Red Hat Linux Adance Sever 2.1 (2.4.9-E3) Root (HD0, 6) kernel /Vmlinuz-2.4.9-e3 Ro root = / dev / hda8initrd /initrd-2.4.9-e3title dosrootnoverify (HD0, 0) Title Red Hat Linux Adance Sever 2.1 (2.4.22) Root (HD0, 6) kernel /Vmlinuz-2.4.22 Ro root = / dev / hda8initrd /initrd-2.4.22.imgchainLoader 1

Starting from 2.6, many make install commands can reduce Make Dep, make clean and many more steps. Specific reference.

转载请注明原文地址:https://www.9cbs.com/read-121236.html

New Post(0)