I would like to create a minimal kernel for a web server.

When you compile a kernel from source how do you get hardware info and then know what drivers need to be kept in the kernel so the rest can be removed?

  1. You should know under some distros like Arch or Gentoo; there are specialized kernels available for virtualization. For example if you want to run Linux under Virtuozzo or VMware technologies.

  2. Use the command lspci -n and paste it's output to http://kmuto.jp/debian/hcl; that site gives you the kernel modules needed in general. Then go to kernel configuration (e.g. menuconfig) and press / to search the options, find their locations and activate them.

  3. There is a site named "kernel seeds" which makes a .config file for generic kernel according to kernel version. It is good to compare the .config for kernel options and modules you are not sure about.

  4. Try to build your kernel on your own and use config script less; it is better if you want to have kernel option related to your hardware.

  5. Try to boot your machine with a latest version of a good live cd/usb. I suggest bodhi linux or FatDog/Puppy linux. then do lsmod in there and see the list of loaded modules. these are the list of kernel options you need to either build in your kernel or add as module to your kernel and load at the boot time.

There is a helpful script shipped with more recent kernels, streamline_config.pl1, which will assist you to create a .config file containing only those modules necessary to your currently running kernel. The script has a commented "How to" with all of the necessary steps.

Another way to accomplish the same thing manually is to use localmodconfig. After unpacking and preparing your downloaded kernel, plug in any external devices you are likely to need in your new, custom kernel so that the relevant modules are loaded.

You then start the compilation process with the make localmodconfig command and your .config file will be generated based upon only the currently loaded modules.

In both cases, it is paramount that you ensure that you have everything you need listed in lsmod prior to compilation,or those modules will not be picked up for the build.

The first (several) times you do this, review the generated .config file prior to compilation to check it has what you need.

The Arch Wiki has a page on compiling the traditional way and includes details on using localmodconfig.

1.Located in scripts/kconfig/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.