Difference between revisions of "User talk:Falconindy"

From ArchWiki
Jump to: navigation, search
(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…')
(Blanked the page)
Line 1: Line 1:
[[Category:Kernel (English)]]
[[Category:HOWTOs (English)]]
{{i18n|Custom Kernel Compilation with ABS}}
=== Introduction ===
There are many ways to build the kernel in Arch; this is just one example.  For other possibilities, see [[Kernel_Compilation|Kernel Compilation]].  Some Arch users prefer [[Kernel Compilation From Source|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 <code>pkgname</code> 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 <code>pkgver</code>, <code>pkgrel</code> and <code>pkgdesc</code> and add additional sources, including patches, to the <code>source</code> array.  Patch users should insert the appropriate patch commands where indicated.  Aside from uncommenting the config method and choosing whether to <code>make clean</code> 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 ===
* <code>pkgname</code> must be declared within 10 lines of the top of the PKGBUILD - so '''DO NOT''' move it - just leave it.<br>
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 <code>kernel26.install</code> file, make your own <code>kernel26.install</code> script or comment out the line <code>install=kernel26.install</code> from the PKGBUILD. The official Arch files are both in your ABS tree, normally under <code>/var/abs/core/kernel26</code>.  To download the ABS tree to your system simply run <code>abs</code> as root. It doesn't take long, even on dialup.  You should keep this updated by running <code>abs</code> 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, <code>kernel26.install</code>, 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:
# <code>pkgbase</code> should be changed to be unique. This is what the kernel will be named.
# Elements in the <code>pkgname</code> array need to be updated as well, and should match the <code>pkgbase</code> provided above. This is what the built packages will be named.
# Insert the <code>pkgver</code> for your kernel (for example: <code>2.6.9</code>).
# Change the <code>pkgrel</code> 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 <code>LOCALVERSION</code> to create a unique pkg.
# Change/expand the <code>pkgdesc</code> to describe any patches or special config options applied.
# Change the source to use a closer mirror and if you are using a patchset, add the patches to the source array.
# {OPTIONAL} Place the patch commands where indicated.
# 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.}}
pkgname=('kernel26-ckzero' 'kernel26-ckzero-headers')
arch=(i686 x86_64)
        # 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 kernel.org 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 http://projects.archlinux.org/linux-2.6-ARCH.git/
  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 "s{{{|}}}CONFIG_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 System.map ${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 "s{{{|}}}source .*{{{|}}}source /etc/mkinitcpio.d/kernel26${_kernelname}.kver{{{|}}}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}'" > ${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:
  # http://bugs.archlinux.org/task/9912
  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:
  # http://bugs.archlinux.org/task/11194
  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 http://mcentral.de/hg/~mrec/em28xx-new
  # in reference to:
  # http://bugs.archlinux.org/task/13146
  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:
  # http://bugs.archlinux.org/task/14568
  cp -a include/drm $pkgdir/usr/src/linux-${_kernver}/include/
  # add headers for broadcom wl
  # in reference to:
  # http://bugs.archlinux.org/task/14568
  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 <code>.config</code> file ===
PLEASE NOTE:  during the build the '''final''' kernel config is stored in your <code>$startdir</code> as, for example, <code>config-Apr13-12h</code>.  Your '''original''' config remains in the <code>$startdir</code> named <code>config</code>.  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:
Processor type and features  --->
  Processor family --->
      ( ) Opteron/Athlon64/Hammer/K8
      ( ) Intel P4 / older Netburst based Xeon
      ( ) Core 2/newer Xeon
      ( ) Intel Atom
      ( ) Generic-x86-64
* Preemptable RCU. This produces some mild improvement in desktop response for multi-core and/or multi-threading systems.
General Setup --->
  RCU Subsystem --->
      RCU Implementation --->
        ( ) Tree-based hierarchical RCU
        (X) Preemptable tree-based hierarchical RCU
=== 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 <code>logo_linux_clut224.ppm</code> to your <code>$startdir</code> from: [http://projects.archlinux.org/linux-2.6-ARCH.git/tree/patches projects.archlinux.org/linux-2.6-ARCH.git/tree/patches]
Add the the file <code>logo_linux_clut224.ppm</code> to the source array, and add the copy command marked with (<code>>></code>) 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 &quot;s|#CARCH#|$carch|g&quot; >./.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.
# arg 1:  the new package version
# arg 2:  the old package version
post_install () {
  # updating module dependencies
  echo ">>> Updating module dependencies. Please wait ..."
  # generate init ramdisks
  echo ">>> ----------------"
  echo ">>> If you use LVM2, Encrypted root or software RAID,"
  echo ">>> Ensure you enable support in /etc/mkinitcpio.conf ."
  echo ">>> More information about mkinitcpio setup can be found here:"
  echo ">>> http://wiki.archlinux.org/index.php/Mkinitcpio"
  echo ""
  echo ">>> Generating initial ramdisk, using mkinitcpio.  Please wait..."
  /sbin/mkinitcpio -p kernel26${KERNEL_NAME}
post_upgrade() {
  pacman -Q grub &>/dev/null
  pacman -Q grub2 &>/dev/null
  pacman -Q lilo &>/dev/null
  # reminder notices
  if [ $haslilo -eq 0 ]; then
    echo ">>>"
    if [ $hasgrub -eq 0 -o $hasgrub2 -eq 0 ]; then
      echo ">>> If you use the LILO bootloader, you should run 'lilo' before rebooting."
      echo ">>> You appear to be using the LILO bootloader. You should run"
      echo ">>> 'lilo' before rebooting."
    echo ">>>"
  if grep "^[^#]*/boot" /etc/fstab 2>&1 >/dev/null; then
    if ! grep "/boot" /etc/mtab 2>&1 >/dev/null; then
      echo "WARNING: /boot appears to be a seperate partition but is not mounted"
      echo "        This is most likely not what you want.  Please mount your /boot"
      echo "        partition and reinstall the kernel unless you are sure this is OK"
  echo ">>> If you use LVM2, Encrypted root or software RAID,"
  echo ">>> Ensure you enable support in /etc/mkinitcpio.conf ."
  echo ">>> More information about mkinitcpio setup can be found here:"
  echo ">>> http://wiki.archlinux.org/index.php/Mkinitcpio"
  echo ""
  echo ">>> Generating initial ramdisk, using mkinitcpio.  Please wait..."
  /sbin/mkinitcpio -p kernel26${KERNEL_NAME}
post_remove() {
  rm -f /boot/kernel26${KERNEL_NAME}.img
  rm -f /boot/kernel26${KERNEL_NAME}-fallback.img
{{Tip|If your config doesn't use a boot image, the only thing this script needs to do is run <code>depmod $KERNELNAME</code>.}}
=== 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.
=== Problems ===
===== 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 <code>LOCALVERSION</code>.
=== Using the nVIDIA video driver with your custom kernel ===
To use the nvidia driver with your new custom kernel, see: [[NVIDIA#Alternate_install:_custom_kernel|How to install NVIDIA driver with custom kernel]]
Original article written by ''DibbleTheWrecker''. Updated by ''Falconindy''.

Revision as of 01:06, 31 August 2010