compiling custom kernel

Ralf Mardorf kde.lists at yahoo.com
Fri Dec 10 04:10:32 UTC 2021


On Thu, 9 Dec 2021 22:12:33 +0100, daggs wrote:
>https://wiki.ubuntu.com/Kernel/BuildYourOwnKernel

Hi,

I wouldn't build Ubuntu kernel packages this way. However, from that
link: "This takes the current configuration for each
architecture/flavour supported and calls menuconfig to edit its config
file."

The option to automagically configure to build modules only for attached
devices was seemingly dropped for "latest" kernels [1]. To manually
configure menuconfig is what I'm using, too, but I don't use it to
reduce the kernel's size.

Indeed, even building a bloated kernel, but for the used architecture
only, around (even <) 4 GiB tmpfs are usually enough space. IIUC the way
described by your link, the kernel gets automatically build for the
machine's architecture only.

"If the build is successful, a set of three .deb binary package files
will be produced in the directory above the build root directory. For
example after building a kernel with version "4.8.0-17.19" on an amd64
system, these three (or four) .deb packages would be produced"

When I build kernels packages for Ubuntu, I've done it the old
fashioned Debian way. I described this several times on the list, but
don't have got a link to the mailing list archive at hand. However, I
found a script at archives/ubuntu-studio-users/ [2]. Please ignore this
old script, the point is, that it's mentioning "make-kpkg", the old
fashioned Debian way to build kernel packages.

Today I tend to build kernel packages for another Linux distro with a
way more straight forward package management only.

I've got no idea why 12 GB aren't enough space. It should be
sufficient, you shouldn't run out of disk space or inodes.

Google for "make-kpkg", IIRC on day fakeroot behaviour changed, so this
might be (or might not be) a fishy thing of this script [2].

Regards,
Ralf

[1]
https://www.kernel.org/doc/html/latest/kbuild/kconfig.html

[2]
[rocketmouse at archlinux ~]$ cat /tmp/attachment.bin 
#!/bin/sh
# sudo sh rt4us-natty

# This script is for Ubuntu Studio 11.04 64-bit
# rt4us version 0.3.20112704-1 Ralf Mardorf

apt-get update
apt-get install fakeroot build-essential crash kexec-tools makedumpfile kernel-package kernel-wedge
apt-get build-dep linux
apt-get install libncurses5 libncurses5-dev libelf-dev asciidoc binutils-dev

## Variables to edit
 # The booted kernel and architecture that by default should fit to this script
 GENERIC=2.6.38-8-generic
 ARCH=x86_64

 # Kernel-rt to build is version
 KMAJOR=2.6.33
 KMINOR=.9
 KMICRO=-rt31

 # Directory where the source codes should be saved
 SRC_DIR=/usr/src

## Variables not to edit
 export KERNEL_UNAME=${KMAJOR}${KMINOR}${KMICRO}
 export SYSSRC=/usr/src/linux-headers-${KERNEL_UNAME}
 export KERNEL_MODLIB=/lib/modules/${KERNEL_UNAME}
 export MODULE_ROOT=/lib/modules/${KERNEL_UNAME}
 export SYSOUT=/usr/src/linux-headers-${KERNEL_UNAME}
 export CC=cc
 KERNEL_ORG=http://www.kernel.org/pub/linux/kernel/

