User talk:Falconindy

From ArchWiki
Revision as of 19:30, 21 February 2010 by Falconindy (talk | contribs) (Created page with 'Category:Kernel (English) Category:HOWTOs (English) {{i18n|Custom Kernel Compilation with ABS}} === Introduction === There are many ways to build the kernel in Arch; th…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی


There are many ways to build the kernel in Arch; this is just one example. For other possibilities, see Kernel Compilation. Some Arch users prefer the traditional way, however using ABS is helpful for automating certain tasks. As with anything in Arch, the choice is yours! Neither way is inherently better than the other.

This how-to has been updated to provide a definitive PKGBUILD for the creation of custom kernel packages. It allows you to maintain multiple custom kernels with a unique naming scheme under pacman version control. It is ideal for almost any custom kernel build and can be easily adapted to fit many requirements. The PKGBUILD automatically accounts for the modified pkgname and appends your custom suffix to the the kernel's .config.

This how-to also assumes that you are compiling a recent kernel (a 2.6 series kernel released in the past 2-3 years).

Note that this is not an ABS howto - to successfully follow this how-to, a working knowledge of building packages with ABS is essential. Please read Arch Build System, Creating Packages and Patching in ABS.

Philosophy and Logic (how it works and why it works this way)

  • The Arch Way - Keep It Simple.
  • This PKGBUILD is based on the official method used by Arch devs.
  • This build provides kernel packages and components with a simple, logical and uncomplicated naming scheme that ONLY uses variables that are part of the ABS system and part of the kernel compilation process itself. If you want to prefix your kernel with your name, or reference to a patch involved, simply name the package as such, (e.g. kernel26-ckzero) and your kernel will be named similarly.
  • If you are familiar with ABS you will see that the PKGBUILD is transparently constructed, self-explanatory and can be customized easily.
  • User input is almost identical to all ABS builds: simply set pkgver, pkgrel and pkgdesc and add additional sources, including patches, to the source array. Patch users should insert the appropriate patch commands where indicated. Aside from uncommenting the config method and choosing whether to make clean or not the rest of the build is automated.
Note: For the duration of this article, -ckzero is the custom suffix. Anywhere you see this, you can (read: must) safely replace this with your own suffix.

Usage Notes

  • pkgname must be declared within 10 lines of the top of the PKGBUILD - so DO NOT move it - just leave it.

If you miss this simple instruction don't worry, it won't screw up your build but your PKGBUILD file will not have the pkgname automatically updated at the end of the build. This is to allow you to use gensync correctly BUT you can edit the PKGBUILD file manually afterwards of course.

  • Until you have your own config that you are happy with it is easiest just to start with the default Arch config; you should also get the Arch kernel26.install file, make your own kernel26.install script or comment out the line install=kernel26.install from the PKGBUILD. The official Arch files are both in your ABS tree, normally under /var/abs/core/kernel26. To download the ABS tree to your system simply run abs as root. It doesn't take long, even on dialup. You should keep this updated by running abs as root on a regular basis.
NOTE: If you use LILO or any other static bootloader (that is, one that requires update after every kernel change) you are advised to use an install file too. This is an example, kernel26.install, for use with Lilo:

  • If used correctly this PKGBUILD should always provide a unique kernel build based on EXTRAVERSION and LOCALVERSION, and on the pkgver and pkgrel (as normal) - however it is up to the user to double check resulting pkgnames and contents before installation to prevent overwrites (see below for more details and examples).

Anatomy of the PKGBUILD

This PKGBUILD is based on the split package that was introduced with the 2.6.32 kernel series. This gives you the flexibility of only installing what you want out of your custom kernel (e.g. you may not need the headers). This does, however, mean a little extra responsibility on the user's part to ensure that we build and package cleanly.

Check out the core/kernel26 port from ABS, and use the modified PKGBUILD below. Before building remember the following:

  1. pkgbase should be changed to be unique. This is what the kernel will be named.
  2. Elements in the pkgname array need to be updated as well, and should match the pkgbase provided above. This is what the built packages will be named.
  3. Insert the pkgver for your kernel (for example: 2.6.9).
  4. Change the pkgrel for your current revision. You should increment this each time you make changes to the kernel config and want to build a REPLACEMENT pkg. If you don't want to replace the previous build but rather install in parallel you should use LOCALVERSION to create a unique pkg.
  5. Change/expand the pkgdesc to describe any patches or special config options applied.
  6. Change the source to use a closer mirror and if you are using a patchset, add the patches to the source array.
  7. {OPTIONAL} Place the patch commands where indicated.
  8. Choose a make method by leaving your preferred method uncommented - gconfig (gtk based) xconfig (qt based) menuconfig (ncurses based).
Warning: This PKGBUILD makes some modifications from the one available directly from ABS. It will not build the firmware package as it assumes you will keep the vanilla ARCH kernel installed.

{{File|name=PKGBUILD|content= pkgbase="kernel26-ckzero" pkgname=('kernel26-ckzero' 'kernel26-ckzero-headers') _kernelname=${pkgname#kernel26} _basekernel=2.6.32 pkgver=${_basekernel}.8 pkgrel=1 _patchname="patch-${pkgver}-${pkgrel}-ARCH" arch=(i686 x86_64) license=('GPL2') url="" source=($_basekernel.tar.bz2${_patchname}.bz2
       # the main kernel config files
       config config.x86_64
       # standard config files for mkinitcpio ramdisk



build() {

 cd ${srcdir}/linux-$_basekernel
 # The ARCH patchset provides:
 #  - Official patches from to bring a base kernel up to the current patch
 #       (i.e. kernel 2.6.32 + =
 #  - Arch logo on bootup
 #  - Patches to allow Aufs to be used as an external module
 # Add -ARCH patches
 # See
 patch -Np1 -i ${srcdir}/${_patchname}  return 1
 # The stock Arch kernel enables the config option to save your kernel in /proc. You can reuse it:
 #   zcat /proc/config.gz  >./.config
 # Comment or delete the lines below if you choose to do this.
 if [ "$CARCH" = "x86_64" ]; then
   cat ../config.x86_64 >./.config
   cat ../config >./.config
 if [ "${_kernelname}" != "" ]; then
   sed -i "sCONFIG_LOCALVERSION=.*CONFIG_LOCALVERSION=\"${_kernelname}\"g" ./.config
 # get kernel version  
 make prepare
 # load configuration
 # Configure the kernel. Uncomment one of the lines below to change the kernel config
 #  before compiling
 # make menuconfig # CLI menu for configuration
 # make xconfig # X-based configuration
 # make oldconfig # using old config from previous kernel version
 yes ""  make config
 # build!
 make bzImage modules  return 1


package_kernel26-ckzero() {

 pkgdesc="The Linux Kernel and modules"
 depends=('coreutils' 'kernel26-firmware>=2.6.32' 'module-init-tools' 'mkinitcpio>=0.5.20')
 # pwc, ieee80211 and hostap-driver26 modules are included in kernel26 now
 # nforce package support was abandoned by nvidia, kernel modules should cover everything now.
 # kernel24 support is dropped since glibc24
 replaces=('kernel24' 'kernel24-scsi' 'kernel26-scsi'
           'alsa-driver' 'ieee80211' 'hostap-driver26'
           'pwc' 'nforce' 'squashfs' 'unionfs' 'ivtv'
           'zd1211' 'kvm-modules' 'iwlwifi' 'rt2x00-cvs'
           'gspcav1' 'atl2' 'wlan-ng26' 'rt2500')
 optdepends=('crda: to set the correct wireless channels of your country')
 cd ${srcdir}/linux-$_basekernel
 # get kernel version
 _kernver="$(make kernelrelease)"
 mkdir -p ${pkgdir}/{lib/modules,boot}
 make INSTALL_MOD_PATH=${pkgdir} modules_install  return 1
 cp ${pkgdir}/boot/System.map26${_kernelname}
 cp arch/$KARCH/boot/bzImage ${pkgdir}/boot/vmlinuz26${_kernelname}
 #  # add vmlinux
 install -m644 -D vmlinux ${pkgdir}/usr/src/linux-${_kernver}/vmlinux
 # install fallback mkinitcpio.conf file and preset file for kernel
 install -m644 -D ${srcdir}/kernel26.preset ${pkgdir}/etc/mkinitcpio.d/${pkgname}.preset  return 1
 # set correct depmod command for install
 sed \
   -e  "s/KERNEL_NAME=.*/KERNEL_NAME=${_kernelname}/g" \
   -e  "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_kernver}/g" \
   -i $startdir/kernel26.install
 sed \
   -e "ssource .*source /etc/mkinitcpio.d/kernel26${_kernelname}.kverg" \
   -e "sdefault_image=.*default_image=\"/boot/${pkgname}.img\"g" \
   -e "sfallback_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}'" > ${pkgdir}/etc/mkinitcpio.d/${pkgname}.kver
 # remove build and source links
 rm -f ${pkgdir}/lib/modules/${_kernver}/{source,build}
 # remove the firmware
 rm -rf ${pkgdir}/lib/firmware


package_kernel26-headers() {

 pkgdesc="Header files and scripts for building modules for kernel26"
 mkdir -p ${pkgdir}/lib/modules/${_kernver}
 cd ${pkgdir}/lib/modules/${_kernver}
 ln -sf ../../../usr/src/linux-${_kernver} build
 cd ${srcdir}/linux-$_basekernel
 install -D -m644 Makefile \
 install -D -m644 kernel/Makefile \
 install -D -m644 .config \
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/include
 for i in acpi asm-{generic,x86} config linux math-emu media net pcmcia scsi sound trace video; do
   cp -a include/$i ${pkgdir}/usr/src/linux-${_kernver}/include/
 # copy arch includes for external modules
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/arch/x86
 cp -a arch/x86/include ${pkgdir}/usr/src/linux-${_kernver}/arch/x86/
 # copy files necessary for later builds, like nvidia and vmware
 cp Module.symvers ${pkgdir}/usr/src/linux-${_kernver}
 cp -a scripts ${pkgdir}/usr/src/linux-${_kernver}
 # fix permissions on scripts dir
 chmod og-w -R ${pkgdir}/usr/src/linux-${_kernver}/scripts
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/.tmp_versions
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/kernel
 cp arch/$KARCH/Makefile ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/
 if [ "$CARCH" = "i686" ]; then
   cp arch/$KARCH/Makefile_32.cpu ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/
 cp arch/$KARCH/kernel/asm-offsets.s ${pkgdir}/usr/src/linux-${_kernver}/arch/$KARCH/kernel/
 # add headers for lirc package
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video
 cp drivers/media/video/*.h  ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video/
 for i in bt8xx cpia2 cx25840 cx88 em28xx et61x251 pwc saa7134 sn9c102 usbvideo zc0301; do
  mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video/$i
  cp -a drivers/media/video/$i/*.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/video/$i
 # add docbook makefile
 install -D -m644 Documentation/DocBook/Makefile \
 # add dm headers
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/md
 cp drivers/md/*.h  ${pkgdir}/usr/src/linux-${_kernver}/drivers/md
 # add inotify.h
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/include/linux
 cp include/linux/inotify.h ${pkgdir}/usr/src/linux-${_kernver}/include/linux/
 # add wireless headers
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/net/mac80211/
 cp net/mac80211/*.h ${pkgdir}/usr/src/linux-${_kernver}/net/mac80211/
 # add dvb headers for external modules
 # in reference to:
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/dvb-core
 cp drivers/media/dvb/dvb-core/*.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/dvb-core/
 # add dvb headers for external modules
 # in reference to:
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/include/config/dvb/
 cp include/config/dvb/*.h ${pkgdir}/usr/src/linux-${_kernver}/include/config/dvb/
 # add dvb headers for
 # in reference to:
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends/
 cp drivers/media/dvb/frontends/lgdt330x.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends/
 cp drivers/media/video/msp3400-driver.h ${pkgdir}/usr/src/linux-${_kernver}/drivers/media/dvb/frontends/
 # add xfs and shmem for aufs building
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/fs/xfs
 mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/mm
 cp fs/xfs/xfs_sb.h ${pkgdir}/usr/src/linux-${_kernver}/fs/xfs/xfs_sb.h
 # add headers vor virtualbox
 # in reference to:
 cp -a include/drm $pkgdir/usr/src/linux-${_kernver}/include/
 # add headers for broadcom wl
 # in reference to:
 cp -a include/trace $pkgdir/usr/src/linux-${_kernver}/include/
 # copy in Kconfig files
 for i in `find . -name "Kconfig*"`; do 
   mkdir -p ${pkgdir}/usr/src/linux-${_kernver}/`echo $i  sed 's/Kconfig.*'`
   cp $i ${pkgdir}/usr/src/linux-${_kernver}/$i
 cd ${pkgdir}/usr/src/linux-${_kernver}/include && ln -s asm-$KARCH asm
 # add header for aufs2-util
 cp -a ${srcdir}/linux-$_basekernel/include/asm-generic/bitsperlong.h ${pkgdir}/usr/src/linux-${_kernver}/include/asm/
 chown -R root.root ${pkgdir}/usr/src/linux-${_kernver}
 find ${pkgdir}/usr/src/linux-${_kernver} -type d -exec chmod 755 {} \;
 # remove unneeded architectures
 rm -rf ${pkgdir}/usr/src/linux-${_kernver}/arch/{alpha,arm,arm26,avr32,blackfin,cris,frv,h8300,ia64,m32r,m68k,m68knommu,mips,microblaze,mn10300,parisc,powerpc,ppc,s390,sh,sh64,sparc,sparc64,um,v850,xtensa}

} }}

  • Install your new pkg as normal.

Your .config file

PLEASE NOTE: during the build the final kernel config is stored in your $startdir as, for example, config-Apr13-12h. Your original config remains in the $startdir named config. If you wish to use the new config in another build make sure you copy the correct file!

Common .config Changes

  • The default Arch kernel is built for a generic i686 or x86_64 processor. You can compile for your specific architecture. On a 64-bit build, you'll see the following:


  • Preemptable RCU. This produces some mild improvement in desktop response for multi-core and/or multi-threading systems.


I Want the Arch logo!

Note: If you use the -ARCH patchset mentioned in the provided PKGBUILD, this is already included. If you opt not to use the patchset, you can still get the logo by doing the following

Download the logo_linux_clut224.ppm to your $startdir from:

Add the the file logo_linux_clut224.ppm to the source array, and add the copy command marked with (>>) below into the PKGBUILD as indicated:

   ##### Uncomment and apply any patches here
   #patch -Np1 -i ../patchname || return 1

>>  ##### Arch logo - not compatible with gensplash!
>>  cp ../logo_linux_clut224.ppm drivers/video/logo/

   # get rid of the 'i' in i686
   carch=`echo $CARCH | sed 's|i||'`
   cat ../config | sed "s|#CARCH#|$carch|g" >./.config

The stock Arch config uses the following logo settings, ensure you set them at the config stage or use the stock config:

# Logo configuration

Install Scriptlet

Chances are high that you'll want to use a .install scriptlet to automate the creation and installation of boot images. Don't forget to replace the two declarations at the top of the file to match your suffix. Below is an example of a slimmed down script for handling a kernel that uses a boot image.


Tip: If your config doesn't use a boot image, the only thing this script needs to do is run depmod $KERNELNAME.

Post Installation

Once you have your kernel installed, don't forget to add a new entry to your bootloader to load the new kernel. See Wiki pages about GRUB, GRUB2, or Lilo for more info on how to create these entries.


My kernel's version has a hash sum and/or 'dirty' appended to it!
  • Make sure that you're not building within the confines of a Git, SVN, or Mercurial repository. During the compilation process, the kernel will check for the presence of a repository, whether for the kernel or not, and append to the LOCALVERSION.

Using the nVIDIA video driver with your custom kernel

To use the nvidia driver with your new custom kernel, see: How to install NVIDIA driver with custom kernel

Original article written by DibbleTheWrecker. Updated by Falconindy.