Kernel PKGBUILD proposition: Ease custom kernel compilation.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Hi all!

Since a couple of years of using Arch, I often wanted to compile a custom kernel, as many others did. There is many, many, many! forum threads about that, a couple of wiki pages too, with questions and howtos.

Many efforts has been put to create new PKGBUILDs[1-2] to ease the effort of this. Unfortunately, these PKGBUILDs suffer from some drawback:
1) They are placed on a wiki which can be edited by everybody. This mean it is not a trusted place to store a PKGBUILD, specifically one as vital as the kernel's.
2) They tend to be forgotten and not updated anymore. This can lead to an unbootable kernel, rendering all this useless.
3) They do not take advantage of the devs' work: They are the best one to trust for a quality PKGBUILD. They also have all the feedback from Arch users, bug reports, etc. They know what has changed in the kernel and what needs to be adapted for the installation, for example new "provides=()". A PKGBUILD from a wiki page or a forum post might be good at the time of post, but be outdated just days latter...
4) They build a kernel which is way different then the stock one, for example because they don't have the same patchset.

Users most often wants to build a custom kernel just to try it, change some configurations, add one or two patch, optimize for their own machines, etc. Maily, they just want to take the existing one, change a couple of things, and be ready. One also wants to install this kernel side by side with the stock one, at least until his own kernel is stabilized and running as wanted. Actually, Arch's stock kernel does not allow that.

What I propose is some simple modifications to the PKGBUILD so users can try to compile their own kernel based on the original, trusted, working and approved one. With theese modifications, one only needs to add a "kernel name" to the pkgname: "pkgname=kernel26-mykernel" for example. Nothing else is needed to compile a custom kernel. The created package would sit without problem side by side with the stock kernel. Also, if the pkgname is kept to "kernel26", then the stock -ARCH kernel will be built.

This approach has many advatanges:
1) The patch is relativelly small: not much is changed in the original PKGBUILD.
1) Nothing changes for the devs. They continue to provide a quality kernel to Arch users.
2) Users who wants to compile a custom kernel can just sync abs, change the pkgname and install a new kernel, in the KISS philosophy. They know that if they just change the name, they will have the same package so they can easily test whatever feature/patch/bug solution/optimization they want.
3) Because one only needs to change the pkgname, they use the devs' high quality, tried and truth PKGBUILD. When a new kernel is out, they can sync the devs' modifications easily.
4) Bugs affecting the kernel can be easily tested for solutions. Affected users just need to compile a "-testing" kernel where a patch is applied, install it and see if it works, without having to risk breaking his system by replacing -ARCH kernel with an unbootable one.
5) Better feedback to the devs since the users would be using (almost) the same PKGBUILD as the original one.
6) Simplify a lot all these "custom kernels" threads and wiki posts.

I did "maintained" such a patch for myself because I wanted to keep in sync with the original PKGBUILD. After posting it on the forum[3], I got some positive feedback. People reporting back said they liked the simplicity and the effectiveness of the method. They also positively tested it with different configuration. The patch should be applied to revision 19747 for i686 or 19749 for x86_64. It modifies the PKGBUILD and also slightly the kernel26.install and kernel26.preset file.

I am thus reporting this to be include in the official file. I think it would be a great addition to an already great distro. I am open to discussion on the subject. I hope I am posting this on the right mailing list and that it can be included! :)

Sincerely,

big_gie

[1] http://wiki.archlinux.org/index.php/Kernel_Compilation_with_ABS
[2] http://wiki.archlinux.org/index.php/Custom_Kernel_Compilation_with_ABS
[3] http://bbs.archlinux.org/viewtopic.php?id=37579


diff -Naur core/PKGBUILD mod/PKGBUILD
--- core/PKGBUILD	2008-12-07 00:05:22.000000000 -0500
+++ mod/PKGBUILD	2008-12-07 15:59:44.000000000 -0500
@@ -1,9 +1,12 @@
 # $Id: PKGBUILD 19603 2008-11-28 10:51:49Z tpowa $
 # Maintainer: Tobias Powalowski <tpowa@xxxxxxxxxxxxx>
 # Maintainer: Thomas Baechler <thomas@xxxxxxxxxxxxx>
