Did anybody start project 1? Kernel Modules! LKM, part 2 (actually writing a module) Utilities: insmod rmmod depmod lsmod modinfo modprobe Inserting Modules: insmod or modprobe Unresolved symbols: - Symbols are exported from the kernel OR MODULES - Dependencies among modules - /proc/kallsyms - Use count remove with rmmod or modprobe -r Could not find kernel version - Descriptive error messages are sometimes lacking How do you tell if it worked? - Depends on the module - lsmod will tell you if it's there Automatic Loading - Do you really want this? Maybe...probably not - unload after 1min with autoclean Where are LKMs found? - Usually /lib/modules Versions: Kernel version must match module version - Memory layout, kernel subroutines, etc - Did anything important really change? insmod -f - Symbol versioning - gcc versions - What about multiple kernels? + People do that sometimes... - Symbol licensing errors and viral GPL Boot without device drivers? - This is complicated and probably not a good idea - Loader can load stuff into RAM before kernel starts - Still need to understand FS and run programs How insmod works: init_module system call init_module subroutine in module - Linking is done at insertion time Debugging is possible with kdb Memory: Linux kernel is not pageable - virtual addresses = real addresses Modules can't be paged either, but virtual addresses != real addresses - kmalloc Demo: blink.c /proc filesystem: Demo adding something crypto.c Let's make read pedantic