You are not logged in.

#1 2005-04-12 06:48:18

digi691
Member
Registered: 2004-10-12
Posts: 21

PKGBUILD first time for kernel (or building a custom kernel)

I am building my first PKGBUILD for updating a kernel and i have to say it is a lot more intense then a regular old PKGBUILD!  :?  So far i been following the WiKi for kernels 2.6.9 and later.  So far i created a directory /var/abs/local/kernel-custom/.  In this directory I downloaded the 2.11.7 kernel copied the PKGBUILD, kernel26-install, and config from /var/abs/kernels/kernel26/.  I than ran the md5sums and put that in my PKGBUILD just as the "how to" put it.  I just wanted to post my PKGBUILD to make sure it looked right or if i am missing anything.  The whole reason i started this project is so I can get support for my ati card and get the module fglrx for my ati radeon.  The only thing i changed is what the How to for the radeon in the forums showed to change or have which it seems like it already has everything but i removed the stuff that it did not have checked because i thought it might conflict with it.  I am really unsure what to remove from the config and it makes me nervous cause i have already had a broken system once from trying to configure it for my system and doing a PKGBUILD earlier this week  sad  So I will post my PKGBUILD.....If anyone could point me in the right direction or a good how to configure my system for the configure file that would be great.  I know my hardware pretty good but i always seem to mess it up and get a broken system.  anyway here is my PKGBUILD:

# Contributor: dibblethewrecker <dibblethewrecker@jiwe.org>
pkgname=kernel26
pkgver=2.6.11.7
pkgrel=1
pkgdesc="The Linux Kernel 2.6.11.7 and modules (IDE support), built with 
... patchset"
url="http://www.kernel.org"
depends=('module-init-tools')
install=kernel26.install

##### if you are using a single patch from a patchset you can add the name, without it's extention, below
patch=
##### add the names of any patches to this section, ensure you have the correct extentions!
source=(ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-$pkgver.tar.bz2 )
md5sums=('04f5efb260ff6fb4eaa221fb5b880d8e')
# Function to grab var from src
getvar() {
  old=$(cat Makefile | grep "^$1")
  echo $(echo ${old/"$1 ="/} | sed -e "s/[ ]*(.*)[ ]*/1/g")
  return 0
}

