Pagini
Workshops
Parteneri
Important
ssh student@spook.local
# Compile and boot Linux kernel
#* wget kernel.org/pub/linux/kernel/v3.0/linux-3.4.4.tar.bz2
#* tar xjvf linux-3.4.4.tar.bz2
#* Check your current kernel version, and notice the target architecture # uname -a
# cat /proc/version
# cat /proc/cpuinfo
#* Create .config
file from i386_defconfig
and check the options enabled # make defconfig
#* Play around with make config
and notice available options # What are the file systems compiled in kernel? # Is IPv6 support enabled ? #* Build kernel image and modules # make -j3 bzImage
; make -j3 modules
#* Install kernel image # cp arch/x86/boot/bzImage /boot/vmlinuz-3.4.4
# cp .config /boot/config-3.4.4
# cp System.map /boot/System.map-3.4.4
#* Install modules # make modules_install
#* Build initial ramdisk # cd /boot ; sudo mkinitramfs -o initrd.img-3.4.4 3.4.4
#* Update grub and reboot the system # sudo update-grub
# reboot
#* Boot into the new image and check current kernel version # cat /proc/version
# Troubleshooting
#* Notice that we can no longer connect, via ssh, to the new booted Linux kernel image inside the virtual machine. # Check the output of ifconfig
or ip a s
# Conclusion: There is no driver installed for the network card #* Boot into the old working image and figure out the network card type #
student@spook:~$ ethtool -i eth0 driver: pcnet32 version: 1.35 firmware-version: bus-info: 0000:00:11.0
#* Compile support for pcnet32
into the kernel # make menuconfig
# Search for PCNET32
(use /PCNET32) # Select Y
for AMD PCnet32 PCI support
#* rebuild the bzImage
as explained above, and reboot. # Say hello from the kernel
#* Add a printk
inside the sources (e.g init/main.c:512
) #
printk("Hello World!\n");
#* Recompile the image and reboot #* Check for the printk message # dmesg | grep Hello
# Simple kernel module
#* Analyze the source code for our simple
module #* <code c simple.c>#include <linux/kernel.h> #include <linux/init.h> #include <linux/module.h> MODULE_DESCRIPTION(“My kernel module”); MODULE_AUTHOR(“Me”); MODULE_LICENSE(“GPL”); static int simple_init(void) { printk( KERN_DEBUG “Hi\n” ); return 0; }
static void simple_exit(void) { printk( KERN_DEBUG “Bye\n” ); }
module_init(simple_init); module_exit(simple_exit);</code> #* For compiling this module we need Makefile
and Kbuid
files. #* <code c Makefile>KDIR=/lib/modules/`uname -r`/build kbuild: make -C $(KDIR) M=`pwd` clean: make -C $(KDIR) M=`pwd` clean</code> #* <code make Kbuild>EXTRA_CFLAGS = -g obj-m = simple.o</code> #* Compile simple
kernel module # make
#* Insert it into the kernel # sudo insmod simple.ko
#* Check if module works # dmesg | grep Hi
# modinfo simple.ko
# rmmod simple.ko
#** dmesg | tail