Top

A Linux User Reference

Search tips
  • search ignores words that are less than 4 characters in length
  • searches are case insensitve
  • if a search does not return anything try it in Boolean mode then Query expansion mode by checking the appropriate radio button e.g. searching for 'cron' in just the Administration category returns nothing - presumably because the 50% threshold is reached. Boolean mode ignores this threshold so a search for 'cron' returns several hits
  • in Boolean mode preceding a word with a '+' means the result must include that word, a '-' means it must not
  • in Boolean mode '+crontab -anacron' means match articles about crontab that DO NOT mention anacron
  • to match a phrase e.g. 'manage system' check the Boolean mode radio button and enclose the phrase in quotes "some phrase ..."
  • in Query expansion mode the search context is expanded beyond the keywords you entered - relevancy of hits may well be degraded

KERNEL

Components

  • Basic overview
    • the kernel source comes in two sizes, or used to - small or larger.
    • the build and install process generates some additional files that are required for a linux system to run
    File Description
    zImage Small image limited to about 508 KB.
    bzImage Larger kernels (up to about 2.5 MB), generally modern Linux.
    /vmlinuz Base kernel is often renamed as vmlinuz. '/vmlinuz' is often a link to a version named file .... 'vmlinuz' -> 'boot/vmlinuz-2.6.28-18-generic'
    /boot/System.map A table showing the addresses for kernel symbols.
    /boot/initrd.img Used by the base kernel to create a file system in a ramdisk prior to mounting the full file system.
  • Kernel source

    Varies but 'always' under /usr/src/. Earlier implementations placed kernel source under /usr/src/linux, often with linux being a link to the source.

    Fedora, as in the example below, use /usr/src/kernels/. Some distributions supply just the header files unless the full source package is installed (Debian, Ubuntu)

    Fedora kernel source directory tree - /usr/src/kernels/2.6.23.8-34.fc7-x86_64

    drwxr-xr-x 27 root root    4096 2007-12-08 15:18 arch
    drwxr-xr-x  2 root root    4096 2007-12-08 15:18 block
    -rw-r--r--  1 root root   70872 2007-11-23 01:58 .config
    -rw-r--r--  1 root root   70872 2007-11-23 01:58 .config-default
    .....
    drwxr-xr-x  4 root root    4096 2007-12-08 15:18 security
    drwxr-xr-x 19 root root    4096 2007-12-08 15:18 sound
    -rw-r--r--  1 root root 1054075 2007-11-23 01:58 System.map
    drwxr-xr-x  2 root root    4096 2007-12-08 15:18 usr
    
  • Kernel runtime information
    • the special directory /proc/ contains pseudo-files and subdirectories with a wealth of information about the running system.
    • each process that is created creates its own numeric subdirectory with several status files.
    • the contents of /proc/sys/kernel are useful for understanding the status of the running kernel.

    Kernel status files

    # ls /proc/sys/kernel/
    acct       domainname       msgmni          printk        
    shmall     threads-max      cad_pid         hostname
    shmmax     version          cap-bound       hotplug       
    ostype     real-root-dev    shmmni          core_pattern
    swsusp     core_uses_pid    msgmax          overflowuid
    rtsig-nr   sysrq            ctrl-alt-del    msgmnb
    tainted    rtsig-max        random/         overflowgid   
    sem        osrelease        modprobe        panic
    
    # cat /proc/sys/kernel/ostype
    Linux
    
    # cat /proc/sys/kernel/threads-max
    4095
    

    The contents of this directory will vary (quite a bit) depending upon the distribution and kernel version.

    Information on the current 'bash' process

    # ps
    PID TTY          TIME CMD
    16961 pts/2    00:00:00 bash
    17239 pts/2    00:00:00 ps
    
    # ls /proc/16961
    binfmt   cwd@     exe@    maps   mounts  stat   status
    cmdline  environ  fd/     mem    root@   statm
    
    # head -12 /proc/17268/status
    Name:   bash
    State: S (sleeping)
    Tgid:   17268
    Pid:    17268
    PPid:   17266
    TracerPid:  0
    Uid:    0   0   0   0
    Gid:    0   0   0   0
    FDSize: 256
    Groups: 0
    VmSize: 2640 kB
    VmLck:  0 kB
    
  • Kernel modules
    • modules contain extra kernel code that may be loaded after the base kernel.
    • modules provide additional functions to those provided by the the base kernel.

    Typical module functions include:

    Device drivers

    Support a specific type of hardware

    File system drivers

    Provide the optional capability to read and/or write a particular file system

    System calls

    Most are supported in the base kernel, but kernel modules can add or modify system services

    Network drivers

    Implement a particular network protocol

    Executable loaders

    Parse and load additional executable formats

    Some module tools

    modinfo        Show information about a module
    insmod         Insert a module
    rmmod          Remove a module
    modprobe       Insert, remove and load module dependencies
    lsmod          List loaded modules
    

    List the first three loaded modules

    $ lsmod | head -4
    Module                  Size  Used by
    ipt_MASQUERADE          4608  1
    xt_tcpudp               4096  13
    ipt_LOG                 7296  8
    
    $ head -3 /proc/modules
    ipt_MASQUERADE 4608 1 - Live 0xe0fb6000
    xt_tcpudp 4096 13 - Live 0xe0f82000
    ipt_LOG 7296 8 - Live 0xe0f75000
    

    'lsmod' puts a header on the display of the raw contents of '/proc/modules'

    Dry run with modprobe

    # modprobe [-i|-r] -n -v module_name     
    

    Display what the command would do, but not do it.

  • Kernel module loader

    /sbin/modprobe

    Automatically load modules. In older Linux versions there was 'kerneld' or 'kmod'.

    # echo "/sbin/modprobe" > /proc/sys/kernel/modprobe
    

    Sets 'modprobe' path in '/proc'

    'kmod' - a replacement for kerneld (dated)

    • consists of a request_module() replacement and a kernel thread called 'kmod'.
    • when the kernel requests a module 'kmod' wakes up and execve()s 'modprobe' passing it the name of the requested module.
    • 'kmod' only loads modules.
  • Kernel modules
    auto-cleaning (dated)

    Is mostly only an issue for memory-constrained systems, such as embedded Linux systems. Normally not really necessary as kernel modules do not use much memory especially when compared to userspace programs.

    Kernel Support for module unloading will not necessarily be enabled. Depends on distribution and build. Some highly critical systems may disable module loading and unloading during runtime - stops the system being messed with.

    Load modules so that they are unloadable - /sbin/insmod

    # insmod --autoclean    
    

    Or '-a', marks modules as unloadable if they are not currently used.

    To unload using older kerneld/kmod - /sbin/rmmod

    # rmmod --all        
    

    Or '-a', periodically to remove unused kernel modules or use crontab entry.

    root's crontab with something like

    0-59/5 * * * * /sbin/rmmod -a
    

    NB.

    '-a', '--autoclean' options no longer valid for either command (2013) - auto-cleaning handled 'auto magically'.

  • Controlling Kernel modules
    • achieved via /etc/modprobe.conf (formerly modules.conf <= 2.4) or by a per module basis as for ubuntu /etc/modeprobe.d/.conf.
    • some distributions use the file /etc/modules to hold a list of modules that are to be loaded at boot.
    Module aliases

    Modules can have aliases however aliases cannot have aliases. This allows an alternate name to be used for the module.

    Aliases can have options. Options are added every time the module is inserted into the kernel. All options are added together.

    Example module alias entry - /etc/modprobe.conf

    # Format: alias <wildcard> <modulename>
    alias my-mod long_modulename         # can use 'modprobe my-mod' for 'modprobe long_modulename'
    alias my-mod* long_modulename        # can use 'modprobe my-mod-something' for modprobe long_modulename'
    
    Module options

    Allow configuration of modules

    Ubuntu example/etc/modprobe.d/alsa-base.conf

    # autoloader aliases
    install sound-slot-0 /sbin/modprobe snd-card-0
    install sound-slot-1 /sbin/modprobe snd-card-1
    .....
    
    # Cause optional modules to be loaded above generic modules
    install snd /sbin/modprobe --ignore-install snd $CMDLINE_OPTS && \
    { /sbin/modprobe --quiet --use-blacklist snd-ioctl32 ;           \
     /sbin/modprobe --quiet --use-blacklist snd-seq ; }
    .....
    
    # Prevent abnormal drivers from grabbing index 0
    options bt87x index=-2
    .....
    # Keep snd-pcsp from being loaded as first soundcard
    options snd-pcsp index=-2
    # Keep snd-usb-audio from beeing loaded as first soundcard
    options snd-usb-audio index=-2
    

    Other module control keywords include

    install <modulename> <cmd> ...      # Run cmd(s) instead of inserting the module
    remove <modulename> <cmd> ...       # Run cmd(s) instead of removing the module 
    include <filename>                  # Include other configuration files or whole directories
    blacklist <modulename>
    

    'cmd(s)' can be any shell command.

    /etc/modprobe.d/blacklist-modem.conf

    # Uncomment these entries in order to blacklist unwanted modem drivers
    blacklist snd-atiixp-modem
    # blacklist snd-intel8x0m
    blacklist snd-via82xx-modem
    

    /etc/modprobe.d/iwlwifi.conf

    # iwlwifi will dyamically load either iwldvm or iwlmvm depending on the
    # microcode file installed on the system.  When removing iwlwifi, first
    # remove the iwl?vm module and then iwlwifi.
    remove iwlwifi (/sbin/lsmod | grep -o -e ^iwlmvm -e ^iwldvm -e ^iwlwifi | xargs /sbin/rmmod) \
    && /sbin/modprobe -r mac80211
    
  • Module dependencies
    • Modules can provide symbols.
    • Symbols, in part, reference functions within the module which other modules can use.
    • If a module uses a symbol exported by another module it then has a dependency on the exporting module.

    Create list of module dependencies - /sbin/depmod

    Creates a list of module dependencies by reading each module under /lib/modules/ and determining what symbols it exports and what symbols it needs.

    By default this list is written to modules.dep in the same directory. This file must be kept current for 'modprobe' to work correctly.

    Run at each boot usually by calling 'depmod -a' from 'rc.sysinit' or similar 'init' script.

    $ depmod --help
    Usage:
        depmod -[aA] [options] [forced_version]
    
    If no arguments (except options) are given, "depmod -a" is assumed
    
    depmod will output a dependency list suitable for the modprobe utility.
    
    Options:
        -a, --all            Probe all modules
        -A, --quick          Only does the work if there's a new module
        -e, --errsyms        Report not supplied symbols
        -n, --show           Write the dependency file on stdout only
        -P, --symbol-prefix  Architecture symbol prefix
        -C, --config=PATH    Read configuration from PATH
        -v, --verbose        Enable verbose mode
        -w, --warn           Warn on duplicates
        -V, --version        show version
        -h, --help           show this help
    
    The following options are useful for people managing distributions:
        -b, --basedir=DIR    Use an image of a module tree.
        -F, --filesyms=FILE  Use the file instead of the
                             current kernel symbols.
        -E, --symvers=FILE   Use Module.symvers file to check
                             symbol versions.
    

    Sample extract of modules.dep

    .....
    /lib/modules/2.6.23.1-21.fc7/kernel/sound/ac97_bus.ko:
    /lib/modules/2.6.23.1-21.fc7/kernel/sound/soundcore.ko:
    /lib/modules/2.6.23.1-21.fc7/kernel/sound/isa/sb/snd-sb16-dsp.ko: \
      /lib/modules/2.6.23.1-21.fc7/kernel/sound/isa/sb/snd-sb-common.ko \
      /lib/modules/2.6.23.1-21.fc7/kernel/sound/core/snd-pcm.ko
    .....
    /lib/modules/2.6.23.1-21.fc7/kernel/sound/isa/sb/snd-sb-common.ko: \
    /lib/modules/2.6.23.1-21.fc7/kernel/sound/core/snd.ko \
      /lib/modules/2.6.23.1-21.fc7/kernel/sound/soundcore.ko
    .....