# Trim kernel configuration

## Dwosky

I was wondering if there is some documentation or tool which we can check to see what items are not being used by our kernel / system in order to remove them from the configuration in a way of improving kernel build times on lower spec systems.

I know the basic ones to remove mostly drivers that you know your system isn't going to use, but I was wondering if there is a more in depth system to try to reduce the kernel configuration to a bare minimum or at least not to a bloated default config one.

----------

## Jaglover

The only way I know is start with 'make allnoconfig' and add what you need. But if you find an application which can read your mind - for instance if I want firewall or not - then I'd gladly use it.   :Razz: 

----------

## Dwosky

I don't know what's better now, start from zero and try to build a running kernel that doesn't end in panic or start removing pieces from the actual one until you reach panic and rollback   :Laughing: 

Still in my case the issue is not "I don't know if I want X feature", but just fit the kernel to all the features the system has/works with right now.

----------

## ct85711

I know for me, I prefer to go with the second route (I have done the first before when I first learned how to compile a kernel, pre-gentoo).  My reasoning, is that I would rather have a running machine first, and less hassle when trying to figure out what all you need.  The big thing that I would think you need to consider, is if you are space limited or not (on if a bigger kernel size is going to cause issues).

----------

## Ant P.

"make localyesconfig" will build a kernel with only the drivers you're currently using. Use menuconfig to go in and re-add modules for things like disconnected USB peripherals and you're 99% done.

----------

## PrSo

 *Ant P. wrote:*   

> "make localyesconfig" will build a kernel with only the drivers you're currently using. Use menuconfig to go in and re-add modules for things like disconnected USB peripherals and you're 99% done.

 

+1

More stuff you will find in gentoo wiki like i.e. iptables(firewall), cups, sane, graphic card (intel/radeon/amdgpu/nvidia), and enable those kernel prerequisites when your machine needs it. 

When you are decided to set the CFLAGS to "native" only in portage make.conf (gcc optimization) without using distcc, you could disable intel/amd (or others) stuff that you wont use in "Processor type and futures". 

This is the beginning.

Later you should explore kernel config with make menuconfig and disable/enable what your machine will use.

This is my 2c.

----------

## Jaglover

CFLAGS from make.conf are not used for kernel compile. Enable 'experimental' use flag for sources, then you can enable -march=native inside kernel configuration.

----------

## PrSo

 *Jaglover wrote:*   

> CFLAGS from make.conf are not used for kernel compile. Enable 'experimental' use flag for sources, then you can enable -march=native inside kernel configuration.

 

100% correct.

----------

## Dwosky

 *Ant P. wrote:*   

> "make localyesconfig" will build a kernel with only the drivers you're currently using. Use menuconfig to go in and re-add modules for things like disconnected USB peripherals and you're 99% done.

 

Thanks for the info, I didn't knew about that option.

----------

## 1clue

Yeah, the drivers are the easy part. The only way I know for the rest is read, read, read...

I've thought about building a minimal Gentoo system to get a bare-bones kernel config, but it seems like a huge amount of very repetitive work.

----------

## Anon-E-moose

pappy's preconfig are a pretty good place to start.

----------

## Jaglover

 *Dwosky wrote:*   

>  *Ant P. wrote:*   "make localyesconfig" will build a kernel with only the drivers you're currently using. Use menuconfig to go in and re-add modules for things like disconnected USB peripherals and you're 99% done. 
> 
> Thanks for the info, I didn't knew about that option.

 

I'm not sure it will not include all modules currently loaded. Never used it. Usually there is a rather big number of unnecessary modules loaded when you boot live CD.

----------

## Dwosky

 *Jaglover wrote:*   

> I'm not sure it will not include all modules currently loaded. Never used it. Usually there is a rather big number of unnecessary modules loaded when you boot live CD.

 

Yeah, I know. The idea its to use it on an actual running system instead of via LiveCD in order to avoid all the drivers loaded by default for compatibility purposes.

----------

## Jaglover

So this is a chicken-egg problem. First you need to build a lean kernel, run it, and then you can use make localyesconfig ...

----------

## 1clue

 *Jaglover wrote:*   

> So this is a chicken-egg problem. First you need to build a lean kernel, run it, and then you can use make localyesconfig ...

 

You should be able to use localyesconfig from the system rescue cd. All the modules are there, but only the ones relevant to your installed hardware will be loaded.

----------

## Jaglover

I just tried and make localyesconfig resulted in a terribly bloated config. Thanks but no thanks.

----------

