199

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?

Giacomo1968
  • 58,727
Sonny Ordell
  • 2,177

9 Answers9

208

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
  • 16,463
  • 24
  • 53
  • 67
new123456
  • 4,833
87

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
  • 65,804
  • 7
  • 115
  • 169
Jarl
  • 979
56

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

29

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

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

jgomo3
  • 580
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.

Ramast
  • 211
4

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
  • 1,112
4

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.

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
0

https://github.com/kubernetes/system-validators/blob/e6e77857caf8e6f5ef43fb61d59d034f5f4c0f94/validators/kernel_validator.go#L177-L188

"/proc/config.gz",
"/boot/config-" + k.kernelRelease,
"/usr/src/linux-" + k.kernelRelease + "/.config",
"/usr/src/linux/.config",
"/usr/lib/modules/" + k.kernelRelease + "/config",
"/usr/lib/ostree-boot/config-" + k.kernelRelease,
"/usr/lib/kernel/config-" + k.kernelRelease,
"/usr/src/linux-headers-" + k.kernelRelease + "/.config",
"/lib/modules/" + k.kernelRelease + "/build/.config",
Giacomo1968
  • 58,727