Sunday, October 25, 2009

First linux kernel module

echo "create xyz.c"
#include
MODULE_LICENSE("Dual BSD/GPL");




echo "create Makefile"
obj-m := nothing.o



echo "compile module"
make -C /usr/src/kernel-source-2.6.8 M=pwd modules



echo "install the module"
insmod xyz.ko



echo "check module is installed"
lsmod | grep xyz



echo "remove module"
rmmod xyz

linux links

File Collection
piavka

ubuntu add patches to kernel

Get patch xyz.bz2 to /usr/src.
cd /usr/src/linux


echo "dry run and then actual patch"
bzip2 -dc /usr/src/patch.bz2 | patch -p1 --dry-run
bzip2 -dc /usr/src/patch.bz2 | patch -p1

ubuntu first kernel compile

echo "copied from \"http://www.howtoforge.com/kernel_compilation_ubuntu\""
echo "Become the superuser and use bash"

sudo passwd root; su; rm -f /bin/sh; ln -s /bin/bash /bin/sh;


echo " Get kernel compile tools"
apt-get update; apt-get install kernel-package libncurses5-dev fakeroot wget bzip2


echo "get kernel sources, untar the, and go to source directory"

cd /usr/src; wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.18.1.tar.bz2; tar xjf linux-2.6.18.1.tar.bz2; ln -s linux-2.6.18.1 linux; cd /usr/src/linux


echo "use working kernel config file, compile kernel"

cp /boot/config-`uname -r` ./.config; make-kpkg clean; fakeroot make-kpkg --initrd --append-to-version=-custom kernel_image kernel_headers


echo "install new kernel as a ackage"

cd /usr/src; ls -l; dpkg -i linux-image-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb; dpkg -i linux-headers-2.6.18.1-custom_2.6.18.1-custom-10.00.Custom_i386.deb


echo "Confirm new kernel availability in grub"

vi /boot/grub/menu.lst


echo "restart"

shutdown -r now


echo "confirm loaded kernel"

uname -r