-pkgname=kernel26
+# pkgname=kernel26     # Build stock -ARCH kernel
+# pkgname=kernel26-nb    # Build kernel with a different name
+pkgname=kernel26-eee
+_kernelname=${pkgname:8}
 _basekernel=2.6.27
-pkgver=2.6.27.7
+pkgver=${_basekernel}.7
 pkgrel=1
 _patchname="patch-${pkgver}-${pkgrel}-ARCH"
 pkgdesc="The Linux Kernel and modules"
@@ -37,16 +40,43 @@
 build() {
   KARCH=x86
 
+  # Change kernel name in kernel26.preset and kernel26.install
+  sed \
+    -e  "s/ALL_kver='.*/ALL_kver='${_basekernel}${_kernelname}'/g" \
+  -i $startdir/kernel26.preset
+  if [ "${_kernelname}" == "" ]; then
+    sed \
+      -e  "s/KERNEL_NAME=.*/KERNEL_NAME=/g" \
+      -e  "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_basekernel}/g" \
+    -i $startdir/kernel26.install
+  else
+    sed \
+      -e  "s/KERNEL_NAME=.*/KERNEL_NAME=${_kernelname}/g" \
+      -e  "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_basekernel}${_kernelname}/g" \
+    -i $startdir/kernel26.install
+  fi
+
   cd ${srcdir}/linux-$_basekernel
+  # Don't repatch if already patched. One can then use "makepkg -e"
+  if [[ ! -e _arch_patched ]]; then
   # Add -ARCH patches
   # See http://projects.archlinux.org/git/?p=linux-2.6-ARCH.git;a=summary
   patch -Np1 -i ${srcdir}/${_patchname} || return 1
+  touch _arch_patched
+  else
+    msg "Already patched, skipping."
+  fi
+  msg "Patches done, continuating with compilation..."
 
   if [ "$CARCH" = "x86_64" ]; then
     cat ../config.x86_64 >./.config
   else
     cat ../config >./.config
   fi
+  # Change kernel name in config file
+  if [ "${_kernelname}" != "" ]; then
+    sed -i "s|CONFIG_LOCALVERSION=.*|CONFIG_LOCALVERSION=\"${_kernelname}\"|g" ./.config
+  fi
   # build the full kernel version to use in pathnames
   . ./.config
   ### next line is only needed for rc kernels
@@ -64,8 +94,9 @@
   make bzImage modules || return 1
   mkdir -p ${pkgdir}/{lib/modules,boot}
   make INSTALL_MOD_PATH=${pkgdir} modules_install || return 1
-  cp System.map ${pkgdir}/boot/System.map26
-  cp arch/$KARCH/boot/bzImage ${pkgdir}/boot/vmlinuz26
+  cp System.map ${pkgdir}/boot/System.map26${_kernelname}
+  cp arch/$KARCH/boot/bzImage ${pkgdir}/boot/vmlinuz26${_kernelname}
+  cp .config ${pkgdir}/boot/config${_kernelname}
   install -D -m644 Makefile \
     ${pkgdir}/usr/src/linux-${_kernver}/Makefile
   install -D -m644 kernel/Makefile \
@@ -140,10 +171,20 @@
   cd ${pkgdir}/lib/modules/${_kernver} && \
     (rm -f source build; ln -sf ../../../usr/src/linux-${_kernver} build)
   # install fallback mkinitcpio.conf file and preset file for kernel
-  install -m644 -D ${srcdir}/${pkgname}.preset ${pkgdir}/etc/mkinitcpio.d/${pkgname}.preset || return 1
-  # set correct depmod command for install
-  sed -i -e "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_kernver}/g" $startdir/kernel26.install
+  install -m644 -D ${srcdir}/kernel26.preset ${pkgdir}/etc/mkinitcpio.d/${pkgname}.preset || return 1
+  sed \
+    -e "s|source .*|source /etc/mkinitcpio.d/kernel26${_kernelname}.kver|g" \
+    -e "s|ALL_kver=.*|ALL_kver='${_basekernel}${_kernelname}'|g" \
+    -e "s|default_image=.*|default_image=\"/boot/${pkgname}.img\"|g" \
+    -e "s|fallback_image=.*|fallback_image=\"/boot/${pkgname}-fallback.img\"|g" \
+    -i ${pkgdir}/etc/mkinitcpio.d/${pkgname}.preset
   echo -e "# DO NOT EDIT THIS FILE\nALL_kver='${_kernver}'" > ${startdir}/pkg/etc/mkinitcpio.d/${pkgname}.kver
   # remove unneeded architectures
   rm -rf ${pkgdir}/usr/src/linux-${_kernver}/arch/{alpha,arm,arm26,avr32,blackfin,cris,frv,h8300,ia64,m32r,m68k,m68knommu,mips,mn10300,parisc,powerpc,ppc,s390,sh,sh64,sparc,sparc64,um,v850,xtensa}
+
+  # If not default kernel, remove firmwares since -ARCH will
+  # provide them.
+  if [ "${_kernelname}" != "" ]; then
+    rm -fr ${pkgdir}/lib/firmware
+  fi
 }