build() {
  cd $startdir/src/linux-$pkgver

  ##### Apply any patches here, if you set the patch variable above uncommment the following line
  #patch -Np1 -i ../$patch || return 1

  ##### Uncomment for 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

  ##### Load config - uncomment your prefered config method - remember to set LOCALVERSION if desired
  #yes "" | make config
  #make oldconfig || return 1
  #make menuconfig
  make xconfig
  #make gconfig

  ##### NO USER CHANGES BELOW HERE #####

  # save the current pkgname
  old_pkgname=$pkgname

  # set pkgname for build purposes - DO NOT alter!
  pkgname=kernel26

  # save the updated config to build with today's date
  cp ./.config $startdir/config-$(date +%b%d-%Hh)

  # get EXTRAVERSION from Makefile to create unique /lib/modules/ subdirectories
  _kernextra=$(getvar "EXTRAVERSION")

  # Read the full kernel version info to use in pathnames and pkgname
  . ./.config

  # Kernel custom - to create a unique pkgname (see below)
  _kerncust="${_kernextra}${CONFIG_LOCALVERSION}"
  # Kernel release - will be the same as Makefile
  _kernrel="${pkgver}${_kerncust}"
  # Get the pkgver suffix for unique pkgname and /boot file suffices
  _pkgversuf="`echo $pkgver | sed "s|2.6.||g"`"
  # Set /boot file suffices from kernel release and pkgver suffix
  _kernboot="${_pkgversuf}${_kerncust}"

  # Set a new pkgname from  kernel release and pkgver suffix
  pkgname="${pkgname}${_pkgversuf}${_kerncust}"

  # build!
  make clean bzImage modules || return 1
  mkdir -p $startdir/pkg/{lib/modules,boot}
  make INSTALL_MOD_PATH=$startdir/pkg modules_install || return 1
  cp System.map $startdir/pkg/boot/System.map26${_kernboot}
  cp arch/i386/boot/bzImage $startdir/pkg/boot/vmlinuz26${_kernboot}
  install -D -m644 Makefile 
    $startdir/pkg/usr/src/linux-${_kernrel}/Makefile
  install -D -m644 .config 
    $startdir/pkg/usr/src/linux-${_kernrel}/.config
  install -D -m644 .config $startdir/pkg/boot/kconfig26${_kernboot}
  mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/include
  mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/arch/i386/kernel
  for i in acpi asm-generic asm-i386 config linux math-emu net pcmcia scsi video; do
    cp -a include/$i $startdir/pkg/usr/src/linux-${_kernrel}/include/
  done
  # copy files necessary for later builds, like nvidia and vmware
  cp -a scripts $startdir/pkg/usr/src/linux-${_kernrel}
  mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/.tmp_versions
  cp arch/i386/Makefile $startdir/pkg/usr/src/linux-${_kernrel}/arch/i386/
  cp arch/i386/kernel/asm-offsets.s 
    $startdir/pkg/usr/src/linux-${_kernrel}/arch/i386/kernel/
  # copy in Kconfig files
  for i in `find . -name "Kconfig*"`; do
    mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/`echo $i | sed 's|/Kconfig.*||'`
    cp $i $startdir/pkg/usr/src/linux-${_kernrel}/$i
  done
  cd $startdir/pkg/usr/src/linux-${_kernrel}/include && ln -s asm-i386 asm
  chown -R root.root $startdir/pkg/usr/src/linux-${_kernrel}
  cd $startdir/pkg/lib/modules/${_kernrel} && 
    (rm -f source build; ln -sf /usr/src/linux-${_kernrel} build)

  # Correct the pkgname in our PKGBUILD - this allows correct gensync operation
  # NOTE: pkgname variable must be declared with first 10 lines of PKGBUILD!
  cd $startdir
  sed -i "1,11 s|pkgname=$old_pkgname|pkgname=$pkgname|" ./PKGBUILD
}

Offline

#2 2005-04-12 09:00:29

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: PKGBUILD first time for kernel (or building a custom kernel)

I dunno the ATI stuff, but I guess it's a matter of applying some minor patch or just changing some kernel options. In that case, I suggest you to use genuine kernel26 PKGBUILD (/var/abs/kernel/kernel26), not dibble's one. If you want to apply some patch, just add relevant line in the beginning of build(), next to other patches. If you want to change kernel options, go to line 39 of genuine kernel26 PKGBUILD, change 'make config' to 'make menuconfig' and set proper options when the ncurses based menu appears - config shall be based on the one of stock Arch kernel, so you shouldn't run into any problems.

Yhm, I guess this post is clear enough for you to understand :-)

-edit-
Of course change the $pkgver from 2.6.11.3 to 2.6.11.7, if you want the newest stuff :-)

Offline

#3 2005-04-12 09:09:47

big_gie
Member
Registered: 2005-01-19
Posts: 637

Re: PKGBUILD first time for kernel (or building a custom kernel)

hey digi691,

You seem to be using the PKGBUILD from dibblethewrecker. It was first created to apply a patch to the kernel sources. If you only want to recompile it without patching it, you don't need this.

You could just compile the sources manually, witch is quite simple, or use a PKGBUILD.

I took dibblethewrecker's PKGBUILD some time ago to adapt it to my needs. I think my version is more simple then his. Here's what you'll need:

1) Create a directory where you will build things. It can be anything. I'm using ~/Arch/PKGBUILDs/kernel/2.6.11.7 but you can use what you want. I'll call this directory $startdir

2) As the wiki says, put those files in the $startdir directory, the one you just created:
-Your "config" file. If you don't have one yet, copy it from /usr/src/linux/.config (/usr/src/linux should be a symbolic link to your kernel sources, mine points to /usr/src/linux-2.6.11.7-vanilla-c2/ You could also execute the "cp" command like this: cp /usr/src/linux-`uname -r`/.config /path/to/your/$startdir)
-kernel26.install It can be found in /var/abs/kernels/kernel26/
-logo_linux_clut224.ppm It can be found in /var/abs/kernels/kernel26/ too.
-the kernel sources package

