174

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?

Hennes
  • 64,768
  • 7
  • 111
  • 168
Sonny Ordell
  • 1,917
  • 3
  • 15
  • 13
  • @Sonny Ordell: There are now two valid answers. Can you accept one of them? – Hennes Oct 02 '13 at 14:43
  • 5
    @Hennes User has not been online since `Jun 27 '11 at 16:19`. Don't think he's going to be accepting anything. – DanteTheEgregore Oct 02 '13 at 14:49
  • 2
    http://superuser.com/questions/577307/how-to-get-a-list-of-active-drivers-that-are-statically-built-into-the-linux-ker || http://askubuntu.com/questions/163304/which-device-drivers-are-built-into-the-kernel || http://stackoverflow.com/questions/14376540/view-linux-kernel-config-options || http://unix.stackexchange.com/questions/83319/how-can-i-know-if-the-current-kernel-was-compiled-with-a-certain-option-enabled || http://serverfault.com/questions/51032/how-do-i-check-what-kernel-options-were-compiled-without-looking-at-boot-config – Ciro Santilli OurBigBook.com Aug 07 '16 at 15:44

8 Answers8

181

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.

Run5k
  • 15,723
  • 24
  • 49
  • 63
new123456
  • 4,485
  • 1
  • 18
  • 19
  • 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 '11 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 '11 at 20:15
  • in /boot/config-$(uname -r) for amazon linux and likely RHEL – aeb0 Nov 27 '16 at 23:47
  • 2
    Not existing such files on Ubuntu Mate or Kali Linux for RaspBerry Pi. – Sopalajo de Arrierez Oct 05 '17 at 23:23
  • 2
    You should mention that your first item (/proc) is only available if module "configs" is loaded – Andy Feb 27 '18 at 07: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 '20 at 06:34
82

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.

Hennes
  • 64,768
  • 7
  • 111
  • 168
Jarl
  • 921
  • 6
  • 3
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

Thomas Sparber
  • 631
  • 5
  • 5
22

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

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

Cristian Ciupitu
  • 5,513
  • 2
  • 37
  • 47
jgomo3
  • 470
  • 1
  • 4
  • 14
10

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
  • 201
  • 2
  • 4
  • 2
    This was extremely helpful and helped me to obtain plenty of configs I didn't expect to ever see. Thanks! – selurvedu Oct 02 '17 at 14:16
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

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
dragon788
  • 992
  • 9
  • 15
  • 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 08 '20 at 00: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 08 '20 at 03:02
1

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.

user2285323
  • 81
  • 2
  • 4