User Tools

Site Tools


Sidebar

software:rhel:building_kernel_rhel7

building as RPM

My notes on compiling the RHEL kernel on RHEL7. Takes 90min on 4 cores 2.8Gzh with 6GB of RAM.

http://fedoraproject.org/wiki/Building_a_custom_kernel/Source_RPM

# lets start in registering the system and activate
# the devel repos
subscription-manager register --username=rhn-support-chorn \
  --name=chorn-rhel7-host
subscription-manager list --all --available >allsubs
less allsubs
subscription-manager subscribe --pool=<pool>
subscription-manager repos --disable='*' \
  --enable=rhel-7-server-extras-rpms \
  --enable=rhel-7-server-rpms \
  --enable=rhel-7-server-optional-rpms

# now install dependencies
yum groupinstall -y "Development Tools"
yum install -y ncurses-devel qt-devel hmaccalc zlib-devel \
  binutils-devel elfutils-libelf-devel rpmdevtools \
  yum-utils bc xmlto asciidoc python-devel newt-devel \
  pesign elfutils-devel audit-libs-devel numactl-devel \
  pciutils-devel perl-ExtUtils-Embed.noarch java-devel \
  asciidoc newt-devel pesign pciutils-devel
rpmdev-setuptree
# echo '%_topdir /root/rpmbuild' >~/.rpmmacros
cat .rpmmacros 

# fetch kernel sources and verify if rpmbuild prepare is ok
yumdownloader --source kernel
rpm -ivh kernel-3.10.0-*
cd ~/rpmbuild/SPECS
rpmbuild -bp --target=$(uname -m) kernel.spec

# lets verify if we got the expected directories
ls -d /root/rpmbuild/BUILD/kernel-3.10.0-*
ls -d /root/rpmbuild/BUILD/kernel-3.10.0-*/linux*

# lets start the build
cd ~/rpmbuild/
rpmbuild -bb --target=x86_64  SPECS/kernel.spec 

building from source

# lets start in registering the system and activate
# the devel repos
subscription-manager register --username=rhn-support-chorn \
  --name=chorn-rhel7-host
subscription-manager list --all --available >allsubs
less allsubs
subscription-manager subscribe --pool=<pool>
subscription-manager repos --disable='*' \
  --enable=rhel-7-server-extras-rpms \
  --enable=rhel-7-server-rpms \
  --enable=rhel-7-server-optional-rpms

# now install dependencies
yum groupinstall "Development Tools"
yum install ncurses-devel qt-devel hmaccalc zlib-devel \
  binutils-devel elfutils-libelf-devel rpmdevtools \
  yum-utils bc xmlto asciidoc python-devel newt-devel \
  pesign elfutils-devel audit-libs-devel numactl-devel \
  pciutils-devel perl-ExtUtils-Embed.noarch \
  asciidoc newt-devel pesign pciutils-devel

# get and extract kernel sources
cd /usr/src
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.13.tar.xz
tar xJf linux-4.14.13.tar.xz
ln -s linux-4.14.13 linux

# configure, using the kernel config from RHEL as
# starting point
cd linux
cp /boot/config-$(uname -r) .config
# the following will ask you just about the new/unanswered
# options.  If you feel lucky, just press <return> to stay
# with the suggested default.
make oldconfig

# build the kernel
make -j3
make modules_install

# deloys /boot/vmlinuz pointing to your new kernel,
# and /boot/initrd to the initramfs.
make install

# create grub2 entry
grub2-mkconfig  >/boot/grub2/grub.cfg

reboot

patch

### minimal specfile changes for a patch
$ diff kernel.spec.org kernel.spec
6a7
> %define buildid .local
377a379,380
> Patch1: nfs4.1_server_trunking_disc-fix2.patch
> 
686a690
> ApplyPatch nfs4.1_server_trunking_disc-fix2.patch

### a small patch, example
$ cat ../SOURCES/nfs4.1_server_trunking_disc-fix2.patch
diff -Naur ./fs/nfs/client.c ../nfs.org2/client.c
--- a/fs/nfs/client.c   2017-04-17 05:24:37.714782986 +0200
+++ b//fs/nfs/client.c  2017-04-17 05:27:53.642782986 +0200
@@ -433,7 +433,7 @@
 
 static bool nfs_client_init_is_complete(const struct nfs_client *clp)
 {
-       return clp->cl_cons_state != NFS_CS_INITING;
+       return clp->cl_cons_state <= NFS_CS_READY;
 }
 
 int nfs_wait_client_init_complete(const struct nfs_client *clp)

### building the modified kernel
$ rpmbuild -bp --target=$(uname -m) kernel.spec
software/rhel/building_kernel_rhel7.txt ยท Last modified: 2021/03/23 12:22 (external edit)