linux kernel how to build
Contents
=== How to build a kernel with src.rpm
- install kernel-$version.src.rpm; cd rpmbuild/
- dnf install -y rpm-build
- rpmbuild -bp SPECS/kernel.spec
- If you want to add a patch, cp your.patch SOURCES/linux-kernel-test.patch
- uncomment # %define buildid .local and change local to you summary
- dnf install -y flex bison bc gcc elfutils-libelf-devel elfutils-devel openssl-devel dwarves vim clang llvm git ldd-devel
- dnf install -y libpcap-devel python3-docutils
- rpmbuild -bb –target=
uname -m
–without debug –without doc –without
headers –without perf –without debuginfo –without tools SPECS/kernel.spec
=== How to build a RHEL kernel
- make rh-configs
- cp redhat/configs/kernel-3.10.0-x86_64.config .config
- make oldconfig
- make -j28
- make rh-check-kabi Or redhat/kabi/check-kabi -k redhat/kabi/Module.kabi_x86_64 -s Module.symvers
=== How to build a kernel
- git clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git
- cd net-next
- git am 0001-net-ipv6…. (attached patch)
- make menuconfig (just exit and save)
- make -j4
- make modules_install -j4
- make install
- cd /boot/
- dracut -f initramfs-3.11.0-rc6+.img 3.11.0-rc6+ (# ls /lib/modules/3.11.0-rc6+/)
- update your grub to boot the correct kernel
- reboot
If you want to rename the kernel, add a name in .config CONFIG_LOCALVERSION
=== How to build a driver
- install kernel devel package
- cd rpmbuild/BUILD/kernel-3.10.0-64.el7/linux-3.10.0-64.el7.x86_64/drivers/infiniband/ulp/ipoib/
- make -C /usr/src/kernels/3.10.0-64.el7.x86_64/ M=${PWD} modules
Or build an upstream kernel driver with clang
|
|
Or only build a driver for testing:
|
|
[1] https://www.kernel.org/doc/html/latest/kbuild/modules.html [2] https://www.kernel.org/doc/html/latest/kbuild/llvm.html
Author Hangbin Liu
LastMod 2024-08-18 (8494b7a)