I want to build myself a custom kernel as a RPM. I use the .config from the distribution I'm using, in this case, Centos, and end up with a kernel install size of 2.2Gb. I have deselected all the drivers/modules I don't need and updated the .config. When I make the kernel I see drivers being compiled that I deselected. What step am I missing to read the .config and not compile a large kernel? The kernel from the repos are a couple of Mb comparing to mine.

  1. Download source

    wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.4.138.tar.xz

  2. Extract source

    tar -xf linux-5.4.138.tar.xz

  3. Copy in existing config found from elrepo.

    cp ~/config-5.4.138-x86_64 linux-5.4.138/.config

  4. Run

    make oldconfig

  5. Configure with menuconfig and deselect drivers/modules not needed and save.

    make menuconfig

  6. Build RPM

    make rpm-pkg -j4

Result is:

  586.3 MiB [##########]  kernel-5.4.138-1.x86_64.rpm
  147.8 MiB [##        ]  kernel-devel-5.4.138-1.x86_64.rpm
    1.3 MiB [          ]  kernel-headers-5.4.138-1.x86_64.rpm

yum install:

kernel          x86_64          5.4.138-1             /kernel-5.4.138-1.x86_64          2.2 G

Here is my .config if it can help https://pastebin.com/LBw6Gm1s

2 Answers 2


Rebuild elrepo's kernel-lt-5.4.spec with your desired config. That is, make your desired edits to Source1, the one with the kernel version in the name, currently config-5.4.138-x86_64. Increment the release number. Build the resulting SRPM with mock.

Red Hat style RPM packages have their own scripts and split out the sub packages in a particular way. Quite different from upstream's RPM spec. Some debugging symbols are not being stripped, resulting in much bigger outputs.

Read the spec files to see how different they are. For elrepo, see kernel-lt-5.4.spec on the mirrors. While moderately complicated, it is a Red Hat style kernel spec. Of a kernel.org longterm release without patches, which is the point of the exercise. Contrast to make rpm-pkg which via some Makefiles calls scripts/package/mkspec, which does not look at all like a Red Hat kernel. Note the comment about disable stripping debug symbols:

The only gothic bit here is redefining install_post to avoid stripping the symbols from files in the kernel which we want

No, the size is not a bug, kernel hackers want debug symbols.

Quite confusing when both upstream (kernel.org) and downstream (Red Hat, elrepo) have their own package build scripts. But these are the kind of details you need to pay attention to. For reproducible builds, and to understand your custom package.

elrepo renamed their package kernel-lt (or kernel-ml) to not conflict with the RHEL kernel package name. Your build conflicts, beware.

  • This is I've done to get the RPM built from src. I'll get a kernel RPM around 40Mb but when I compile it differently, as stated above, it becomes a 2.2Gb monster. Is this not a bug on how make rpm-pkg works that I should report? Commented Aug 6, 2021 at 19:17
  • No, the kernel.org spec not stripping is not a bug. The packages are very different, see my edit. Commented Aug 6, 2021 at 23:44

@JohnMahowald provides a good overview, so see his answer, too. However, there is something you can do before make rpm-pkg that will reduce the build size dramatically:


If you say Y here gcc is instructed to generate less debugging information for structure types. This means that tools that need full debugging information (like kgdb or systemtap) won't be happy. But if you merely need debugging information to resolve line numbers there is no loss. Advantage is that build directory object sizes shrink dramatically over a full DEBUG_INFO build and compile times are reduced too. Only works with newer gcc versions.

You will find this in make menuconfig, in this menu order:

  • Kernel hacking
    • Compile-time checks and compiler options
      • Reduce debugging information

Also, if it is not already, make sure you set Compressed Debug information (ie, CONFIG_DEBUG_INFO_COMPRESSED_ZLIB=y) in the same menu.

You must log in to answer this question.

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