# Linux Kernel Module Cheat

#### 17.1.1. Modify kernel config

To modify a single option on top of our default kernel configs, do:

    ./build-linux --config 'CONFIG_FORTIFY_SOURCE=y'

Kernel modules depend on certain kernel configs, and therefore in general you might have to clean and rebuild the kernel modules after changing the kernel config:

    ./build-modules --clean
    ./build-modules

and then proceed as in Your first kernel module hack.

You might often get way without rebuilding the kernel modules however.

To use an extra kernel config fragment file on top of our defaults, do:

    printf '
    CONFIG_IKCONFIG=y
    CONFIG_IKCONFIG_PROC=y
    ' > data/myconfig
    ./build-linux --config-fragment 'data/myconfig'

To use just your own exact `.config` instead of our defaults ones, use:

    ./build-linux --custom-config-file data/myconfig

There is also a shortcut `--custom-config-file-gem5` to use the gem5 arm Linux kernel patches.

The following options can all be used together, sorted by decreasing config setting power precedence:

- `--config`

- `--config-fragment`

- `--custom-config-file`

To do a clean menu config yourself and use that for the build, do:

    ./build-linux --clean
    ./build-linux --custom-config-target menuconfig

But remember that every new build re-configures the kernel by default, so to keep your configs you will need to use on further builds:

    ./build-linux --no-configure

So what you likely want to do instead is to save that as a new `defconfig` and use it later as:

    ./build-linux --no-configure --no-modules-install savedefconfig
    cp "$(./getvar linux_build_dir)/defconfig" data/myconfig
    ./build-linux --custom-config-file data/myconfig

You can also use other config generating targets such as `defconfig` with the same method as shown at: Section 17.1.3.1.1, “Linux kernel defconfig”.