178

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?

1

8 Answers 8

188

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.

6
  • 4
    On some distros (Fedora/Redhat) it's /boot/config-2.6.18-194.el5 or similar, with the kernel release string appended.
    – PhilR
    May 23, 2011 at 15:50
  • 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
    May 23, 2011 at 20:15
  • 2
    Not existing such files on Ubuntu Mate or Kali Linux for RaspBerry Pi. Oct 5, 2017 at 23:23
  • 2
    You should mention that your first item (/proc) is only available if module "configs" is loaded
    – Andy
    Feb 27, 2018 at 7:41
  • 2
    Note that you can use zgrep CONFIG_OPTION /proc/config.gz if you want to search for a specific option without unzipping a copy of the config file.
    – catleeball
    Sep 25, 2020 at 6:34
83

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.

4
  • 12
    These are known as CONFIG_IKCONFIG and CONFIG_IKCONFIG_PROC, if you're grepping for them. Mar 26, 2015 at 18:34
  • 2
    zcat /proc/config.gz works fine.
    – Quanlong
    Aug 22, 2016 at 4:15
  • less /proc/config.gz also works fine
    – nocnokneo
    Aug 6, 2020 at 10:53
  • @nocnokneo for me that failed (offered to show me the binary file) but zless worked Jan 22, 2021 at 21:24
53

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

6
  • Can confirm on Intel MIC embedded Linux (BusyBox), this is necessary and works. Feb 23, 2016 at 18:59
  • 4
    Same for Raspbian on Raspberry Pi 2 Mar 24, 2016 at 2:39
  • 5
    FATAL: Module configs not found. on OMV 2.2 (Debian Wheezy) so glad they provided it in /boot/config-$(uname -r)
    – tuk0z
    Apr 12, 2016 at 11:42
  • You sir, saved my day. Have a +1
    – Christian
    Jan 14, 2018 at 10:26
  • '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
    Jan 3, 2019 at 0:40
24

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

Source: proc(5) man page (search for /proc/config.gz).

3
  • 1
    Unfortunately neither this no any other solution here works to get the kernel config on a Netgear ReadyNAS. Jun 8, 2022 at 19:21
  • 1
    This one works great with raspbian . Thanks.
    – DPalharini
    Dec 9, 2022 at 14:22
  • 1
    This one works great for raspbian. Thanks.
    – DPalharini
    Dec 9, 2022 at 14:23
11

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.

1
  • 2
    This was extremely helpful and helped me to obtain plenty of configs I didn't expect to ever see. Thanks!
    – selurvedu
    Oct 2, 2017 at 14:16
3

If you can't find any of the suggested files and you are able to modprobe you should almost always be able to get a copy of the current config this way.

modprobe configs # might need `sudo modprobe configs`

# This will create /proc/config.gz
zcat /proc/config.gz

# Or if you are looking for whether a specific option was set
zgrep USBIP /proc/config.gz
2
  • Interesting idea, but I'm not sure enough kernels ship with the configs module available. I couldn't find it on the Ubuntu 18.04 or 20.04 systems I had handy.
    – Greg Smith
    Sep 8, 2020 at 0:40
  • I found it useful specifically on ChromeOS where they don't include the compressed configs but do include the module to export the running config if so desired.
    – dragon788
    Sep 8, 2020 at 3:02
2

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
2

Run modprobe configs as root to create /proc/config.gz

After that zcat /proc/config.gz > /boot/config-$(uname -r) to list config of the kernel.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .