Pagini
Workshops
Parteneri
Important
ssh student@spook.local
# Compile and boot Linux kernel
#* Check your current kernel version, and notice the target architecture # uname -a
# cat /proc/version
# cat /proc/cpuinfo
#* wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.10.tar.xz
#* tar xf linux-3.10.tar.xz
#* 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 # Note: the current linux version needs the 'bc' package that is not on the vm. Install it with sudo apt-get install bc
. # make -j3 bzImage
#* grab a coffee # make -j3 modules
#* Install kernel image # sudo cp arch/x86/boot/bzImage /boot/vmlinuz-3.10.0
# sudo cp .config /boot/config-3.10.0
# sudo cp System.map /boot/System.map-3.10.0
#* Install modules # sudo make modules_install
#* Build initial ramdisk # cd /boot ; sudo mkinitramfs -o initrd.img-3.10.0 3.10.0
#* Update grub and reboot the system # sudo update-grub
# reboot
#* Boot into the new image and check current kernel version # cat /proc/version
ifconfig
or ip a s
student@spook:~$ ethtool -i eth0 driver: pcnet32 version: 1.35 firmware-version: bus-info: 0000:00:11.0
pcnet32
into the kernelmake menuconfig
PCNET32
(use /PCNET32)Y
for AMD PCnet32 PCI support
bzImage
as explained above, and reboot.printk
inside the sources (e.g init/main.c:512
)printk("Hello World!\n");
dmesg | grep Hello
simple
module#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);
Makefile
and Kbuid
files.KDIR=/lib/modules/`uname -r`/build kbuild: make -C $(KDIR) M=`pwd` clean: make -C $(KDIR) M=`pwd` clean
EXTRA_CFLAGS = -g obj-m = simple.o
simple
kernel modulemake
sudo insmod simple.ko
dmesg | grep Hi
modinfo simple.ko
rmmod simple.ko
dmesg | tail
== Resources ==