Monday, April 20, 2009

bash script, spaces in filenames

Delete all mp3s. Don't ask why...
find . -name '*.mp3' |while read FILE; do rm "$FILE"; done


List disk usage for all items in a dir
ls |while read i; do du -sh "$i";  done

This is easier done with
du -sh *

but it's the usage of "while read" I wanted to show.

Sunday, April 19, 2009

Look up hardware for kernel and module compilation

PCI Devices

List kernel drivers and modules

lspci -k
00:1f.1 IDE interface: Intel Corporation 82801G (ICH7 Family) IDE Controller (rev 01)
Kernel driver in use: ata_piix
00:1f.2 IDE interface: Intel Corporation 82801GB/GR/GH (ICH7 Family) SATA IDE Controller (rev 01)
Kernel driver in use: ata_piix
00:1f.3 SMBus: Intel Corporation 82801G (ICH7 Family) SMBus Controller (rev 01)
Kernel driver in use: i801_smbus
Kernel modules: i2c-i801

(This is just a small portion of the output from the command, it is normally longer)

List more info about the hardware

lspci -s <bus>:<slot>
ker@srv1:~$ sudo lspci -vv -s 0:1e


To just list the drivers and modules in use do
sudo lspci -k |grep Kernel

Then make sure they're activated in the kernel config

USB

lsusb
lsusb -s <bus>:<slot>

Thursday, April 16, 2009

Patch linux kernel 2.6.29 to 2.6.30-rc2

Download "2.6.29" NOT "2.6.29.1" and the patch for 2.6.30-rc2 from kernel.org.

then

tar xvf linux-2.6.29.tar.bz2
bunzip2 patch-2.6.30-rc2.bz2
cd linux-2.6.29
patch -p1 <../patch-2.6.30-rc2


now compile as usual.

You can check the Makefile for the new version:

/usr/src/linux-2.6.30-rc2$ head Makefile
VERSION = 2
PATCHLEVEL = 6
SUBLEVEL = 30
EXTRAVERSION = -rc2
NAME = Temporary Tasmanian Devil


Rename the source dir also

mv 2.6.29 2.6.30-rc2

Compile nvidia on kernel 2.6.30-rc2

Compiling nvidia on a 2.6.30-rc2 ends in disappointment with "Could not build module" and the log (/var/log/nvidia-installer.log) shows an error about not finding "owner" in struct "proc_dir_entry" in nv.c.

unpack the NVIDIA-Linux-x86-180.44-pkg1.run (or pkg2 if x86_64) with -x

sh NVIDIA-Linux-x86-180.44-pkg1.run -x


in NVIDIA-Linux-x86-180.44-pkg1/usr/src/nv/nv.c
just replace the lines with
    entry->owner = THIS_MODULE;

with

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
entry->owner = THIS_MODULE;
#endif


make sure to not forget the last endif closing the ifdef CONFIG_PROC_FS
so on line 718 you'll have:

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
entry->owner = THIS_MODULE;
#endif
#endif


then run the nvidia installer script in the root of the unpacked binary

./nvidia-installer

Sunday, April 12, 2009

Compiling kernel on debian or ubuntu

On a Ubuntu 9.04 Jaunty Jackalope, 2.6.28-11-generic #41-Ubuntu

Install necessary tools and get the latest kernel
apt-get install kernel-package libncurses5-dev fakeroot
wget ftp://ftp.sunet.se/pub/Linux/kernel.org/linux/kernel/v2.6/linux-2.6.29.1.tar.bz2

Unpack and change to the source dir
tar xvf linux-2.6.29.1.tar.bz2
cd linux-2.6.29.1

Make sure we clean out old config files and debris if we've compiled from this source before
make clean && make mrproper

Copy the running config,check with uname -r
cp /boot/config-2.6.28-11-generic ./.config

Run menuconfig and pick up the config file, make changes and exit
make menuconfig

If you're on multiple cores/cpus set CONCURRENCY_LEVEL (same as -j for make) to number of cpus/cores.

export CONCURRENCY_LEVEL=2

(It tells make to run multiple jobs in parallel)
Clean then compile
make-kpkg clean
time fakeroot make-kpkg --initrd kernel_image kernel_headers


Afterwards you may have to recompile stuff like graphics drivers (modules) for your new kernel.
With nVidia I just save my current xorg.conf then run the nvidia installer, copy back my xorg.conf and restart X.

NB: You can check module versions (and license) with modinfo