clear
if [ $USER = "root" ] ; then
 if [ $(uname -m) != ${ARCH} ] ; then
  echo "#######################################"
  echo "You're running the wrong architecture"
  echo "Continuing anyway"
  echo "#######################################"
 fi
 if [ $(uname -r) != ${GENERIC} ] ; then
  echo "#######################################"
  echo "You're running the wrong kernel"
  echo "Continuing anyway"
  echo "#######################################"
 fi

 # Backup configuration, delete sources and packages in SRC_DIR
 cd $SRC_DIR
 cp linux-${KERNEL_UNAME}/.config config-${KERNEL_UNAME}_$(date +"%b-%d-%Y_%H-%M-%S")
 rm -r linux-${KERNEL_UNAME}
 rm linux-headers-${KERNEL_UNAME}_${KERNEL_UNAME}-10.00.Custom_*.deb
 rm linux-image-${KERNEL_UNAME}_${KERNEL_UNAME}-10.00.Custom_*.deb
 rm linux-${KMAJOR}${KMINOR}.tar.bz2 patch-${KERNEL_UNAME}.bz2
 
 # Download all sources to source directory
 wget ${KERNEL_ORG}v2.6/longterm/v${KMAJOR}/linux-${KMAJOR}${KMINOR}.tar.bz2
 wget ${KERNEL_ORG}projects/rt/patch-${KERNEL_UNAME}.bz2
 
 # Extracting and patching
 tar -jxf linux-${KMAJOR}${KMINOR}.tar.bz2
 mv linux-${KMAJOR}${KMINOR} linux-${KERNEL_UNAME}
 cd linux-${KERNEL_UNAME}
 bzip2 -dc ../patch-${KERNEL_UNAME}.bz2 | patch -p1
 rm ../linux-${KMAJOR}${KMINOR}.tar.bz2 ../patch-${KERNEL_UNAME}.bz2

 # Configuration
 # Add or remove options here
 # - Staging very often disables to build a rt patched kernel
 # - RT_GROUP_SCHED has to be disabled
 # - Debug and trace options might slow down the machine
 # - The default CPU frequency scaling might be important too
 # For processor type and features there should be enabled --->
 # - Tickless System (Dynamic Ticks)
 # - High Resolution Timer Support
 # - HPET Timer Support
 # - Preemption Mode (Complete Preemption (Real-Time))
 # - Timer frequency (1000 HZ)
 cp /boot/config-$(uname -r) .config
 echo "CONFIG_STAGING=n" >> .config
 echo "CONFIG_RT_GROUP_SCHED=n" >> .config
 echo "CONFIG_DEBUG_INFO=n" >> .config
 echo "CONFIG_DEBUG_KERNEL=n" >> .config
 echo "CONFIG_FTRACE=n" >> .config
 echo "CONFIG_PREEMPT_RT=y" >> .config
 echo "CONFIG_HZ_1000=y" >> .config
 # Optimize to CPU
 # It's possible to optimize to CPUs
 # e.g. set to CONFIG_MK8=y (Opteron/Athlon64/Hammer/K8), command out for default
 echo "CONFIG_MK8=y" >> .config
 
 # 32-bit only
 # HIGHMEM from 4G to 64G
 # echo "CONFIG_HIGHMEM4G is not set" >> .config
 # echo "CONFIG_HIGHMEM64G=y" >> .config
 
 # [...]
 make oldconfig

 # Building the kernel
 make-kpkg clean
 make-kpkg --rootcmd fakeroot --initrd kernel-image kernel-headers
 ## End

 # Additional commands
 # Add or remove any command you wish to run or not to run
 # Installing new packages
 make-kpkg clean
 dpkg -i ../linux-image-${KERNEL_UNAME}_${KERNEL_UNAME}-10.00.Custom_*.deb
 dpkg -i ../linux-headers-${KERNEL_UNAME}_${KERNEL_UNAME}-10.00.Custom_*.deb
 # Restoring grub.cfg on my machine
 cp /boot/grub/grub.cfg.natty /boot/grub/grub.cfg
 gedit /boot/grub/grub.cfg
 echo "-------------------------------"
 echo "Push any key to continue."
 echo "cp /boot/grub/grub.cfg"
 echo "   /boot/grub/grub.cfg.edubuntu"
 echo "-------------------------------"
 read any_pushed_key
 cp /boot/grub/grub.cfg /boot/grub/grub.cfg.natty

else
 echo "Run \"sudo sh rt4us-02\""
fi
exit 0




More information about the ubuntu-users mailing list