Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 10 The Linux Kernel More Development Tools CSCI 156.

Similar presentations


Presentation on theme: "Week 10 The Linux Kernel More Development Tools CSCI 156."— Presentation transcript:

1 Week 10 The Linux Kernel More Development Tools CSCI 156

2 Types of Kernels Monolithic –One large executable does everything –Advantages: speed –Disadvantages: inflexible Microkernel –Small core, interacts with modules in user space. Almost everything done in modules –Advantages: highly modifiable –Disadvantages: typically slower

3 The Linux Kernel Hybrid! (best of both worlds) –Monolithic kernel with modular support –Modules are inserted into the running kernel thus, everything runs in kernel space –Keep the speed, add the flexibility Linux kernel can be built as purely monolithic –Disadvantages: huge, slows booting, hogs RAM –Advantages: some older hardware has problems with modules

4 Loading Modules Module loding utilities (must be root) –lsmod – list currently running modules –insmod – insert module into kernel (requires.o) –modprobe – smarter insmod: uses module name –rmmod – remove module from kernel Some modules loaded at startup –In Fedora 2 (these machines) /etc/modprobe.conf –Other systems /etc/modules.conf –(Redhat = Evil)

5 Writing a Module Big Learning Curve –Memory allocation is different in kernel-space –Allow for pre-emption Alternatives –Hijacking system calls to add/modify: #include pid_t getpid(void) { printf("w00t!\n"); return syscall(SYS_getpid); } root@newdell6a:~> gcc -Wall -fPIC -shared -o getpid.so getpid.c root@newdell6a:~> LD_PRELOAD=./getpid.so bash -c 'echo $$' To Run:

6 Building the Kernel Steps –Download the source to /usr/src/linux-version –configure the kernel make menuconfig –build the kernel make bzImage –build the kernel modules make modules && make modules_install How long does it take? –30 minutes w/kernel hacking disabled: 1.2MB –45 minutes w/kernel hacking enabled: 1.3MB

7 Installing the Kernel Bold replacement –cp arch/i386/boot/bzImage /boot/bzImage-version –what if the kernel fails to boot? Safety Net –cp arch/i386/boot/bzImage /boot/MYIMG-version Using the safety net: –How to specify which kernel to boot (old/new)?

8 GRUB Bootloader, configured with grub.conf –In the /boot/grub dir (or /etc/grub.conf) –Naming convention: /dev/hda2 -> (hd0,1) –Must specify title, root drive, kernel –Allows for dual-booting multiple Oss Even multiple versions of the same OS: tweak away! Other options –LILO: older boot-loader, fallen out of use –others for other hardware (non-i386) this room?

9 Switching Gears...Tools ctags –ctags -R recurse through all directories, find tags –while in vim: CTRL-] –jumps to function definition CTRL-T –jumps back to the caller gd –in command mode, go to local variable definition CTRL-N –in insert mode, complete the variable/method name

10 Method Folding In vim: –:set foldmethod=indent –:set foldlevel=0 –on a folded method: zO to expand/unfold –on an unfolded method: zC to close/fold


Download ppt "Week 10 The Linux Kernel More Development Tools CSCI 156."

Similar presentations


Ads by Google