CSE451 13Sp Section 2 Notes
James Youngquist <jay@cs>
1
Linux Kernel
The following assumes you have your source unpacked in the directory LDIR.
1.1
Configuring / Compiling
The linux kernel as given does not
need to be configured. But it's fun to look through all the options available to you. To run the configuration tool,
$ cd LDIR
$ make menuconfig
If you're using Qemu, you NEED to change a couple of options from modules to built-in. Modules requied for boot are stored in an initial RAM based filesystem (
http://en.wikipedia.org/wiki/Initrd), which gives flexibility but adds unneeded complexity for our purposes. Thus, to run your kernel in Qemu, you must change the following options from modules to built-in:
which allows the kernel to boot without any external requirements.
Device Drivers
-> Network device support
-> Virtio network driver
-> Ethernet driver support
-> Intel PRO/1000*
File systems
-> Second extended fs support
-> Network File Systems
-> NFS client support
-> ALL suboptions
-> Root file system on NFS
-> NFS server support
-> ALL suboptions
Networking support
-> Networking options
-> IP: kernel level autoconfiguration
-> IP: DHCP support
-> IP: BOOTP support
-> IP: RARP support
After configuring, don't forget to run
$ make clean
$ make -j<# cores> bzImage
1.2
Relevant files
After you compile with make bzImage, several files are generated.
- LDIR/.config
-
This file is what make menuconfig changes. You can edit it directly if you like to change options.
- LDIR/vmlinux
-
An ELF “executable” that is the kernel. You can't actually run this, but you can examine it with objdump and readelf or load it into a GDB session.
- LDIR/arch/x86/boot/bzImage
-
The compressed kernel binary. This is the file you use to overwrite /boot/vmlinuz-3.8.3-201.cse451custom.fc18.x86_64
1.3
Introspection
The kernel provides several services that let you peak in on it's state.
1.3.1
printk
The simplest is using printk. Any messages sent using printk are displayed on the console and also stored in a kernel buffer so you can get to them later. The dmesg command will play back the kernel printk buffer. For example
$ dmesg
....tons of messages scroll past your screen
# Send the output of dmesg through the 'less' pager
$ dmesg | less
# Search for a specific string
$ dmesg | grep some_string
# Save the output of dmesg to peruse at your leisure
$ dmesg > output_file.txt
1.3.2
/proc
The /proc filesystem is a virtual file system that exports information primarily about processes. Each process has a pid (process ID), and a corresponding directory /proc/pid that lets you examine state information about the process. For example, I have a bash process running as process 8103,
# Show where the binary and shared libraries have been loaded into virtual memory
$ cat /proc/8103/maps
# Look at all the files it has open
$ ls -l /proc/8103/fd
# What limits have been placed on this process?
$ cat /proc/8103/limits
It's not inconceivably that you could export the execcount information here so it can be accessed by any language that can read a file, instead of being limited to the syscall interface.
1.3.3
/sys
The /sys filesystem is a virtual file system that exports information primarily about devices and drivers from the kernel. It also lets you change parameters for the kernel at run time, either to tune performance, or enable/disable features (like IP forwarding).
It's not as pertinent to the kind of things we're doing in this course, but you could imagine having a “file” that you can write a 0 or 1 to, to toggle execcount instrumentation on a kernel-wide basis.
1.3.4
/sys/kernel/debug