Before compiling a new kernel, what needs to be done?

A. Compile kernel modules
B. Configure the kernel options
C. Delete old kernel sources
D. Change to runlevel 1
E. All of the above

题解

编译 Linux kernel 的步骤如下:

一、解压缩 kernel 源代码

二、如果有先前编译 kernel 时用的设置档,可以拷贝到源代码目录里面来用。

三、接着要清空先前操作 kernel 源代码时残留的暂存盘案。如果要保留之前的设置档,下达「make clean」指令;如果不要保留之前的设置档,下达「make mrproper」指令。

四、运行「make XXconfig」相关指令,如「make menuconfig」、「make xconfig」、「make oldconfig」等等不同的方式来设置 kernel 的功能。

五、如果是早期的 kernel 版本(2.6 之前),可能还需要使用「make dep」指令来创建源代码文件的相依关系。

六、接着就可以开始进行 kernel 的编译了。使用「make vmlinux」可以编译出没有压缩过的 kernel;使用「make bzImage」可以编译出压缩过的 kernel;使用「make modules」可以编译出 kernel 模块;使用「make all」可以将上述三种东西都编译出来。

所以答案是选项 B,必须要使用「make XXconfig」相关指令来设置 kernel 的功能。