Upgrading the Kernel

From LinuxMCE
Jump to: navigation, search


The ability to change kernel versions at will can be extremely useful for fighting driver bugs and regressions. This article provides procedures for upgrading the kernel.

LinuxMCE 0810

Upgrading kernels is significantly easier in 0810, now that LinxMCE uses the standard Ubuntu kernel. If you're interested in using a non-standard kernel, you can adapt the 0710 instructions to your needs.

Apt Repositories

If the kernel version you're looking for is not available in the standard repositories, you might have to enable the proposed repositories by adding a line that looks something like:

deb http://ubuntu.media.mit.edu/ubuntu/ intrepid-proposed restricted main universe multiverse

to /etc/apt/sources.list. Of course, you'll want to use the package mirror that is closest to you, probably not MIT. After adding this line, run apt-get update to refresh the package lists.


On the core, simply install the new kernel like any other package. Don't forget the restricted modules and headers if you need them.

linuxmce@dcerouter:~$ sudo apt-get install linux-image-2.6.27-13-generic linux-restricted-modules-2.6.27-13-generic linux-headers-2.6.27-13-generic

If you always want the most up-to-date kernel, consider installing the package linux. (This is outside of the scope of this article.)

On MDs, there is one extra step. You will need to update some links in /boot/.

root@moon44:~# cd /boot/
root@moon44:/boot# mv initrd.img initrd.img.bk
root@moon44:/boot# mv vmlinuz vmlinuz.bk
root@moon44:/boot# ln initrd.img-2.6.27-13-generic initrd.img
root@moon44:/boot# ln vmlinuz-2.6.27-13-generic vmlinuz

Installing newer 2.6.3x kernels for 0810 via PPA repository

Ubuntu Kernel team maintains mainline kernel builds and PPA reposotory from which you can get newer kernel images than ones in official Ubuntu 8.10 repositories.

This feature hasn't been tested, so please do this at your own risk. Risk should be minimal because you will still have your old kernel and boot it if this one doesn't work as expected.

First download new kernel images, in this example

wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v2.6.32.8/linux-headers-2.6.32-02063208_2.6.32-02063208_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v2.6.32.8/linux-headers-2.6.32-02063208-generic_2.6.32-02063208_i386.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v2.6.32.8/linux-image-2.6.32-02063208-generic_2.6.32-02063208_i386.deb

There is one missing dependency and that is solved by installing wireless-crda package. But this package is not available in 8.10 Intrepid repository. But is available in 9.10 Jaunty repository. So download .deb for this package from here and install it using dpkg command. Then kernel image .deb installation should succeed.

wget http://mirrors.kernel.org/ubuntu/pool/main/w/wireless-crda/wireless-crda_1.7_i386.deb

Installing packages

sudo dpkg -i wireless-crda_1.7_i386.deb
sudo dpkg -i linux-headers-2.6.32-02063208_2.6.32-02063208_all.deb
sudo dpkg -i linux-headers-2.6.32-02063208-generic_2.6.32-02063208_i386.deb
sudo dpkg -i linux-image-2.6.32-02063208-generic_2.6.32-02063208_i386.deb

I get some error while installing new kernel image but it works after reboot.

run-parts: executing /etc/kernel/header_postinst.d/dkms
 *  nvidia (195.36.15)...
nvidia (195.36.15): Installing module.
 *  v4l2-modules (304cfde05b3f)...
v4l2-modules (304cfde05b3f): Installing module.
...........(bad exit status: 10)
  Build failed.  Installation skipped.
run-parts: executing /etc/kernel/header_postinst.d/nvidia-common

Edit GRUB menu

Now you only need to add this new kernel to grub menu. Best it to add it below previous entries so that it doesn't get started by default but only if you choose to do so until you are positive it work better than previous kernel.

sudo kate /boot/grub/menu.lst

If GRUB is not automatically updated you need to add these lines:

title		LinuxMCE 8.10, kernel 2.6.32
uuid		843c0ec3-56ea-4988-a05a-b3cf4fecc709
kernel		/boot/vmlinuz-2.6.32-02063208-generic root=UUID=843c0ec3-56ea-4988-a05a-b3cf4fecc709 ro quiet splash 
initrd		/boot/initrd.img-2.6.32-02063208-generic

