Linux kernel compilation steps and new kernel enablement

1. Preparatory work
(1) Sort out the hardware, file system type, and network protocol that the system needs to support.
(2) It is recommended to use the command uname –r to check the version number of the system. If your system version is consistent with the kernel version to be compiled, it is recommended to back up the contents under /lib/modules , otherwise the files generated by the make modules_install step in the future will be Overwrite the content under this path.
(3) A: Download and decompress the linux kernel. It is recommended to download the kernel from
http://www.kernel.org/pub/linux/kernel/
, because the source code installed when installing the system supports many devices by default. Kernel pruning adds to the difficulty. The following assumes that you have downloaded the kernel as linux-xyz.tar.gz. Generally, the linux kernel source code is placed under /usr/src, and this habit is still followed here. If this version of the kernel already exists in your path, it is recommended to change the name of the existing one.
               B: If the kernel has been installed (the /usr/src/ directory has a linux subdirectory), skip it. If not, put the linux installation CD in the CD-ROM and find the kernel-source-2.xx.xx.rpm file (xx stands for number, indicating the version number of the kernel), for example, the RPMS directory of RedHat linux is the /RedHat/RPMS/ directory, and then use the command rpm -ivh kernel-source-2.xx.xx.rpm to install the 
kernel .o files and unnecessary associations  
cd /usr/src/linux 
make mrproper 
    Make sure that there are no incorrect .o files and file dependencies in the source code directory. After executing this command, the kernel options will return to the default state. If you are downloading the kernel source code and compiling it for the first time, there is no need to perform this step.
3. Configure the kernel and modify related parameters, please refer to other information. 
In the graphical interface, make xconfig; in the character interface, make menuconfig 
in Correctly set a kernel option in the kernel configuration menu, save and exit 
4. Correctly set the associated file 
make dep 
    to establish the dependency relationship of the file according to the option selected in the previous step.
5. Make clean
to clean up some unnecessary files. If you deleted some options based on the last compilation, it is recommended that you perform this step, otherwise, it is unnecessary.
6. Compile the kernel 
For large kernels (for example, SCSI support is required), make bzImage 
For small kernels, make zImage 
7. Compile modules 
make modules 
to compile loadable modules (that is, the option selected as M in the kernel option), the compilation time is the same as that of the M option Quantity related.
8. Install the module 
make modules_install 
   is about to copy the compiled modules to /lib/modules, which is why you are reminded to backup in the third step of "preparation".
9. Use the new kernel
Method 1: 
(1) Replace the kernel: A, mv /usr/src/linuxX.XX/system.map    /boot/system.map
                 B, mv /usr/src/linuxX.XX/arch/i386/boot/bzImage    /boot/vmlinuz
(2) Then modify the /etc/lilo.conf file, add a startup option, and use the new kernel bzImage/zImage starts. The format is as follows: 
boot=/dev/hda 
map=/boot/map 
install=/boot/boot.b 
prompt 
timeout=50 
linear 
default=linux-new ### Tell lilo to use the new kernel to start linux by default ### 
append= "mem=256M" 
image=/boot/vmlinuz-2.2.14-5.0 
        label=linux 
        read-only 
        root=/dev/hda5 
image=/boot/bzImage(zImage) 
        label=linux-new 
        read-only 
        root=/dev /hda5 
retains the old boot options to ensure that the new kernel cannot be booted, and can also enter linux for other operations. 
After saving and exiting, don’t forget the most important step, run /sbin/lilo to make the modification take effect 
方法二:使用GRUB(修改grub.conf文件)
(1)更换内核:A、mv /usr/src/linuxX.X.X/system.map    /boot/system.map
                 B、mv /usr/src/linuxX.X.X/arch/i386/boot/bzImage   /boot/vmlinuz
(2)修改引导管理程序Grub,/etc/grub.conf
内容如下:
#boot =/dev/had
default =0
timeout =10
splashimage =(hd0, 0)/grub/splash.xpm.gz
title Red Hat Linux(2.4.20-8)
   root(hd0, 0)
   kernel /vmlinuz -2.4.20-8  ro root =LABEL =/
   initrd /initrd-2.4.20-8.img
方法三: 修改启动配置文件
现在大多数使用的都是grub启动,需要修改/boot/grub/grub.conf,添加相应的启动信息,添加内容的最简单格式如下:
title 显示在启动菜单上的名称
root 根文件系统挂载分区
kernel 压缩过的内核文件名
initrd 根文件系统文件名
              如:
              title My new kernel
              root (hd0,2)
              kernel /boot/vmlinuz-x.y.z
              initrd /boot/initrd-x.y.z.img
10、重新生成ram磁盘 
如果您的系统中的/etc/lilo.conf没有使用了ram磁盘选项initrd,略过 
如果您的系统中的/etc/lilo.conf使用了ram磁盘选项initrd, 
使用mkinitrd initrd-内核版本号 内核版本号命令重新生成ram磁盘文件,例如我的Redhat 6.2: 
mkinitrd initrd-2.2.14-5.0 2.2.14-5.0 
之后把/etc/lilo.conf中的initrd指向新生成的initrd-2.2.14-5.0文件: 
initrd=/boot/initrd-2.2.14-5.0 
ram磁盘能使系统性能尽可能的优化,具体参考/usr/src/linux/Documents/initrd.txt文件 
11、重新启动,OK!

Guess you like

Origin blog.csdn.net/cliffordl/article/details/9198525