3) Save the PKGBUILD I'm posting and edit the lines you want. I suggest you look at those lines:
-line 7: _kername=vanilla
Name the kernel. Give it a name you want. I'm using kernel.org's vanilla kernel so hence the name.
-line 8: pkgver=2.6.11.7
Put the kernel version you will use.
-line 29: configmethod="gconfig"
Put the config method you preffer. It is acutally set to gconfig witch is a graphical tool, easy to use.
-line 38 -> 40:
boot_kernel="kernel-"
boot_systemmap="System.map-"
boot_config="config-"
Those 3 lines are the "model" on the 3 files that will be copied to /boot. The kernel is often (or maybe always...) called "vmlinuz" but I prefer "kernel-<information" so there can be multiple kernels in the /boot.
-line 43: source="..."
If you don't want to use kernel.org kernels, change the source where to download it.

4) One you adapted it to your need, check the md5 and save them:
makepkg -g >> PKGBUILD

5) Run makepkg to build:
makepkg

6) Install it (as root) :
pacman -A kernel...


With my PKGBUILD, you will have:
-A package named with the kernel version. That way you could install multiple kernels on your machine. This is usefull if you want to test new kernel, new config, etc.
Package will have this syntax:
kernel<kernel version without dots>-<kernel name>-c<compilation number>-<kernel version for pacman>.pkg.tar.gz
Example:
File: kernel26117-vanilla-c2-2.6.11.7-1.pkg.tar.gz
Name of the package: kernel26117-vanilla-c2
This will be the name the package will be refered by pacman. For example, unistalling it like this : pacman -R kernel26117-vanilla-c2
Compilation numer: 2
If you want to have multiple kernels with different .config files (for example, if you want to test if an option is better in "module" instead of builtin), you can change this number. The first time you compile the kernel, it is 1, then if you need to change an option and recompile, you can still keep the old kernel.
Kernel version for pacman: 2.6.11.7-1
This is the version of the package. It will be the same as the kernel version, plus the "-1" at the end (the "1" if the package release).

Thats it...:)

If you have any questions, don't hesitate!

Good luck

PKGBUILD:

# $Id: PKGBUILD,v 1.36 2004/12/07 08:59:32 judd Exp $
# Maintainer: big_gie <coagulateur@gmail.com>
# Date : 28-03-2005
# Please note that I don't use the "EXTRAVERSION" variable...
# kernel26115-vanilla-c1
pkgname=kernel26
_kername=vanilla
pkgver=2.6.11.7
pkgrel=1
compilation_number=2
pkgdesc="The Linux Kernel v$pkgver ($_kername) and modules (IDE support)"
url="http://www.kernel.org"
depends=('module-init-tools')
install=kernel26.install

# Patch Section
#
#patchname=swsusp2
#patchfile=software-suspend-2.1.8-for-2.6.11
#patchextension=.tar.bz2
#patchurl="http://www.suspend2.net/downloads/all/$patchfile$patchextension"
#patchcommand="$startdir/src/$patchfile/apply $startdir/src/$patchfile/"

# Prefered config method
#
#configmethod="oldconfig || return 1"
#configmethod="menuconfig"
#configmethod="xconfig"
configmethod="gconfig"

# Make clean or not?
#
#makeclean="clean"
makeclean=""

# kernel, System.map and config name for /boot/
#
boot_kernel="kernel-"
boot_systemmap="System.map-"
boot_config="config-"


source=(config $patchurl ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-$pkgver.tar.bz2 logo_linux_clut224.ppm)


# Function to grab var from src
getvar() {
  old=$(cat Makefile | grep "^$1")
  echo $(echo ${old/"$1 ="/} | sed -e "s/[ ]*(.*)[ ]*/1/g")
  return 0
}