title		LinuxMCE 8.10, kernel 2.6.32 (recovery mode)
uuid		843c0ec3-56ea-4988-a05a-b3cf4fecc709
kernel		/boot/vmlinuz-2.6.32-02063208-generic root=UUID=843c0ec3-56ea-4988-a05a-b3cf4fecc709 ro  single
initrd		/boot/initrd.img-2.6.32-02063208-generic

Helpful links

LinuxMCE 0710

WARNING: This procedure will break certain things and may even make your system unusable, therefore use at your own risk. Of course, if your system is not working or is unstable anyway, then trying this could improve things!

The kernel version that ships with LinuxMCE 0710 is 2.6.22-14. At the time of writing the most recent stable kernel version is The .22 kernel is almost a full year old and as such does not support a lot of the newer hardware.

Note- kernel version 2.6.27 has changes in it (a redefined set of arguments for smp_call_function) which breaks earlier versions of the Nvidia driver. Nvidia drivers 178.80 and above should work.


Some modules that are part of the vanilla Linux MCE installation are not part of the standard Linux kernel. These modules have been added as part of the Ubuntu distribution or by LMCE. It is not always straight forward, or even possible to compile these modules against different kernel sources. I suggest you read this entire Wiki first, to determine if you will be affected by the missing modules.


Usually kernels are upgraded for better driver support. In these cases it is often easier to compile new versions of modules against the 2.6.22-14 kernel than it is to upgrade the whole kernel (for reasons mentioned in the caveats section. Unfortunately, a lot of modules depend on other modules or patches in the kernel. So this option is not always possible.


cd ~
wget http://www.somesite.com/some_kernel_driver.c
echo obj-m = some_kernel_driver.o > Makefile
cd /lib/modules/2.6.22-14-generic/build
make M=~ modules
ls -l ~/some_kernel_driver.ko

You may then copy the module to the appropriate directory in the modules tree.

Upgrade process

This wiki will provide step-by-step instructions on how to upgrade your kernel. These examples will assume you are upgrading to 2.6.26 from 2.6.22. You may however apply these steps to any 2.6 kernel.

An alternative approach is described here Rebuilding the kernel the debian way. Anyone using this potentially easier method could update this document.

Potential problems

All the normal issues of upgrading your kernel apply. Always keep your old, working kernel on hand.


Recompiling the kernel

The first step is to grab the kernel source and extract it to the /usr/src folder.

cd /usr/src
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-
tar -jxvf linux-
rm linux
ln -s linux- linux

Now lets copy the .config file from our generic 2.6.22 kernel.

cd linux
cp /boot/config-2.6.22-14-generic .config

On our first load of menuconfig there will be many warnings displayed about non-existant config options. This is simply due to the removal or renaming of old options. Most of these warnings are insignificant, and enabled by default in the vanilla kernel. I would quickly go over the list of warnings and verify that any drivers you need haven't been renamed. One option that has been renamed is DVB_CORE_ATTACH. It is now DVB_MEDIA_ATTACH, and you may need it if you use the DVB stack. Also some netfilter matches have been renamed. Simply reselect these from the config menus. You may also need to install the ncurses library and development files if you haven't already.

sudo apt-get install libncurses5 libncurses5-dev qt3-dev-tools libqt3-mt-dev

Then you can either choose to use the character based interface to set your kernel options

make menuconfig 2> module_errors

Or you can use the GUI interface

DISPLAY=:0.0 make xconfig

It's also a good idea to go over the kernel and make any optimizations for your particular system. The performance gain from these options is fairly minor, but definitely worth selecting.

I opted to change these things:

  • Selected exact processor family to enable processor optimization extensions
  • Selected preemptive kernel (low latency)
  • Build SATA driver into kernel
  • Build MD,RAID1,RAID5 modules into kernel
  • Build NIC module into kernel
  • Disabled kernel debugging (Note: This is very important if you plan to use this kernel on Media Directors.)

At this point you can start the kernel build process. You may use the standard kernel method or the Debian build method. For simplicity this Wiki will use the standard method.

sudo make modules_install

Copy your kernel image to your /boot folder. Create a new initramfs image. Update your menu.lst file.

cp arch/yyxx/boot/bzImage /boot/vmlinuz-
mkinitramfs -o /boot/initrd.img-
nano /boot/grub/menu.lst

Save a list of all currently used modules for future reference. You will use this later to make sure you have all the required modules.

  lsmod > ~/module_list-

Go ahead and reboot. Your new kernel should now load. If your boot fails, simply edit the parameters from the grub menu and specify your old kernel and initramfs image. Please note: udev attempts to assign persistent names to most devices. If the way the kernel identifies your device changes from your old kernel version to the new one, udev may assume it's a new device and assign it an unexpected name. For example, the nForce ethernet drivers corrected a bug in the way the MAC address was read from the device. On my first boot what was usually my eth0 device was now my eth1 device. To fix this simply flush the offending rule from the /etc/udev/rules.d folder.

Additional items which need to be rebuilt

You should now build any custom modules you need. Linux MCE (and Ubuntu) come with some non-standard drivers. The key modules to worry about are AppArmor, Asterisk (ztdummy & zaptel), ALSA, nVidia video, ATI video. You are better off downloading the latest nVidia and ATI drivers and installing them using the instructions found in the display drivers wiki. The Gutsy kernel also contains other important video drivers, like ivtv. However most of these drivers are now in the mainstream kernel and more up-to-date than the Gutsy versions.


You do not have to rebuild Mythtv, but if you chose to use the new High Precision Event Timer (HPET) instead of the older kernel Real Time Clock (RTC), then Mythtv will not start up because /proc/sys/dev/rtc/max-user-freq does not exist. This is because the LinuxMCE 7.10 /etc/init.d/mythtv-backend script does not check if it exists before trying to write to it. You will have to change your /etc/init.d/mythtv-backend script as follows:

case "$1" in
       if test -e $RUNDIR/$NAME.pid ; then
           echo "mythbackend already running, use restart instead."
           # set the timeslice to 1/1024 of a sec for smoother mythtv and xine and mplayer playback 
           if [ -w /proc/sys/dev/rtc/max-user-freq ] # check if RTC (older kernels) exists and I can write to it
               # failure is not an option!
           then echo 1024 > /proc/sys/dev/rtc/max-user-freq
       elif [ -w /proc/sys/dev/hpet/max-user-freq ] # or newer kernels with the High Precision Timer (HPET)
           # may or may not emulate the older RTC fully
       then echo 1024 > /proc/sys/dev/hpet/max-user-freq
   fi # start starting the startup of mythtv 
echo -n "Starting $DESC: $NAME " start-stop-daemon --start --pidfile $RUNDIR/$NAME.pid \ 

I have decided to forgo the AppArmor module. Compiling and running this module would require a complete upgrade of the whole package in addition to manually patching many areas of the kernel. This is entirely too much work for something that is largely useless in a Linux MCE installation.


For the ALSA drivers I opted to upgrade the whole package. The compilation and installation is so straight forward that there's no reason to play around with mixmatched versions. Just rebuild both the kernel drivers and the userspace utilities. Here are the steps for that (Note: You should select your card specifically for the alsa-driver package, using the --with-cards option):

mkdir alsa
cd alsa
wget ftp://ftp.alsa-project.org/pub/driver/alsa-driver-1.0.19.tar.bz2
wget ftp://ftp.alsa-project.org/pub/firmware/alsa-firmware-1.0.19.tar.bz2
wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.19.tar.bz2
wget ftp://ftp.alsa-project.org/pub/plugins/alsa-plugins-1.0.19.tar.bz2
wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.0.19.tar.bz2
wget ftp://ftp.alsa-project.org/pub/oss-lib/alsa-oss-1.0.17.tar.bz2
for fi in *; do
tar -jxvf $fi
cd alsa-driver-1.0.19 
./configure --with-cards=hda-intel
sudo make install
cd ..
for fi in alsa-lib-1.0.19 alsa-plugins-1.0.19 alsa-utils-1.0.19 alsa-oss-1.0.19 alsa-firmware-1.0.19; do
cd $fi
sudo make install
cd ..
Asterisk telephony

For Asterisk, simply download the latest Zaptel sources. Configure, Make, Install.

wget http://downloads.digium.com/pub/zaptel/zaptel-
tar -zxvf zaptel-
cd zaptel-
./configure --prefix=/usr
sudo make install

For kernel >= 2.6.28 a fix is needed Save the following as zaptel-kernel.patch :

--- zaptel-        2009-04-11 00:26:02.000000000 +0200
+++ zaptel-    2009-04-11 00:26:53.000000000 +0200
@@ -199,7 +199,12 @@
         * expired.
         * We should worry if overrun is 2 or more; then we really missed
         * a tick */
-       overrun = hrtimer_forward(&zaptimer, htmr->expires,
+       overrun = hrtimer_forward(&zaptimer,
+                      hrtimer_get_expires(htmr),
+                      htmr->expires,
                        ktime_set(0, ZAPTEL_TIME_NS));
        if(overrun > 1) {

and apply after untaring like this :

tar -zxvf zaptel-
patch -p0 <zaptel-kernel.patch
LIRC IR control

You will also need to recompile LIRC. Note: Some LIRC drivers are not SMP safe and will not compile on SMP kernels. In this case I suggest you pick only the drivers you need.

For kernel version 2.6.27 the following LIRC setup steps worked. The only issue you will have is with some modules not compiling, as noted above. Just compile the module you need for your remote- for me it was mceusb2.

 cd /opt/lirc
 wget http://prdownloads.sourceforge.net/lirc/lirc-0.8.4a.tar.bz2
 tar -xjvf lirc-0.8.4a.tar.bz2
 ./configure --prefix=/usr --with-driver=usbmce2

At this point if you get errors about not being about to overwrite /usr/lib/liblirc_client.la you may need to

 cp /usr/lib/liblirc_client.la /opt/lirc/liblirc_client.la.orig
 dpkg --force-overwrite -i lirc_0.8.4a-1_i386.deb

Proceed with

 modprobe lirc_mceusb2

Press some buttons on your remote, you should see information appear about the IR being received.

For I had to patch some files in the kernel to get LIRC to compile. The patch is located on the LIRC site. Also only the CVS version will compile. I ran into even more drama with LIRC, because many drivers failed to even attempt a build. I was able to manually enter each driver directory and perform a make/make install. After applying the patch to the kernel, it failed to compile as well. At this point I would assume that LIRC is not working with

cd /usr/src/linux
wget http://lirc.sourceforge.net/software/snapshots/lirc-bttv-linux-2.6.24.patch
patch -p1 < lirc-bttv-linux-2.6.24.patch
cd ..
cvs -z8 -d:pserver:anonymous@lirc.cvs.sourceforge.net:/cvsroot/lirc co lirc
cd lirc-0.8.3
./configure --prefix=/usr --with-driver=all
make install 
Video driver

You will most likely need to reinstall your video driver at this point, if you used a proprietary binary version. Instructions for getting the latest driver and installing it can be found in the display drivers wiki.

For nVidia do this:

wget http://us.download.nvidia.com/XFree86/Linux-x86/177.80/NVIDIA-Linux-x86-177.80-pkg1.run
sh NVIDIA-Linux-x86-177.80-pkg1.run

If you have already had a newer version of the driver installed, then just install the kernel module like this :

sh NVIDIA-Linux-x86-XXX.XX-pkg1.run -K

Now it is a good idea to compare your lsmod output from your old kernel to the output of your new kernel. Just to be certain you didn't miss anything. I found the order to be different, so I copied the output to an Excel spreadsheet and sorted the two different lists. The only discrepancies I found were related to name changes in the kernel and AppArmor.

Tuner and other drivers

Don't forget to recompile and install other drivers which you may have had to install to get your system working. These include the V4L DVB drivers.

Media Directors

In a traditional installation the Core and Media Directors all run the Gutsy 2.6.22-14 kernel. You may still use this kernel if you like, or you may opt to use your newly built kernel.

Use old kernel

If you want the media directors to continue to use this old kernel then you must create a symlink to the old kernel in the boot directory of each MD. You must also update the MD archives with this symlink, so future MDs will be setup correctly.

mkdir /tmp/moonfs_64 /tmp/moonfs_32
tar -jxvf /usr/pluto/install/PlutMD-adm64.tar.bz2 /tmp/moonfs_64/
tar -jxvf /usr/pluto/install/PlutMD-i386.tar.bz2 /tmp/moonfs_32/
for md in /usr/pluto/diskless/* /tmp/moonfs_64 /tmp/moonfs_32; do
md_device=`echo "$md" | sed -e 's/.*[/]\([^/]\)/\1/g'`
cd $md/boot
ln -s vmlinuz-2.6.22-14-generic vmlinuz-
ln -s initrd.img-2.6.22-14-generic initrd.img-
tar -C /tmp/moonfs_64 -jcvpf /usr/pluto/install/PlutoMD-adm64.tar.bz2 .
tar -C /tmp/moonfs_32 -jcvpf /usr/pluto/install/PlutoMD-i386.tar.bz2 .
rm -rf /tmp/moonfs_*
Use new kernel

A better route, although more complex one is to use your new kernel on the media directors as well. You can do this by copying your kernel and modules to each MD root filesystem. Additionally, you will need to add the kernel image plus modules to the MD root archive (/usr/pluto/install/PlutoMD-xxxyyy.tar.bz2) where xxxyyy is your architecture. This does present an issue if your core and media directors are not the same architecture. In this case you will need to build a kernel for the other architecture using cross-compile methods or using a machine of the that architecture.

These scripts serve as a guideline, and may need to be customized to your unique configuration.

A few notes:

  • Your initrd-img file should be about 10MB. If it is around the 40MB mark you compiled your kernel with debugging support. The tftp server will refuse to transfer files this large. As a result, all MDs will fail to boot. If you absolutely must use a debugging kernel then there are options you can pass to tftp to make it ignore this limit.
  • These scripts assume all media directors and cores are 64-bit machines. It is left as an exercise for the reader to distribute the proper kernel image for the target MD's architecture.
  • You should build your video driver files first, so you can include them in your MD archive.
for md in /usr/pluto/diskless/*; do
md_device=`echo "$md" | sed -e 's/.*[/]\([^/]\)/\1/g'`
cp /boot/vmlinuz- $md/boot/
cp /boot/initrd.img- $md/boot/
cp -r /lib/modules/ $md/lib/modules/
/usr/pluto/bin/Diskless_InstallKernel.sh $md_device

Now rebuild the archives, so future Media Directors will get the correct kernel image.

cd /tmp
mkdir moonfs_x64
cd moonfs_x64
tar -jxvf /usr/pluto/install/PlutMD-adm64.tar.bz2
cp /boot/vmlinuz- boot
cp /boot/initrd.img- boot
cp -r /lib/modules/ lib/modules/
tar -jcvpf /usr/pluto/install/PlutoMD-adm64.tar.bz2 *
cd ..
rm -rf moonfs_x64

Video Drivers

Video drivers for Media Directors get their own section because they often require updated libraries in addition to updated kernel modules. These libraries will have to be distributed to the media directors and updated in the archive. nVidia's driver installation script provides many useful options for this. I have not looked into a way to do with the ATI drivers, but I assume it's similar.

You will need this small script I made. NVIDIA packages the precompiled kernel interface with a proprietary header. Removing the header allows you to link the interface and kernel module manually.


readsint ()
  byte=`head -c$2 $1 | tail -c1`
  sint=`printf '%u' "'$byte"`
  let "sint=$sint & 0xFF"
  eval "$3=\"$sint\""
readuint32 ()
  readsint $1 $(($2+1)) b1
  readsint $1 $(($2+2)) b2
  readsint $1 $(($2+3)) b3
  readsint $1 $(($2+4)) b4 

  uint=$(( ($b4 << 24) + ($b3 << 16) + ($b2 << 8) + $b1 ))
  eval "$3=\"$uint\""

let "header=12"
readuint32 $1 $header int
let "header=$header+$int+4"
readuint32 $1 $header int
let "header=$header+$int+4"
readuint32 $1 $header int
let "header=$header+$int+4"

precomp=$(stat -c%s "$1")
let "precomp-=$header"
tail -c$precomp $1 > $2

These commands will update each Media Director. You should also copy these files into the MD archives. This is left as an exercise for the reader.

wget http://us.download.nvidia.com/XFree86/Linux-x86_64/173.14.12/NVIDIA-Linux-x86_64-173.14.12-pkg2.run
sh NVIDIA-Linux-x86_64-173.14.12-pkg2.run --keep --add-this-kernel
./stripheader.sh NVIDIA-Linux-x86_64-173.14.12-pkg2/usr/src/nv/precompiled/precompiled-nv-linux.o* NVIDIA-Linux-x86_64-173.14.12-pkg2/usr/src/nv/nv-linux.o
ld -d -r -o nvidia.ko NVIDIA-Linux-x86_64-173.14.12-pkg2/usr/src/nv/nv-linux.o NVIDIA-Linux-x86_64-173.14.12-pkg2/usr/src/nv/nv-kernel.o
for md in /usr/pluto/diskless/*; do
cp -r NVIDIA-Linux-x86_64-173.14.12-pkg2/usr/* $md/usr/
cp nvidia.ko $md/lib/modules/