You are not logged in.

#1 2004-07-01 05:05:36

android
Member
From: San Diego
Registered: 2003-04-18
Posts: 160

A PKGBUILD that allows multiple installed kernels

Hi All,

I've had so many people help me with so many things here at Arch, hopefully this will be useful to someone.

What is it:
I've got a kernel PKGBUILD file that allows me to build and install as many different kernels as desired, as long as each one has a unique $pkgver-$pkgrel setting.

/var/abs/local/kernel-custom1/PKGBUILD:

# $Id: PKGBUILD,v 1.17 2004/05/11 23:25:20 judd Exp $
# Maintainer: judd <jvinet@zeroflux.org>
# 2004/06/30: Modified to support multiple loaded kernels -jea
# Any kernel with a unique $pkgver-$pkgrel will not conflict with others.
pkgver=2.6.6
pkgrel=custom1
# name mangling is necessary so pacman will load multiple packages
pkgname=kernel$pkgver$pkgrel
pkgdesc="Linux Kernel ver: $pkgver, build: $pkgrel"
url="http://www.kernel.org"
depends=('module-init-tools')
# Is this file were patches to grub/menu.lst should occur? -jea
install=kernel26.install
source=(ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-$pkgver.tar.bz2 
        config)
# patch makepkg to use as many sums as listed, in order? -jea
md5sums=('5218790bc3db41e77a7422969639a9ad' 'fd32e9f43e9b6060e01f71d666372518')

build() {
  cd $startdir/src/linux-$pkgver
  # get rid of the 'i' in i686
  carch=`echo $CARCH | sed 's|i||'`
  cat ../config | sed "s|#CARCH#|$carch|g" >./.config
  yes "" | make config
  # set EXTRAVERSION to create unique /lib/modules/ subdirectories
  cat Makefile | sed "s|EXTRAVERSION =|EXTRAVERSION = -$pkgrel|" > tmpMake
  mv tmpMake Makefile
  make clean bzImage modules || return 1
  mkdir -p $startdir/pkg/{lib/modules,boot}
  make INSTALL_MOD_PATH=$startdir/pkg modules_install || return 1
  # create unique names in /boot/
  cp System.map $startdir/pkg/boot/System.map-$pkgver-$pkgrel
  cp arch/i386/boot/bzImage $startdir/pkg/boot/vmlinuz-$pkgver-$pkgrel
  install -D -m644 Makefile $startdir/pkg/usr/src/linux-$pkgver/Makefile
  install -D -m644 .config $startdir/pkg/usr/src/linux-$pkgver/.config
  install -D -m644 .config $startdir/pkg/boot/kconfig-$pkgver-$pkgrel
  mkdir -p $startdir/pkg/usr/src/linux-$pkgver/include
  mkdir -p $startdir/pkg/usr/src/linux-$pkgver/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-$pkgver/include/
  done
  # copy files necessary for later builds, like nvidia and vmware
  # does this "$pkgver-$pkgrel" multi-kernel strategy screw these up? -jea
  cp -a scripts $startdir/pkg/usr/src/linux-$pkgver/
  cp arch/i386/Makefile $startdir/pkg/usr/src/linux-$pkgver/arch/i386/
  cp arch/i386/kernel/asm-offsets.s $startdir/pkg/usr/src/linux-$pkgver/arch/i386/kernel/
  # copy in Kconfig files
  for i in `find . -name "Kconfig*"`; do
    mkdir -p $startdir/pkg/usr/src/linux-$pkgver/`echo $i | sed 's|/Kconfig.*||'`
    cp $i $startdir/pkg/usr/src/linux-$pkgver/$i
  done
  cd $startdir/pkg/usr/src/linux-$pkgver/include && ln -s asm-i386 asm
  cd $startdir/pkg/usr/src
  # create a unique subdirectory under /usr/src/
  mv linux-$pkgver linux-$pkgver-$pkgrel
  chown -R root.root $startdir/pkg/usr/src/linux-$pkgver-$pkgrel
  cd $startdir/pkg/lib/modules/$pkgver-$pkgrel && 
    (rm -f build; ln -sf /usr/src/linux-$pkgver-$pkgrel build)
}

How it works:
The primary thing I've usually done is wipe out my custom kernel by inadvertantly overwriting the loadable modules in the /lib/modules/$pkgver directory with a pacman -Su.

The reason for this is that the current arch kernel build does not set the EXTRAVERSION variable in the kernel top level makefile. Therefore all kernels of the same $pkgver use the same /lib/modules/$pkgver/ subdirectory.

The above PKGBUILD sets EXTRAVERSION to the $pkgrel variable.

