Overview of Hardware and the Kernel

Kernel's role Kernel device drivers Two way to implement device driver Benefits of Kernel Dynamic Kernel Modules Modules Statically Compiled into Kernel Loadable Kernel modules are stored in /lib/modules/`uname -r`

To view the currently loaded modules

# lsmod
To manually load a module
# insmod /some/path/mymodule.o
You can pass parameters to loadable kernel modules
# insmod /some/path/mymodule.o io=0x300 irq=10
If a module is not being used you can remove it
# rmmod
A better way to load modules and check for dependencies
# modprobe mymodule
Can also be used to remove modules
# modprobe -r mymodule

This happens as part of the boot process from inside /etc/rc.d/rc.sysinit

To list all the modules in /lib/modules
# modprobe -l
To rebuild the dependency file in /lib/modules/`uname -r`/modules.dep
# depmod -a
How do system utilities such as fdisk, dumpe2fs, swapon, etc access devices?

In Unix everything is a file. Take a look inside the /dev directory

Utilities can access devices without knowing the driver's implementation details This command is used to create RedHat bootable floppy Characteristics of device nodes

The mknod command

   mknod Example

Virtual Block Devices

Filesystem Example
cd /mnt/foobar
touch a b c
ls -l
  • Umount the filesystem
  • cd ..
    umount /mnt/foobar
    System Bus Support Kernel Random Number Source Device
    man 4 random
    The random number generator gathers environmental noise
    from device drivers and other sources into an entropy pool.
    The generator also keeps an estimate of the number of bit
    of the noise in the entropy pool. From this entropy pool
    random numbers are created.
    Example /dev/random
    # tty
    /dev/pts/1

    cat /dev/random,  you will see lots of binary junk on your screen

    # cat /dev/random
     

  • Don't move your mouse or touch your keyboard
  • Now move your mouse
  • Wait...
  • Now type a key
  • Notice that more data in /dev/random is generated by this activity
  • Configuring and building a custom kernel

    ncurses-devel
    glibc-devel
    dev86
    cpp
    binutils
    gcc
    make
    glibc-kernheaders or kernel-headers
    kernel-source
    # rpm -q kernel-source
    Downloading the RedHat kernel source
  • Download the kernel source rpm from the Linux ftp server, gandalf.

  • # cd /tmp
    # ftp somehost.example.edu

    login: anonymous
    password is your login account and fully qualified hostname:
    root@stationX.example.edu

    ftp> cd pub/rh7.3
    ftp> cd Redhat/RPMS
    ftp> ls
    ftp> bin
    ftp> mget kernel-source

    ftp> quit
     
  • Install the rpm

  • # rpm -ivh kernel-source*

    1. Go to kernel directory and modify Makefile so your custom kernel will have a different name than the generic kernel
    cd /usr/src/linux-2.4
    vi Makefile
    modify the line that reads
    EXTRAVERSION=
    by appending the work custom (or whatever makes sense)
    2. Clean up any previous builds by removing old .o files and dependencies that might be lying around. Note, this will also remove any .config files in the directory
    make mrproper
    3. Use a config file that matches your processor type. This gives you a good baseline from which to begin tayloring to your kernel
    cp configs/kernel-*-i686.config .config
    4. To save time, configure based on the existing configuration by reading the ./.config file. Do this only if you have previously configured the kernel and have a .config file on hand.
    make oldconfig
    5. Use one of the available tools to refine the configuration further
    make xconfig -- X windows based config tool
    make config  -- the most criptic of the tools
    make menuconfig -- text based color menus
    6. Once the config file is created, propagate defined configuration to other kernel subdirectories
    make dep
    7. Compile the kernel
    make bzImage
    8. Compile the kernel modules (and take a coffee break :)
    make modules
    9. Install the kernel modules
    make modules_install
    10. Install the kernel files to appropriate directories under /boot
    make install

    Linux Boot Loader

    Grub
    cat /boot/grub/grub.conf

    default=1
    timeout=10
    splashimage=(hd0,2)/grub/splash.xpm.gz
    title Red Hat Linux (2.4.20custom)
            root (hd0,2)
            kernel /vmlinuz-2.4.20custom ro root=/dev/hda5
            initrd /initrd-2.4.20custom.img
    title Red Hat Linux (2.4.18-18.8.0)
            root (hd0,2)
            kernel /vmlinuz-2.4.18-18.8.0 ro root=LABEL=/
            initrd /initrd-2.4.18-18.8.0.img
    title DOS
            rootnoverify (hd0,0)
            chainloader +1
     

    Lilo

    cat /etc/lilo.conf.anaconda

    prompt
    timeout=50
    default=linux
    boot=/dev/hda
    map=/boot/map
    install=/boot/boot.b
    message=/boot/message
    linear

    image=/boot/vmlinuz-2.4.18-14
            label=linux
            initrd=/boot/initrd-2.4.18-14.img
            read-only
            append="root=LABEL=/"

    image=/boot/vmlinuz-2.4.17
            label=linux-old
            initrd=/boot/initrd-2.4.17.img
            read-only
            append="root=LABEL=/"

    other=/dev/hda1
            optional
            label=DOS

    Add the lines for the old kernel just in case the new one doesn't boot!
    ** Don't forget to run /sbin/lilo to write the new loading map