Difference between revisions of "Upgrading the Kernel"
(→Steps) |
(→Steps) |
||
Line 61: | Line 61: | ||
* Disabled kernel debugging ('''Note: This is very important if you plan to use this kernel on Media Directors.''') | * Disabled kernel debugging ('''Note: This is very important if you plan to use this kernel on Media Directors.''') | ||
+ | If you have a multiprocessor system you can make the next step run faster with this command. Change the number to be equal to the number of cores you have +1. | ||
+ | export CONCURRENCY_LEVEL=3 | ||
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. | 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. |
Revision as of 06:45, 1 November 2008
Introduction
The ability to change kernel versions at will can be extremely useful for fighting driver bugs and regressions. The kernel version that ships with LinuxMCE 0710 is 2.6.22-14. At the time of writing the most recent kernel version is 2.6.26.5. The .22 kernel is almost a full year old and as such does not support a lot of the newer hardware.
Caveats
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.
Alternatives
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.
Example:
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.
Potential problems
All the normal issues of upgrading your kernel apply. Always keep your old, working kernel on hand.
Steps
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-2.6.26.5.tar.bz2 tar -jxvf linux-2.6.26.5.tar.bz rm linux ln -s linux-2.6.26.5 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.
apt-get install libncurses5 libncurses5-dev make menuconfig 2> module_errors
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.)
If you have a multiprocessor system you can make the next step run faster with this command. Change the number to be equal to the number of cores you have +1.
export CONCURRENCY_LEVEL=3
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.
make 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-2.6.26.5 mkinitramfs -o /boot/initrd.img-2.6.26.5 2.6.26.5 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-2.6.22.14
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.
reboot
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.
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.17.tar.bz2 wget ftp://ftp.alsa-project.org/pub/firmware/alsa-firmware-1.0.17.tar.bz2 wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.17a.tar.bz2 wget ftp://ftp.alsa-project.org/pub/plugins/alsa-plugins-1.0.17.tar.bz2 wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.0.17.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 done cd alsa-driver-1.0.17 ./configure --with-cards=hda-intel make make install cd .. for fi in alsa-lib-1.0.17a alsa-plugins-1.0.17 alsa-utils-1.0.17 alsa-oss-1.0.17 alsa-firmware-1.0.17; do cd $fi ./configure make make install cd .. done
For Asterisk, simply download the latest Zaptel sources. Configure, Make, Install.
wget http://downloads.digium.com/pub/zaptel/zaptel-1.4.12.1.tar.gz tar -zxvf zaptel-1.4.12.1.tar.gz cd zaptel-1.4.12.1 ./configure --prefix=/usr make make install
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 2.6.26.5 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 2.6.26.5.
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 make install reboot
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
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.
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-2.6.26.5 ln -s initrd.img-2.6.22-14-generic initrd.img-2.6.26.5 done 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-2.6.26.5 $md/boot/ cp /boot/initrd.img-2.6.26.5 $md/boot/ cp -r /lib/modules/2.6.26.5/ $md/lib/modules/ /usr/pluto/bin/Diskless_InstallKernel.sh $md_device done /usr/pluto/bin/Diskless_BuildDefaultImage.sh
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-2.6.26.5 boot cp /boot/initrd.img-2.6.26.5 boot cp -r /lib/modules/2.6.26.5/ 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.
stripheader.sh
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/2.6.26.5/kernel/drivers/video/ done