Linux: Get Kernel Config

Objective: Get Linux kernel config from currently running system or from a kernel image file.

If the kernel was compiled with CONFIG_IKCONFIG (found under General setup – Kernel .config support – Enable access to .config through /proc/config.gz), then the config file can be extracted from /proc/config.gz. It is gzip compressed and it can be extracted using the following syntax.

# cat /proc/config.gz | gunzip > linux-$(uname -r).config

The above command will create a config file called linux-4.4.0-24-generic.config where 4.4.0-24-generic is the Linux kernel version that is currently running.

If the /proc/config.gz file is not found, try loading the configs kernel module. This helps in some cases.

# modprobe configs

On some Linux distributions, the kernel config file can be found under the /boot directory.

# ls -l /boot/config-$(uname -r)
-rw-r--r-- 1 root root 189521 Jun  9 05:39 /boot/config-4.4.0-24-generic

The config file under /boot is usually bundled in the linux-image package.

# dpkg-query -L linux-image-4.4.0-22-generic | grep /boot/config

If you would like to extract the config from a kernel image file, install the extract-ikconfig script on your system. Once installed, run the script with the path to the kernel image. An example is shown below.

# curl -so extract-ikconfig
# ./extract-ikconfig /boot/vmlinuz-4.4.0-24-generic > linux-4.4.0-24-generic.config

The linux-4.4.0-24-generic.config output file will contain the kernel config. Note the the script will only work if the kernel was compiled with CONFIG_IKCONFIG option.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react, vuejs); plays_on(xbox, ps4); linux_desktop_user(true); }