This causes the loadable module tree to be in a /lib/modules/$pkgver-$pkgrel/ directory.

There are two other places where kernels experience file conflicts:
/boot/
/usr/src/

The /boot/ files: vmlinuz, System.map and kconfig are given unique names by appending the $pkgver-$pkgrel string.

The /usr/src/linux-$pkgver/ directory is moved to /usr/src/linux-$pkgver-$pkgrel/.

This allows the loadable kernel, the loadable modules and the stripped source headers to be in a unique place for each different kernel. Therefore multiple kernels can be loaded concurrently and the desired one may be chosen at boot time by grub.

The only thing a little weird about this, is the $pkgname variable. pacman will only load one version of each $pkgname, so for multiple kernels to be loaded, they each have to have a unique $pkgname. This is accomplished by appending the $pkgver and $pkgrel to the $pkgname. This is fine, except it gives a slightly weird name for the resulting kernel package file. It has the format:
kernel$pkgver$pkgrel-$pkgver-$pkgrel.pkg.tar.gz

That is, the $pkgver and $pkgrel appear in the package file name twice. This also shows if one issues:
pacman -Q | grep kernel -

Which yields for me:
kernel2.6.6custom1 2.6.6-custom1
kernel2.6.61 2.6.6-1
kernel26 2.6.7-1

This command could only have shown one package before, now it shows that I currently have installed: a custom 2.6.6 kernel, the stock arch 2.6.6 kernel built with the above PKGBUILD and the current arch kernel26 package.

I may choose between any of these at boot time with grub. And as an added bonus, the next time I pacman -Su I won't wipe out my custom /lib/modules subdirectory 8-)

All of this assumes the supply of your own custom config file as in the arch wiki Building the Kernel in ABS instructions.

Idle thoughts:
It would sure be nice if something like this could be adopted for the stock arch kernels. Unlike most other packages it is often desirable to have multiple versions of the kernel package installed at once.

I wonder if it is practical for pacman to allow multiple versions of the same $pkgname to be installed concurrently if the $pkgname-$pkgver-$pkgrel string is unique and the different versions do not have file conflicts?

The other major package I could see this being applied to is gcc. It would be really cool to load different cross and other configurations of gcc concurently.

I find one of the most diifficult things needed to get a workstation running is getting all of the correct kernel modules built in. It seems that most PCs today have all the major features built in to the motherboard chipset: graphics controller, sound, usb, ethernet, etc. If it was possible to build a database of custom kernels, one for each major chipset, then one could be chosen by hardware detection at install time. This would provide the benefits of a custom kernel in an autoload fashion.

Just dreaming...

Conclusion:
I'm not sure how this strategy fits in with the bigger pictiure of running pkg repositories, building dependent packages, who knows what else.

The thing I hope to add next is automatically adding and removing entries into: /boot/grub/menu.lst when the kernel package is installed and removed. The $pkgdesc string is perfect for serving as the title line.

Hopefully this can be useful to others, it has helped me clean up my multi-kernel mess here.

Thanks Again for such an awesome distro...

John E. A.

p.s Arch Rulz!

Offline

#2 2004-07-01 05:26:54

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: A PKGBUILD that allows multiple installed kernels

Thank you, I tried to set something up like this in the wiki, but never tested it and it didn't work for some users. You've tested it well?

If so, you can copy it over to the wiki (edit or overwrite the Kernel compile with ABS wiki entry), or I can.

Thanks again, its much appreciated.

Dusty

Offline

#3 2004-07-01 07:59:31

android
Member
From: San Diego
Registered: 2003-04-18
Posts: 160

Re: A PKGBUILD that allows multiple installed kernels

I've built a half dozen or so kernels, loaded and unloaded them.

Everything seems to work. (looking for a "knocking on wood" emoticon 8-)

I'll create a new wiki doc and copy this stuff in...

John E. A.

Offline

#4 2004-07-01 09:24:26

android
Member
From: San Diego
Registered: 2003-04-18
Posts: 160

Re: A PKGBUILD that allows multiple installed kernels

OK, first swag at wiki text is online:

http://wiki.archlinux.org/index.php/Bui … with%20ABS

John E. A.

Offline

#5 2004-07-01 13:02:22

dp
Member
From: Zürich, Switzerland
Registered: 2003-05-27
Posts: 3,378
Website

Re: A PKGBUILD that allows multiple installed kernels

excellent documentation!


The impossible missions are the only ones which succeed.

Offline

#6 2004-07-01 15:03:39

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: A PKGBUILD that allows multiple installed kernels

Very good!

Offline

Board footer

Powered by FluxBB