build() {

  cd $startdir/src/linux-$pkgver

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

  # Apply any patches
  $patchcommand

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

  # NO USER CHANGES BELOW HERE

  # save the current pkgname
  old_pkgname=$pkgname
 
  # set pkgname for build purposes - DO NOT alter!
  pkgname=kernel26

  # save the updated config to build with today's date
  cp ./.config $startdir/config-$(date +%b%d-%Hh)

  # get EXTRAVERSION from Makefile to create unique /lib/modules/ subdirectories
#  _kernextra=$(getvar "EXTRAVERSION")
  if [ "$patchname" == "" ]; then
    _kernextra=-${_kername}${_kernextra}
  else
    _kernextra=-${_kername}-${patchname}${_kernextra}
  fi

  # Read the full kernel version info to use in pathnames and pkgname
  . ./.config

  # Kernel custom - to create a unique pkgname (see below)
  _kerncust="${_kernextra}-c${compilation_number}"
  # Kernel release - will be the same as Makefile
  _kernrel="${pkgver}${_kerncust}"
  # Get the pkgver suffix for unique pkgname and /boot file suffices
  _pkgversuf="`echo $pkgver | sed "s|2.6.||g" | sed "s|.||g"`"
 
  # Set /boot file suffices from kernel release and pkgver suffix
  _kernboot="${_pkgversuf}${_kerncust}"

  # Set a new pkgname from  kernel release and pkgver suffix
  pkgname="${pkgname}${_pkgversuf}${_kerncust}"


  # set LOCAVERSION in $startdir/src config
  sed -i "s|LOCALVERSION=.*|LOCALVERSION="$_kerncust"|g" $startdir/src/config
  cp $startdir/src/config $startdir/src/linux-$pkgver/.config

  # Config using the prefered method
  make $configmethod



  #
  # build!
  #

  make $makeclean bzImage modules || return 1

  mkdir -p $startdir/pkg/{lib/modules,boot}
  make INSTALL_MOD_PATH=$startdir/pkg modules_install || return 1
  cp System.map $startdir/pkg/boot/${boot_systemmap}${_kernrel}
  cp arch/i386/boot/bzImage $startdir/pkg/boot/${boot_kernel}${_kernrel}
  install -D -m644 Makefile 
    $startdir/pkg/usr/src/linux-${_kernrel}/Makefile
  install -D -m644 .config 
    $startdir/pkg/usr/src/linux-${_kernrel}/.config
  install -D -m644 .config $startdir/pkg/boot/${boot_config}${_kernrel}
  mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/include
  mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/arch/i386/kernel
  for i in acpi asm-generic asm-i386 config linux math-emu net pcmcia scsi video; do
    cp -a include/$i $startdir/pkg/usr/src/linux-${_kernrel}/include/
  done
 # copy files necessary for later builds, like nvidia and vmware
  cp -a scripts $startdir/pkg/usr/src/linux-${_kernrel}
  mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/.tmp_versions
  cp arch/i386/Makefile $startdir/pkg/usr/src/linux-${_kernrel}/arch/i386/
  cp arch/i386/kernel/asm-offsets.s 
    $startdir/pkg/usr/src/linux-${_kernrel}/arch/i386/kernel/
  # copy in Kconfig files
  for i in `find . -name "Kconfig*"`; do
    mkdir -p $startdir/pkg/usr/src/linux-${_kernrel}/`echo $i | sed 's|/Kconfig.*||'`
    cp $i $startdir/pkg/usr/src/linux-${_kernrel}/$i
  done
  cd $startdir/pkg/usr/src/linux-${_kernrel}/include && ln -s asm-i386 asm
  chown -R root.root $startdir/pkg/usr/src/linux-${_kernrel}

  cd $startdir/pkg/lib/modules
  #mv $pkgver-c$compilation_number ${_kernrel}
  cd ${_kernrel}
  rm -f source build
  ln -sf /usr/src/linux-${_kernrel} build
  ln -sf /usr/src/linux-${_kernrel} source

  # Correct the pkgname in our PKGBUILD - this allows correct gensync operation
  # NOTE: pkgname variable must be declared with first 10 lines of PKGBUILD!
  cd $startdir
  sed -i "1,11 s|pkgname=$old_pkgname|pkgname=$pkgname|" ./PKGBUILD
}

Offline

#4 2005-04-12 11:07:47

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,436
Website