diff -Naur core/kernel26.install mod/kernel26.install
--- core/kernel26.install	2008-12-07 00:05:22.000000000 -0500
+++ mod/kernel26.install	2008-12-07 15:59:44.000000000 -0500
@@ -1,6 +1,7 @@
 # arg 1:  the new package version
 # arg 2:  the old package version
 
+KERNEL_NAME=
 KERNEL_VERSION=2.6.27-ARCH
 
 post_install () {
@@ -16,7 +17,7 @@
   echo ">>> http://wiki.archlinux.org/index.php/Mkinitcpio";
   echo ""
   echo ">>> Generating initial ramdisk, using mkinitcpio.  Please wait..."
-  /sbin/mkinitcpio -p kernel26
+  /sbin/mkinitcpio -p kernel26${KERNEL_NAME}
 }
 
 post_upgrade() {
@@ -88,8 +89,8 @@
     echo ">>> Please change your bootloader config files:"
     echo ">>> Grub: /boot/grub/menu.lst | Lilo: /etc/lilo.conf"
     echo "------------------------------------------------"
-    echo "| - initrd26.img to kernel26.img               |"
-    echo "| - initrd26-full.img to kernel26-fallback.img |"
+    echo "| - initrd26.img to kernel26${KERNEL_NAME}.img               |"
+    echo "| - initrd26-full.img to kernel26${KERNEL_NAME}-fallback.img |"
     echo "------------------------------------------------"
   fi
   if [ "`vercmp $2 2.6.19`" -lt 0 ]; then
@@ -121,11 +122,11 @@
   echo ""
   echo ">>> Generating initial ramdisk, using mkinitcpio.  Please wait..."
 if [ "`vercmp $2 2.6.19`" -lt 0 ]; then
-  /sbin/mkinitcpio -p kernel26 -m "ATTENTION:\nIf you get a kernel panic below
+  /sbin/mkinitcpio -p kernel26${KERNEL_NAME} -m "ATTENTION:\nIf you get a kernel panic below
 and are using an Intel chipset, append 'earlymodules=piix' to the
 kernel commandline"
 else
-  /sbin/mkinitcpio -p kernel26
+  /sbin/mkinitcpio -p kernel26${KERNEL_NAME}
 fi
 if [ "`vercmp $2 2.6.21`" -lt 0 ]; then
   echo ""
diff -Naur core/kernel26.preset mod/kernel26.preset
--- core/kernel26.preset	2008-12-07 00:05:22.000000000 -0500
+++ mod/kernel26.preset	2008-12-07 15:59:44.000000000 -0500
@@ -4,6 +4,7 @@
 # DO NOT EDIT THIS LINE:
 source /etc/mkinitcpio.d/kernel26.kver
 ########################################
+ALL_kver='2.6.27'
 ALL_config="/etc/mkinitcpio.conf"
 
 PRESETS=('default' 'fallback')
@@ -14,4 +15,4 @@
 
 #fallback_config="/etc/mkinitcpio.conf"
 fallback_image="/boot/kernel26-fallback.img" 
-fallback_options="-S autodetect"
\ No newline at end of file
+fallback_options="-S autodetect"

[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux