Difference between revisions of "Kernel-packaging"

From SlackWiki
Jump to navigation Jump to search
 
(16 intermediate revisions by 2 users not shown)
Line 5: Line 5:
For info on compiling please look at these pages:
For info on compiling please look at these pages:


[http://slackwiki.org/Kernel_Compilation Kernel_Compilation]
[http://slackwiki.com/Kernel_Compilation Kernel_Compilation]


[http://slackwiki.org/Kernel26Compilation Kernel26Compilation]
[http://slackwiki.com/Kernel26Compilation Kernel26Compilation]


[http://slackwiki.org/Kernel_Checklist Kernel_Checklist]
[http://slackwiki.com/Kernel_Checklist Kernel_Checklist]


*Note2: I will be assuming x86 here, but if anyone wants to contribute some notes on x86_64 until I can get a machine setup, please do.


== Kernel Output Target Option ==
== Kernel Output Target Option ==
Line 38: Line 37:
Ok let's use '''/tmp/kernel-package''' for our package directory. Also let's assume a '''2.6.29.6''' kernel with '''jabberwok''' as local name. A little bash will copy our modules to it:
Ok let's use '''/tmp/kernel-package''' for our package directory. Also let's assume a '''2.6.29.6''' kernel with '''jabberwok''' as local name. A little bash will copy our modules to it:
    
    
   for i in $(cat modules.order | sed "s#^kernel/##")
   for i in $(sed "s#^kernel/##" modules.order)
   do
   do
     mkdir -p /tmp/kernel-package/lib/modules/2.6.29.6-jabberwok/$(dirname $i)
     mkdir -p /tmp/kernel-package/lib/modules/2.6.29.6-jabberwok/$(dirname $i)
Line 53: Line 52:
And then the doinst.sh and slack-desc.
And then the doinst.sh and slack-desc.


   doinst.sh:
   mkdir /tmp/kernel-package/install
 
 
doinst.sh:
 
   ## Taken from stock modules package
   ## Taken from stock modules package
   if [ -x sbin/depmod ]; then
   if [ -x sbin/depmod ]; then
Line 71: Line 72:


   cd /tmp/kernel-package
   cd /tmp/kernel-package
   /sbin/makepkg -l y -c n /tmp/kernel-jabberwok-2.6.29.6_tag-i686-1.txz
   /sbin/makepkg -l y -c n /tmp/kernel-jabberwok-2.6.29.6-i686-1_tag.txz


Change '_tag' to your usual moniker. Hopefully we now have a package in /tmp. Copy it to a temporary directory somewhere, '''explodepkg''' it and check the contents. We don't want to install something with messed up paths etc. If all is well we can installpkg it.
Change '_tag' to your usual moniker. Hopefully we now have a package in /tmp. Copy it to a temporary directory somewhere, '''explodepkg''' it and check the contents. We don't want to install something with messed up paths etc. If all is well we can installpkg it.
Line 81: Line 82:
Of course this would be easier to control with a script rather than typing in these commands manually and trying not to make typos. Here is the script that I've been using (run make menuconfig first):
Of course this would be easier to control with a script rather than typing in these commands manually and trying not to make typos. Here is the script that I've been using (run make menuconfig first):


  #!/bin/sh
    #!/bin/sh
  # Slackware build script for kernel and modules
    # Slackware build script for kernel and modules
  #
    #
  # Copyright 2009  David Woodfall <dave@dawoodfall.net>
    # Copyright 2009-2010 David Woodfall <dave@dawoodfall.net>
  # All rights reserved.
    # All rights reserved.
  #
    #
  # Redistribution and use of this script, with or without modification, is
    # Redistribution and use of this script, with or without modification, is
  # permitted provided that the following conditions are met:
    # permitted provided that the following conditions are met:
  #
    #
  # 1. Redistributions of this script must retain the above copyright
    # 1. Redistributions of this script must retain the above copyright
  #    notice, this list of conditions and the following disclaimer.
    #    notice, this list of conditions and the following disclaimer.
  #
    #
  # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
    # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED
  # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
    # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
    # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  #  
    #  
  # Notes:
    # Notes:  
  # You should have a /usr/src/linux-$VERSION-$LOCALNAME of source or you will  
    # You should have a /usr/src/linux-$VERSION-$LOCALNAME of source or you will  
  # have problems.
    # have problems.
  # Do not omit setting localname in .config.
    # Do not omit setting localname in .config.
 
   
  source .config
   
  LOCALNAME=${LOCALNAME:-${CONFIG_LOCALVERSION/-/}}
    source ./.config
  KARCH=${ARCH:-i486}
    LOCALNAME=${LOCALNAME:-${CONFIG_LOCALVERSION/-/}}
  ARCH=x86
    if [ -z "$ARCH" ]; then
  MODULELIST=modules.order
      case "$( uname -m )" in
  PRGNAM=kernel
        i?86) ARCH=i486 ;;                     
  VERSION=${VERSION:-2.6.29.6}
        arm*) ARCH=arm ;;                     
  BUILD=${BUILD:-1}
          *) ARCH=$( uname -m ) ;;
  TAG=${TAG:-_daw}
      esac
  OUTPUT=${TMP:-/tmp}
    fi
  PKG=$OUTPUT/$PRGNAM-$LOCALNAME-$VERSION
    KARCH=$ARCH
  MODDIR=$PKG/lib/modules/$VERSION-$LOCALNAME
    ARCH=x86
 
    MODULELIST=modules.order
  set -e
    PRGNAM=kernel
    VERSION=${VERSION:-2.6.29.6}
  rm -rf $PKG  
    BUILD=${BUILD:-1}
 
    TAG=${TAG:-_daw}
  make
    OUTPUT=${TMP:-/tmp}
 
    PKG=$OUTPUT/$PRGNAM-$LOCALNAME-$VERSION
  for i in $(cat $MODULELIST | sed "s#^kernel/##")
    MODDIR=$PKG/lib/modules/$VERSION-$LOCALNAME
  do
   
      mkdir -p $MODDDIR/$(dirname $i)
    set -e
      install -m 644 -v $i $MODDDIR/$(dirname $i)
   
  done
    rm -rf $PKG  
 
   
  mkdir -p $PKG/boot
    make
  cp arch/x86/boot/bzImage $PKG/boot/vmlinuz-$VERSION-$LOCALNAME
   
  cp System.map $PKG/boot/System.map-$VERSION-$LOCALNAME
    for i in $(sed "s#^kernel/##" $MODULELIST)
  cp .config $PKG/boot/config-$VERSION-$LOCALNAME
    do
 
        mkdir -p $MODDIR/$(dirname $i)
  mkdir $PKG/install
        install -m 644 -v $i $MODDIR/$(dirname $i)
 
        let nummods=$nummods+1
  cat << EOF > $PKG/install/doinst.sh
    done
  ## Taken from stock modules package
   
  if [ -x sbin/depmod ]; then
    mkdir -p $PKG/install
  chroot . /sbin/depmod -a $VERSION-$LOCALNAME > /dev/null 2> /dev/null
   
  fi
    cat << EOF > $PKG/install/doinst.sh
 
    ## Taken from stock modules package
  cat << EOF > $PKG/install/slack-desc
    if [ -x sbin/depmod ]; then
  # HOW TO EDIT THIS FILE:
    chroot . /sbin/depmod -a $VERSION-$LOCALNAME > /dev/null 2> /dev/null
  # The "handy ruler" below makes it easier to edit a package description.  Line
    fi
  # up the first '|' above the ':' following the base package name, and the '|'
   
  # on the right side marks the last column you can put a character in.  You must
    ( cd lib/modules/$VERSION-$LOCALNAME ; rm -rf build )
  # make exactly 11 lines for the formatting to be correct.  It's also
    ( cd lib/modules/$VERSION-$LOCALNAME ; ln -sf /usr/src/linux-$VERSION-$LOCALNAME build )
  # customary to leave one space after the ':'.
    ( cd lib/modules/$VERSION-$LOCALNAME ; rm -rf source )
    ( cd lib/modules/$VERSION-$LOCALNAME ; ln -sf /usr/src/linux-$VERSION-$LOCALNAME source )
  $PRGNAM-$LOCALNAME|-----handy-ruler------------------------------------------------------|
    EOF
  $PRGNAM-$LOCALNAME: kernel and modules 2.6.29.6-jabberwok
   
  $PRGNAM-$LOCALNAME:
    cat << EOF > $PKG/install/slack-desc
  $PRGNAM-$LOCALNAME: Jabberwokky type kernel!
    # HOW TO EDIT THIS FILE:
  $PRGNAM-$LOCALNAME:
    # The "handy ruler" below makes it easier to edit a package description.  Line
  $PRGNAM-$LOCALNAME:
    # up the first '|' above the ':' following the base package name, and the '|'
  $PRGNAM-$LOCALNAME:
    # on the right side marks the last column you can put a character in.  You must
  $PRGNAM-$LOCALNAME:
    # make exactly 11 lines for the formatting to be correct.  It's also
  $PRGNAM-$LOCALNAME:
    # customary to leave one space after the ':'.
  $PRGNAM-$LOCALNAME:
   
  $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME|-----handy-ruler------------------------------------------------------|
  $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME: kernel and modules for $LOCALNAME-$VERSION
  EOF
    $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME: Jabberwokky type kernel!
  cd $PKG
    $PRGNAM-$LOCALNAME:
  /sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$LOCALNAME-$VERSION$TAG-$KARCH-$BUILD.${PKGTYPE:-tgz}
    $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME:
    $PRGNAM-$LOCALNAME:
    EOF
   
    mkdir -p $PKG/boot
   
    cp arch/x86/boot/bzImage $PKG/boot/vmlinuz-$VERSION-$LOCALNAME
    cp System.map $PKG/boot/System.map-$VERSION-$LOCALNAME
    cp .config $PKG/boot/config-$VERSION-$LOCALNAME
   
    ksize=$(ls -l arch/x86/boot/bzImage | awk '{print $5}')
   
    cd $PKG
   
    PACKAGE=$OUTPUT/$PRGNAM-$LOCALNAME-$VERSION-$KARCH-$BUILD-$TAG.${PKGTYPE:-tgz}
   
    /sbin/makepkg -l y -c n $PACKAGE
   
    echo -ne '\e[01;34m'
    printf "$nummods Modules Built\n"
    printf "Kernel Size: $ksize\n"
    printf "Package Size: $(ls -l $PACKAGE | awk '{print $5}')\n\n"
    echo -ne '\e[m\017'


And here's a downloadable version: http://www.dawoodfall.net/slackbuilds/13.0/kernel/kernel-jabberwok.SlackBuild
Downloadable version: http://www.dawoodfall.net/slackbuilds/noversion/kernel/


= Conclusion =
= Conclusion =


The aim for doing this was to be able to build a kernel for my old T42 on my desktop box using the T42's .config. It could be possible to split up kernel and modules into separate packages but I'll let you figure out the details. Note that this does not include the firmware so you should keep the relevant kernel-firmware package installed.
The aim for doing this was to be able to build a kernel for my old T42 on my desktop box using the T42's .config. It could be possible to split up kernel and modules into separate packages but I'll let you figure out the details.


At the end of the day, this helped me to compile a kernel without my laptop getting even warm, which was the point of the project.
At the end of the day, this helped me to compile a kernel without my laptop getting even warm, which was the point of the project.


--[[User:Dive|Dive]] 04:31, 11 March 2010 (UTC)
--[[User:Dive|Dive]] 04:31, 11 March 2010 (UTC)

Latest revision as of 12:15, 9 December 2011

Creating a Custom Package of Kernel and Modules

  • Note: This tutorial assumes that you know how to compile a kernel already. It only looks at a way of creating a package and doesn't aim to show kernel config options.

For info on compiling please look at these pages:

Kernel_Compilation

Kernel26Compilation

Kernel_Checklist


Kernel Output Target Option

The usual way to make any sort of package is via the $DESTDIR variable. The kernel doesn't use this however, but it does have an O switch which does almost the same thing, although the output might not be exactly what you expect. I will not be using that option here, but see the discussion page about that.

Building

Copy your .config into the source directory and do

  make menuconfig

(or whichever method you prefer.)

You may need to do 'make mrproper' first, and perhaps 'make oldconfig'.

  make
  • Note: Do not use 'make install' or 'make modules_install', even with O switch, as this *will* install to /boot and /lib/modules.

At this point everything we need is in the source directory. The file modules.order lists the modules to be installed and that we can use to help us make a package.

Installing Modules and Kernel to our Package Directory

Ok let's use /tmp/kernel-package for our package directory. Also let's assume a 2.6.29.6 kernel with jabberwok as local name. A little bash will copy our modules to it:

  for i in $(sed "s#^kernel/##" modules.order)
  do
    mkdir -p /tmp/kernel-package/lib/modules/2.6.29.6-jabberwok/$(dirname $i)
    install -m 644 -v $i /tmp/kernel-package/lib/modules/2.6.29.6-jabberwok/$(dirname $i)
  done

Now we need the kernel and associated files.

  mkdir /tmp/kernel-package/boot
  cp arch/x86/boot/bzImage /tmp/kernel-package/boot/vmlinuz-2.6.29.6-jabberwok
  cp System.map /tmp/kernel-package/boot/System.map-2.6.29.6-jabberwok
  cp .config /tmp/kernel-package/boot/config-2.6.29.6-jabberwok

And then the doinst.sh and slack-desc.

  mkdir /tmp/kernel-package/install

doinst.sh:

  ## Taken from stock modules package
  if [ -x sbin/depmod ]; then
  chroot . /sbin/depmod -a 2.6.29.6-jabberwok > /dev/null 2> /dev/null
  fi
  
  ( cd lib/modules/2.6.29.6-jabberwok ; rm -rf build )
  ( cd lib/modules/2.6.29.6-jabberwok ; ln -sf /usr/src/linux-2.6.29.6-jabberwok build )
  ( cd lib/modules/2.6.29.6-jabberwok ; rm -rf source )
  ( cd lib/modules/2.6.29.6-jabberwok ; ln -sf /usr/src/linux-2.6.29.6-jabberwok source )


I'll leave you to figure out the slack-desc. It should be copied into the install/ directory and appname ought to be (going by this example) kernel-jabberwok.

Making the Package

  cd /tmp/kernel-package
  /sbin/makepkg -l y -c n /tmp/kernel-jabberwok-2.6.29.6-i686-1_tag.txz

Change '_tag' to your usual moniker. Hopefully we now have a package in /tmp. Copy it to a temporary directory somewhere, explodepkg it and check the contents. We don't want to install something with messed up paths etc. If all is well we can installpkg it.

As usual, edit your /etc/lilo.conf and add an option for the new kernel, keeping the old kernel entry in place for safety, then run lilo.

A Little Automation

Of course this would be easier to control with a script rather than typing in these commands manually and trying not to make typos. Here is the script that I've been using (run make menuconfig first):

   #!/bin/sh
   # Slackware build script for kernel and modules
   #
   # Copyright 2009-2010  David Woodfall <dave@dawoodfall.net>
   # All rights reserved.
   #
   # Redistribution and use of this script, with or without modification, is
   # permitted provided that the following conditions are met:
   #
   # 1. Redistributions of this script must retain the above copyright
   #    notice, this list of conditions and the following disclaimer.
   #
   # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AS IS AND ANY EXPRESS OR IMPLIED
   # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
   # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
   # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   # 
   # Notes: 
   # You should have a /usr/src/linux-$VERSION-$LOCALNAME of source or you will 
   # have problems.
   # Do not omit setting localname in .config.
   
   
   source ./.config
   LOCALNAME=${LOCALNAME:-${CONFIG_LOCALVERSION/-/}}
   if [ -z "$ARCH" ]; then
     case "$( uname -m )" in
       i?86) ARCH=i486 ;;                      
       arm*) ARCH=arm ;;                       
          *) ARCH=$( uname -m ) ;;
     esac
   fi
   KARCH=$ARCH
   ARCH=x86
   MODULELIST=modules.order
   PRGNAM=kernel
   VERSION=${VERSION:-2.6.29.6}
   BUILD=${BUILD:-1}
   TAG=${TAG:-_daw}
   OUTPUT=${TMP:-/tmp}
   PKG=$OUTPUT/$PRGNAM-$LOCALNAME-$VERSION
   MODDIR=$PKG/lib/modules/$VERSION-$LOCALNAME
   
   set -e
   
   rm -rf $PKG 
   
   make
   
   for i in $(sed "s#^kernel/##" $MODULELIST)
   do
       mkdir -p $MODDIR/$(dirname $i)
       install -m 644 -v $i $MODDIR/$(dirname $i)
       let nummods=$nummods+1
   done
   
   mkdir -p $PKG/install
   
   cat << EOF > $PKG/install/doinst.sh
   ## Taken from stock modules package
   if [ -x sbin/depmod ]; then
   chroot . /sbin/depmod -a $VERSION-$LOCALNAME > /dev/null 2> /dev/null
   fi
   
   ( cd lib/modules/$VERSION-$LOCALNAME ; rm -rf build )
   ( cd lib/modules/$VERSION-$LOCALNAME ; ln -sf /usr/src/linux-$VERSION-$LOCALNAME build )
   ( cd lib/modules/$VERSION-$LOCALNAME ; rm -rf source )
   ( cd lib/modules/$VERSION-$LOCALNAME ; ln -sf /usr/src/linux-$VERSION-$LOCALNAME source )
   EOF
   
   cat << EOF > $PKG/install/slack-desc
   # HOW TO EDIT THIS FILE:
   # The "handy ruler" below makes it easier to edit a package description.  Line
   # up the first '|' above the ':' following the base package name, and the '|'
   # on the right side marks the last column you can put a character in.  You must
   # make exactly 11 lines for the formatting to be correct.  It's also
   # customary to leave one space after the ':'.
   
   $PRGNAM-$LOCALNAME|-----handy-ruler------------------------------------------------------|
   $PRGNAM-$LOCALNAME: kernel and modules for $LOCALNAME-$VERSION
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME: Jabberwokky type kernel!
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME:
   $PRGNAM-$LOCALNAME:
   EOF
   
   mkdir -p $PKG/boot
   
   cp arch/x86/boot/bzImage $PKG/boot/vmlinuz-$VERSION-$LOCALNAME
   cp System.map $PKG/boot/System.map-$VERSION-$LOCALNAME
   cp .config $PKG/boot/config-$VERSION-$LOCALNAME
   
   ksize=$(ls -l arch/x86/boot/bzImage | awk '{print $5}')
   
   cd $PKG
   
   PACKAGE=$OUTPUT/$PRGNAM-$LOCALNAME-$VERSION-$KARCH-$BUILD-$TAG.${PKGTYPE:-tgz}
   
   /sbin/makepkg -l y -c n $PACKAGE
   
   echo -ne '\e[01;34m'
   printf "$nummods Modules Built\n"
   printf "Kernel Size: $ksize\n"
   printf "Package Size: $(ls -l $PACKAGE | awk '{print $5}')\n\n"
   echo -ne '\e[m\017'

Downloadable version: http://www.dawoodfall.net/slackbuilds/noversion/kernel/

Conclusion

The aim for doing this was to be able to build a kernel for my old T42 on my desktop box using the T42's .config. It could be possible to split up kernel and modules into separate packages but I'll let you figure out the details.

At the end of the day, this helped me to compile a kernel without my laptop getting even warm, which was the point of the project.

--Dive 04:31, 11 March 2010 (UTC)