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.
1 |
# 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.
1 |
# modprobe configs |
On some Linux distributions, the kernel config file can be found under the /boot
directory.
1 2 |
# 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.
1 2 |
# dpkg-query -L linux-image-4.4.0-22-generic | grep /boot/config /boot/config-4.4.0-22-generic |
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.
1 2 |
# curl -so extract-ikconfig https://raw.githubusercontent.com/torvalds/linux/master/scripts/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.