Re: PKGBUILD first time for kernel (or building a custom kernel)

It was first created to apply a patch to the kernel sources

big_gie, that's not true. it was created to make use of EXTRAVERSION and LOCALVERSION in custom naming schemes.  the patch support is minimal (two lines).

Wiki page wrote:

This howto has been updated to try and provide a definitive PKGBUILD for the creation of simple custom kernels and for the major patchesets.  This document incorporates a special PKGBUILD that allows you to maintain multiple kernels, especially patchset versions, under pacman version control.  This PKGBUILD features specific emphasis on using patches but is just as useful for any custom kernel build - especially if you use the LOCALVERSION to localise - simply setting LOCALVERSION to -custom at the config stage will suffice!

It is "especially patchset versions" because patchsets use EXTRAVERSION which can bugger up all your naming schemes - as big_gie found out, not because it features the $patch variable - i just threw that in for lazy people using major patchsets!

I think my version is more simple then his

i think yours is very over-complicated and makes counter-intuitive pkgnames + i think the complexity is demonstrated by the number of custom variables you can set - mine simply uses one - the patch - IF YOU USE ONE!

I would appreciate it if you would not mis-represent all my hard work to simplify the process of building a kernel with a custom name, while at the same time advocating your own totally custom approach, which, as anyone can see, is not the easiest way to do it all!  Especially as it just a rehash of my PKGBUILD!

the nerve of some people!

based on this I am going to re-write parts of the wiki to better explain the philsophy and, most importantly, the logic!

Offline

#5 2005-04-12 16:58:22

digi691
Member
Registered: 2004-10-12
Posts: 21

Re: PKGBUILD first time for kernel (or building a custom kernel)

Sorry for the problem this has caused....  But to help you with the wiki and being new at the whole kernel PKGBUILD thing i can tell you what things i had a hard time understanding.  A couple of things i really don't understand is the logo thing and the config patch.  What does it actually do?  I really don't understand the whole concept of patching using ABS or even just patching the kernel the old fashioned way.  Like I said in the post earlier i know exactly what my hardware is but i take out stuff and it seems to break other things or i just get crazy errors.  The real problem i have using the stock config with the current kernel is that it takes forever to compile because of all the modules.  This machine is only a P-3 933 Mhz.  If you could take a look at my modified PKGBUILD dibble and point me in the right direction that would be great.  I would hate to be doing something wrong in the begining and doing a compile that is just going to be bunk anyways.  Thanks for the posts guys....I appreciate it

Offline

#6 2005-04-13 04:21:05

digi691
Member
Registered: 2004-10-12
Posts: 21

Re: PKGBUILD first time for kernel (or building a custom kernel)

Well i was able to compile a succesful Kernel from the PGKBUILD I posted before.  Only probelm i run into is my system locks up when I am building.  I think this could be due to bad RAM.

Offline

#7 2005-04-13 06:51:48

lucke
Member
From: Poland
Registered: 2004-11-30
Posts: 4,018

Re: PKGBUILD first time for kernel (or building a custom kernel)

Use memtest to get sure :-)

Offline

#8 2005-04-13 11:59:40

dtw
Forum Fellow
From: UK
Registered: 2004-08-03
Posts: 4,436
Website

Re: PKGBUILD first time for kernel (or building a custom kernel)

digi691 - not your fault, dude, sorry you got caught up in it!

I have re-written the wiki if you are interested!

The PKGBUILD you posted looks exactly like the regular one on the wiki so, aside from the fact it doesn't do what it should with 2.6.x.y kernels it should have still built fine.

It's good you have said you were confused about the logo and the patch - i have now taken that out and added comments for people who want to put it back in big_smile

Offline

#9 2005-04-13 12:05:39

Mr Green
Forum Fellow
From: U.K.
Registered: 2003-12-21
Posts: 5,751

Re: PKGBUILD first time for kernel (or building a custom kernel)

It does help .. when looking for kernel build in wiki

http://wiki2.archlinux.org/index.php/Ti … e&s=kernel

Which one to go for  :?


Mr Green

Offline

Board footer

Powered by FluxBB