1. 编译镜像准备
使用rockylinux:9
的容器镜像创建一个容器实例:
sudo docker run -it rockylinux:9 bash
在容器实例中,运行以下命令准备内核的编译环境:
yum makecache
dnf install -y 'dnf-command(config-manager)'
dnf config-manager --set-enabled crb
yum install -y vim rpm-build python3-devel elfutils-devel openssl-devel \
perl-generators pesign yum-utils bc bison bpftool dwarves flex gcc gcc-c++ \
git-core hmaccalc kmod m4 make net-tools perl-devel gcc-plugin-devel rpm-build \
rpmdevtools dnf-plugins-core ncurses-devel make gcc bc bison flex elfutils-libelf-devel \
openssl-devel grub2 rpm-build rsync gcc vim yum-utils perl systemd-udev \
asciidoc audit-libs-devel binutils-devel clang dwarves fuse-devel gcc-c++ \
gcc-plugin-devel git-core glibc-static java-devel kabi-dw kernel-rpm-macros \
libbabeltrace-devel libbpf-devel libcap-devel libcap-ng-devel libmnl-devel \
libnl3-devel libtraceevent-devel libtracefs-devel lld llvm lvm2 net-tools \
newt-devel numactl-devel pciutils-devel perl-devel python3-docutils system-sb-certs \
tpm2-tools xmlto elfutils-devel nss-tools perl-generators pesign python3-devel xz-devel
# download the following packages offlinely
yum install -y WALinuxAgent-cvm-2.7.0.6-9.el9_2.1.rocky.0.noarch.rpm systemd-boot-unsigned-252-14.el9_2.1.x86_64.rpm
useradd -m mock
新建一个终端,在该终端上将运行中且已做上述修改的容器实例提交为容器镜像以便下次使用:
[root@dellnew ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f7eb549f3d44 rockylinux:9 "bash" 7 minutes ago Up 7 minutes wonderful_sinoussi
[root@dellnew ~]# docker commit wonderful_sinoussi buidrockykernel:latest
[root@dellnew ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
buidrockykernel latest 207a4b57059e 5 seconds ago 1.94GB
2. 使用容器编译内核
使用上节创建的编译镜像编译内核:
[root@text ~]# docker run --name=testrocky -v /root/buildout:/buildout -it buidrockykernel:latest /bin/bash
[root@fa4d8f532c21 /]# cp /buildout/kernel-5.15.113-200.el9.src.rpm /home/mock/
[root@fa4d8f532c21 /]# su - mock
[mock@fa4d8f532c21 ~]$ rpm -Uvh kernel-5.15.113-200.el9.src.rpm
[mock@fa4d8f532c21 ~]$ cd rpmbuild/SPECS/
[mock@fa4d8f532c21 SPECS]$ time rpmbuild -ba kernel.spec 2>&1 | tee build.log
编译出的内核rpm包位于/home/mock/rpmbuild下,可以通过find /home/mock/rpmbuild | grep rpm$
命令找到。
3. 编译更改细节记录
$ dnf config-manager --set-enabled crb
$ yum install -y vim rpm-build python3-devel elfutils-devel openssl-devel \
perl-generators pesign yum-utils bc bison bpftool dwarves flex gcc gcc-c++ git-core\
hmaccalc kmod m4 make net-tools perl-devel gcc-plugin-devel
$ vim /etc/yum.repos.d/kernellongterm.repo
[copr:copr.fedorainfracloud.org:kwizart:kernel-longterm-5.15]
name=Copr repo for kernel-longterm-5.15 owned by kwizart
baseurl=贵司mg词
type=rpm-md
skip_if_unavailable=True
gpgcheck=1
gpgkey=贵司mg词
repo_gpgcheck=0
enabled=1
enabled_metadata=1
$ yum makecache
切换为Mock用户后,按以下命令操作:
$ yumdownloader --source kernel-longterm
$ ls
kernel-longterm-5.15.124-200.el9.src.rpm
$ rpm -Uvh kernel-longterm-5.15.124-200.el9.src.rpm
$ ls
kernel-longterm-5.15.124-200.el9.src.rpm rpmbuild
更改kernel.spec文件中的 5.15.113-1
, 具体记录如下:
$ cp linux-5.15.tar.xz ./rpmbuild/SOURCES/linux-5.15.tar.xz
$ vim rpmbuild/SPECS/kernel.spec
Line 135?
# Do we have a -stable update to apply?
#%define stable_update 124
%define stable_update 113
%define rpmversion %{kversion}.%{stable_update}
%define patchversion 5.15
#%define pkgrelease 200
%define pkgrelease 1
1400 # released_kernel with possible stable updates
1401 # This is special because the kernel spec is hell and nothing is consistent
1402 #xzcat %{SOURCE5000} | patch -p1 -F1 -s
1403 #xzcat %{SOURCE5000} | patch -p1 -F1 -s
1404 git commit -a -m "Stable update"
1405
1406 # Note: Even in the "nopatches" path some patches (build tweaks and compile
1407 # fixes) will always get applied; see patch defition above for details
1408
1409 #git am %{patches}
1410 #git am %{patches}