Kernel Build

Applying old config to new kernel

Copy existing .config to new kernel source tree:

cp kvm-vm-ext4-xfs.config /path/to/linux-7.x/.config
cd /path/to/linux-7.x

All new options set to NO (tightest result)

make KCONFIG_ALLCONFIG=.config allnoconfig

Keeps every option from old config, sets all new/unknown options to n. Kconfig auto-resolves dependencies — if existing CONFIG_VIRTIO_PCI=y now depends on new CONFIG_FOO, it gets force-enabled.

All new options set to their defaults

make olddefconfig

Usually n, but some may default to y. Less strict than allnoconfig.

List what is new

make listnewconfig

Prints every option old config doesn’t cover. Useful to scan before blanket-disabling.

Full recipe

cd /path/to/linux-7.x
cp /path/to/kvm-vm-ext4-xfs.config .config
make listnewconfig > new_options.txt
make KCONFIG_ALLCONFIG=.config allnoconfig
make -j$(nproc)

Building kernel src.rpm with mock

Install

sudo dnf install mock rpm-build
sudo usermod -aG mock $USER
newgrp mock

Build from source RPM

mock -r fedora-43-x86_64 --rebuild kernel-6.19.0-1.src.rpm

Results in /var/lib/mock/fedora-43-x86_64/result/.

Build from spec + sources

rpmbuild -bs kernel.spec \
  --define "_sourcedir $(pwd)" \
  --define "_srcrpmdir $(pwd)"

mock -r fedora-43-x86_64 --rebuild kernel-*.src.rpm

The spec expects linux.tar.gz as Source0 and config as Source1. Both must exist in same directory.

Useful mock flags

# Keep build tree for debugging
mock --no-clean --rebuild kernel-*.src.rpm

# Use specific config (EPEL, CentOS Stream, etc.)
mock -r centos-stream+epel-9-x86_64 --rebuild kernel-*.src.rpm

# Inject .config before build
mock --init
mock --copyin kvm-vm-ext4-xfs.config /builddir/build/SOURCES/config
mock --no-clean --rebuild kernel-*.src.rpm

# Speed up with tmpfs (needs RAM)
mock --enable-plugin=tmpfs --rebuild kernel-*.src.rpm

List available mock configs

ls /etc/mock/*.cfg

Controlling CPU count in mock

Default: all CPUs. Verify with:

rpm --eval '%_smp_mflags'

Override via mock define

mock -r fedora-43-x86_64 \
  --define "_smp_mflags -j16" \
  --rebuild kernel-*.src.rpm

Override via rpmbuild opts

mock -r fedora-43-x86_64 \
  --rpmbuild-opts="--define '_smp_mflags -j16'" \
  --rebuild kernel-*.src.rpm

Persistent mock config

In /etc/mock/custom.cfg:

config_opts['macros']['%_smp_mflags'] = '-j16'

Limit via cgroup

systemd-run --scope -p AllowedCPUs=0-15 \
  mock -r fedora-43-x86_64 --rebuild kernel-*.src.rpm

Quick reference

CPUs desiredFlag
All-j$(nproc)
16-j16
Half-j$(( $(nproc) / 2 ))