Rationale:
- I need a custom kernel (because sound won't work with vanilla)
- I want to use Fedora Atomic Host
- The only way to override the kernel with Fedora Atomic Host is to install a kernel package using
ostree-rpm
- I have a metered network connection and want to avoid downloading the kernel sources too many times
- The powerful machine that can build the kernel is nor running Fedora or Red-hat based system with rpmbuild available
You need the following Dockerfile
in an empty directory:
FROM fedora:27
RUN dnf -y groupinstall 'Development Tools'
RUN dnf -y install fedora-packager
RUN dnf -y install rpmdevtools
RUN dnf -y install dnf-utils
RUN dnf -y install numactl-devel pesign
RUN dnf -y install sudo
RUN dnf builddep -y kernel
RUN dnf -y install flex bison
RUN sed -i.bak -n -e '/^Defaults.*requiretty/ { s/^/# /;};/^%wheel.*ALL$/ { s/^/# / ;} ;/^#.*wheel.*NOPASSWD/ { s/^#[ ]*//;};p' /etc/sudoers
RUN useradd -s /bin/bash -G adm,wheel,systemd-journal -m rpm
WORKDIR /home/rpm
USER rpm
RUN rpmdev-setuptree
WORKDIR /home/rpm/rpmbuild
RUN echo HOME=$HOME
Then, create a docker image by building it: docker build -t rpmbuild .
Clone the repository: git clone https://src.fedoraproject.org/git/rpms/kernel.git rpms-kernel
Update the kernel.spec
according to your kernel version. in my case I have a kernel v4.14.24
and I want to suffix it with .4102.gec2d27324588.mildred
(a chromiumos kernel):
-%global released_kernel 0
+%global released_kernel 1
-# define buildid .local
+%define buildid .4102.gec2d27324588.mildred
-%define base_sublevel 15
+%define base_sublevel 14
-%define stable_update 0
+%define stable_update 24
Then update the %build
section to use .config
instead of copying from configs/*
, and avoid running make mrproper
before the build if you want to save on some build time:
@@ -1226,14 +1226,15 @@ BuildKernel() {
# and now to start the build process
- make %{?make_opts} mrproper
- cp configs/$Config .config
+ #make %{?make_opts} mrproper
+ #cp configs/$Config .config
%if %{signkernel}%{signmodules}
cp %{SOURCE11} certs/.
%endif
Arch=`head -1 .config | cut -b 3-`
+ Arch=x86_64
echo USING ARCH=$Arch
make %{?make_opts} ARCH=$Arch olddefconfig >/dev/null
(You need to manually specify the Arch because it may not be in the .config
file)
Run rpmbuild through docker:
mkdir -p BUILD/kernel-4.14.fc27 && \
docker run -ti --name=rpmbuild \
-v $PWD/rpms-kernel/kernel.spec:/home/rpm/rpmbuild/SPECS/kernel.spec \
-v $PWD/rpms-kernel:/home/rpm/rpmbuild/SOURCES \
-v $PWD/RPMS:/home/rpm/rpmbuild/RPMS \
-v $PWD/SRPMS:/home/rpm/rpmbuild/SRPMS \
-v $PWD/BUILD:/home/rpm/rpmbuild/BUILD \
-v $PWD/linux:/home/rpm/rpmbuild/BUILD/kernel-4.14.fc27/linux-4.14.24-1.4102.gec2d27324588.mildred.fc27.x86_64/ \
-v /dev/zero:/home/rpm/rpmbuild/SOURCES/linux-4.14.tar.xz:ro \
rpmbuild \
rpmbuild -bb \
--without debug --without doc --without perf --without tools --without debuginfo \
--without kdump --without bootwrapper --without cross_headers \
--nocheck --noclean --noprep \
SPECS/kernel.spec
Here $PWD/linux
contains the git checkout of the linux source tree. The name inside the container has to be adjusted too. $PWD/rpms-kernel
is the checkout containing the kernel.spec
you adjusted.
The BUILD/kernel-*
directory must be owned by the rpm
user inside the docker container so it won't fail after the build.