How To Compile Linux Kernel


Hi today we are going to compile linux kernel. you can think that compiling  kernel is very complicated and hard for you. But it is not. It is more easy to compile than a lot other projects. Because linux kernel has no dependency to library or other tools. It needs just ncurses development library which is used for module configuration. Lets start the process.

Download Linux Kernel

Download the linux kernel from

Extract Linux Kernel

Then decompress it. The postfix of file like xz, gz is not important they are just different compression algorithms all ingredients are the same

Enter the decompress directory

Install Dependencies

Run module configuration menu for kernel. Here you need ncurses devel library for c. You can install it with yum

Here you will see main menu

General menu

You can configure file system module from here. If you have space constraint you can remove unneeded file system modules or add required file system modules


Here is driver modules.As I said aboove you can remove unneded modules or add drivers you need.


Virtualization modules can be configured with this menu. Say you have amd cpu you do not have to compile intel driverss.


After applying all settings you can save them and exit

Selection_005 Selection_006

Available Options

Now we are ready to compile process. There is a lot of compile options but I am gonna show you some of them. If you want to see all off them run make help

Other generic targets:
all             – Build all targets marked with [*]
* vmlinux         – Build the bare kernel
* modules         – Build all modules
modules_install – Install all modules to INSTALL_MOD_PATH (default: /)
firmware_install- Install all firmware to INSTALL_FW_PATH
(default: $(INSTALL_MOD_PATH)/lib/firmware)
dir/            – Build all files in dir and below
dir/file.[oisS] – Build specified target only
dir/file.lst    – Build specified mixed source/assembly target only
(requires a recent binutils and recent build (
dir/file.ko     – Build module including final link
modules_prepare – Set up for building external modules
tags/TAGS       – Generate tags file for editors
cscope          – Generate cscope index
gtags           – Generate GNU GLOBAL index
kernelrelease   – Output the release version string
kernelversion   – Output the version stored in Makefile
image_name      – Output the image name
headers_install – Install sanitised kernel headers to INSTALL_HDR_PATH
(default: ./usr)

LEARN MORE  How to Install Mariadb / Mysql Server in Linux Fedora?

Static analysers
checkstack      – Generate a list of stack hogs
namespacecheck  – Name space analysis on compiled kernel
versioncheck    – Sanity check on version.h usage
includecheck    – Check for duplicate included header files
export_report   – List the usages of all exported symbols
headers_check   – Sanity check on exported headers
headerdep       – Detect inclusion cycles in headers
coccicheck      – Check with Coccinelle.

Kernel packaging:
rpm-pkg             – Build both source and binary RPM kernel packages
binrpm-pkg          – Build only the binary kernel package
deb-pkg             – Build the kernel as a deb package
tar-pkg             – Build the kernel as an uncompressed tarball
targz-pkg           – Build the kernel as a gzip compressed tarball
tarbz2-pkg          – Build the kernel as a bzip2 compressed tarball
tarxz-pkg           – Build the kernel as a xz compressed tarball
perf-tar-src-pkg    – Build perf-3.16.0-rc4.tar source tarball
perf-targz-src-pkg  – Build perf-3.16.0-rc4.tar.gz source tarball
perf-tarbz2-src-pkg – Build perf-3.16.0-rc4.tar.bz2 source tarball
perf-tarxz-src-pkg  – Build perf-3.16.0-rc4.tar.xz source tarball

Documentation targets:
Linux kernel internal documentation in different formats:
htmldocs        – HTML
pdfdocs         – PDF
psdocs          – Postscript
xmldocs         – XML DocBook
mandocs         – man pages
installmandocs  – install man pages generated by mandocs
cleandocs       – clean all generated DocBook files

Architecture specific targets (x86):
* bzImage      – Compressed kernel image (arch/x86/boot/bzImage)
install      – Install kernel using
(your) ~/bin/installkernel or
(distribution) /sbin/installkernel or
install to $(INSTALL_PATH) and run lilo
fdimage      – Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
fdimage144   – Create 1.4MB boot floppy image (arch/x86/boot/fdimage)
fdimage288   – Create 2.8MB boot floppy image (arch/x86/boot/fdimage)
isoimage     – Create a boot CD-ROM image (arch/x86/boot/image.iso)
bzdisk/fdimage*/isoimage also accept:
FDARGS=”…”  arguments for the booted kernel
FDINITRD=file initrd for the booted kernel
kvmconfig     – Enable additional options for guest kernel support

LEARN MORE  Linux OS and Distributions

x86_64_defconfig         – Build for x86_64
i386_defconfig           – Build for i386

make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build
make V=2   [targets] 2 => give reason for rebuild of target
make O=dir [targets] Locate all output files in “dir”, including .config
make C=1   [targets] Check all c source with $CHECK (sparse by default)
make C=2   [targets] Force check of all c source with $CHECK
make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections
make W=n   [targets] Enable extra gcc checks, n=1,2,3 where
1: warnings which may be relevant and do not occur too often
2: warnings which occur quite often but may still be relevant
3: more obscure warnings, can most likely be ignored
Multiple levels can be combined with W=12 or W=123

Execute “make” or “make all” to build all targets marked with [*]
For further info see the ./README file

The default output of compile process is bzImage which is a compressed kernel binary but if you want you can select iso with isoimage parameter. Here the second thing is if you have cpu with more then one core and hyperthreading you can make compile process faster by using -j <number  of cores x 2> paremeter. I have 4 cores so I multiply it with 2 and get parameter -j8.

Compiling Linux Kernel As Iso Image

After compilation you can find your image in arch/x86/boot/image.iso

Compile Linux As Binary

Install Linux Kernel

We can install compiled linux kernel like below

Well done!