linux内核编译

编译准备

创建一个大小写敏感的分区
alt text

下载内核源码

1
2
3
wget https://www.kernel.org/pub/linux/kernel/v6.x/linux-6.7.9.tar.gz
tar -xvf linux-6.7.9.tar.gz
cd linux-6.7.9

安装编译器

1
2
3
# brew install lld
# brew install rbenv/tap/[email protected]
brew mysticlgbt/made/mac-linux-kdk

如果提示lld.ld not found, 需要先安装lld,后续版本中lld已经没有包含在llvm里面了,需要单独安装。

设置编译选项

1
lkmake ARCH=arm64 menuconfig

编译内核

1
lkmake ARCH=arm64 LLVM=1 -j $(nproc)

编译完成后会生成vmlinux文件。

用file命令查看文件类型:

1
file vmlinux

输出类似:

1
vmlinux: ELF 64-bit LSB pie executable, ARM aarch64, version 1 (SYSV), statically linked, BuildID[sha1]=aedcccc5579d4c80a4c0934e6fd1a18c0a682fa2, with debug_info, not stripped