# 安装编译依赖组件。 sudo apt install -y libncurses5-dev libssl-dev bison flex libelf-dev gcc make openssl libc6-dev sudo apt install -y flex bison make gcc libssl-dev bc libelf-dev wget https://mirrors.tuna.tsinghua.edu.cn/kernel/v4.x/linux-4.18.tar.gz tar -zxf linux-4.18.tar.gz cd linux-4.18.tar.gz
# 设置调试的编译菜单 export ARCH=x86 make x86_64_defconfig make menuconfig
# 下面选项如果没有选上的,选上(点击空格键),然后 save 保存设置,退出 exit。 ################################################################## General setup ---> [*] Initial RAM filesystem and RAM disk (initramfs/initrd) support
Device Drivers ---> [*] Block devices ---> <*> RAM block device support (65536) Default RAM disk size (kbytes)
Processor type and features ---> [*] Randomize the address of the kernel image (KASLR) Kernel hacking ---> Compile-time checks and compiler options ---> [*] Compile the kernel with debug info [*] Provide GDB scripts for kernel debugging
Device Drivers --> Network device support --> <*> Universal TUN/TAP device driver support
[*] Networking support --> Networking options --> <*> 802.1d Ethernet Bridging # 编译内核。 make -j8
2. 编译内核
编译内核会遇见很多问题
2.1 网络库的问题
1 2 3 4 5 6 7 8 9
In file included from scripts/selinux/genheaders/genheaders.c:19: # scripts/selinux/mdp/mdp.c 也会出现这种现象 ./security/selinux/include/classmap.h:249:2: error: #error New address family defined, please update secclass_map. 249 | #error New address family defined, please update secclass_map. | ^~~~~ make[3]: *** [scripts/Makefile.host:90: scripts/selinux/genheaders/genheaders] Error 1 make[2]: *** [scripts/Makefile.build:558: scripts/selinux/genheaders] Error 2 make[1]: *** [scripts/Makefile.build:558: scripts/selinux] Error 2 make: *** [Makefile:1045: scripts] Error 2
arch/x86/entry/entry_64.S: Assembler messages: arch/x86/entry/entry_64.S:1667: Warning: no instruction mnemonic suffix given and no register operands; using default for `sysret' AS arch/x86/entry/thunk_64.o arch/x86/entry/thunk_64.o: warning: objtool: missing symbol table