Obtain kernel config from currently running Linux system?

118

39

I accidentally deleted my .config for my kernel configuration on Linux, and seem to remember there was a way to retrieve the kernel configuration via the proc filesystem somehow.

Is this still possible, and if so how would I do it?

Sonny Ordell

Posted 2011-05-23T10:49:38.847

Reputation: 1 357

@Sonny Ordell: There are now two valid answers. Can you accept one of them? – Hennes – 2013-10-02T14:43:28.133

3@Hennes User has not been online since Jun 27 '11 at 16:19. Don't think he's going to be accepting anything. – DanteTheEgregore – 2013-10-02T14:49:20.297

Answers

118

Depending on your system, you'll find it in any one of these:

  1. /proc/config.gz
  2. /boot/config
  3. /boot/config-$(uname -r)

and possibly more places.

new123456

Posted 2011-05-23T10:49:38.847

Reputation: 3 707

in /boot/config-$(uname -r) for amazon linux and likely RHEL – aeb0 – 2016-11-27T23:47:25.957

1Not existing such files on Ubuntu Mate or Kali Linux for RaspBerry Pi. – Sopalajo de Arrierez – 2017-10-05T23:23:05.530

1You should mention that your first item (/proc) is only available if module "configs" is loaded – Andy – 2018-02-27T07:41:21.313

4On some distros (Fedora/Redhat) it's /boot/config-2.6.18-194.el5 or similar, with the kernel release string appended. – Phil – 2011-05-23T15:50:03.057

1@Phil I run a distro (Zenwalk) where those filenames are symlinked by the latest kernel package to /boot/config. I'll go ahead and add these to the list - thanks for reminding me. – new123456 – 2011-05-23T20:15:32.463

57

For an actual running kernel, one way to get the config file this is to

cat /proc/config.gz | gunzip > running.config

or,

zcat /proc/config.gz > running.config

Then running.config will contain the configuration of the running linux kernel.

However this is only possible if your running linux kernel was configured to have /proc/config.gz. The configuration for this is found in

  • General setup
    • [*] Kernel .config support
      • [*] Enable access to .config through /proc/config.gz

Most distributions do not have this configuration set. They provide kernel config files in their kernel packages and is usually found in /boot/ directory.

Jarl

Posted 2011-05-23T10:49:38.847

Reputation: 671

5These are known as CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC, if you're grepping for them. – chronospoon – 2015-03-26T18:34:28.727

2zcat /proc/config.gz works fine. – Quanlong – 2016-08-22T04:15:49.470

39

A Little bit late but maybe it helps someone. I didn't have /proc/config.gz nor /boot/config nor /boot/config-$(uname -r) on my Computer. I had to run modprobe configs as root. Then, /proc/config.gz was present

Thomas Sparber

Posted 2011-05-23T10:49:38.847

Reputation: 491

Can confirm on Intel MIC embedded Linux (BusyBox), this is necessary and works. – Mark Lakata – 2016-02-23T18:59:59.963

4Same for Raspbian on Raspberry Pi 2 – Drew McGowen – 2016-03-24T02:39:30.057

2FATAL: Module configs not found. on OMV 2.2 (Debian Wheezy) so glad they provided it in /boot/config-$(uname -r) – tuk0z – 2016-04-12T11:42:10.040

You sir, saved my day. Have a +1 – Christian – 2018-01-14T10:26:15.467

'modprobe configs' is very helpful I had tests that automatically probe kconfig that were failing on a Raspberry Pi 3, but now work. Thanks for the tip!! – Tim Bird – 2019-01-03T00:40:54.783

9

If you couldn't find kernel configuration in /boot/ nor in /proc/config.gz, you can try extracting this information from the kernel itself.

Inside any kernel source code there is a script for extracting config located in scripts/extract-ikconfig, pass the kernel you want its configuration as parameter to this script.

This solution will only work if Kernel .config support was enabled in the compiled kernel.

Ramast

Posted 2011-05-23T10:49:38.847

Reputation: 191

2This was extremely helpful and helped me to obtain plenty of configs I didn't expect to ever see. Thanks! – selurvedu – 2017-10-02T14:16:58.620

6

Independently of the distribution, you can run: cat /lib/modules/$(uname -r)/build/.config

Source: https://linux.die.net/man/5/proc (search for /proc/config).

jgomo3

Posted 2011-05-23T10:49:38.847

Reputation: 281

1

For RedHat-based distributions, the .config file of the off-the-shelf kernel can be found with the command cat /lib/modules/$(uname -r)/build/.config that's available after the package kernel-devel is installed using the command:

yum -y install kernel-devel

Note that with the real Red Hat Enterprise Linux distribution, you will need to enable the source-repository to get this package. On RHEL8, use the following command to do that:

subscription-manager repos --enable=rhel-8-for-x86_64-baseos-source-rpms

Gertjan Bijl

Posted 2011-05-23T10:49:38.847

Reputation: 11