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

Customising

  • Ubuntu links
  • Kernel configuration options

    Customising involves enabling/disabling existing features via configuration options in the '.config' file and choosing whether or not to implement drivers as kernel modules or build them in to the kernel.

    • Building a driver into the kernel will increase the kernels size but can improve performance. The converse applies if built as a module.
    • If a driver is built as a module and it is required during boot then an initial ramdisk is required.

    Any change to the '.config' file will require recompilation and install.

    An idea of the options available with a Ubuntu generic kernel

    $ grep CONFIG .config | wc -l
    3688                                     (Total number of configurable kernel options)
    
    $ grep  '^# CONFIG' .config | wc -l
    487                                      (The number of options not set/disabled)
    
    $ grep  '^CONFIG' .config | wc -l
    3201                                     (The number of options set/enabled)
    
    $ grep  '=m' .config | wc -l
    2005                                     (The number of 'drivers' configured as modules)
    
    $ grep  '=y' .config | wc -l
    1102                                     (The number of 'drivers' built into the kernel)
    

    /usr/src/linux-headers-2.6.28-18-generic/.config

    And today'ish

    /boot$ grep CONFIG config-3.8.0-33-generic | wc -l
    5922
    

    One of the main reasons to customise a kernel maybe to optimise it for the system that it is going to be run on. A generic kernel, as in this instance, provides built in support for many devices and features that are either not installed or not required by this system - very much like Windows, however unlike Windows you can do something about it.

    A customised kernel will provide enhanced performance but requires a thorough understanding of all the hardware requirements and many of the configurable options. Further more, any changes to the system's build (hardware and software) and or its usage may well require reconfiguring and recompiling the kernel.

    When patches are applied new features may become available (often the case with new versions). These may provide new support or enhancements to existing features. In such cases it is necessary to identify userspace requirements (packages and or patches), meet them, enable the features and recompile the kernel.

  • Shadow directory of an existing kernel source tree

    *** Removing files within a shadow directory is a real pain (an understatement) - so up to you if you want to bother with this.

    • If you have an existing source tree you can create a shadow directory. All files contained in the shadow directory are symbolic links to the source directory (fromdir).
    • Files created in the shadow directory during compilation are just that. All object files are therefore kept separate from the source files.

    Create a shadow directory of symbolic links - /usr/bin/lndir

    Creates a shadow directory of symbolic links to another directory tree. Updating symlinks to newly added files just requires reruning 'lndir'.

    lndir [options] fromdir [todir]
    

    Part of lubuntu xutils-dev package so may not be installed.

  • Configuring the kernel

    Done via '.config' file in the source's top level directory.

    Edit kernel configuration options

    ~/linux/linux-2.6.29$ make menuconfig
    

    If no '.config' file in source directory a default one is loaded for editing. You can copy an existing one to the source directory and it will be loaded for editing. Alternatively you can load an alternative '.config' file from within the editing menu.

    Major configuration sections - 2.6 kernel

    Sections:
     Code maturity level options            Provides an option to include experimental code. Not selecting
                                            will only allow subsequent selections for stable code. 
     General setup                          Option to provide an identification string for new kernel plus
                                            other options. 
     Loadable module support                Option to enable automatic loading and unloading of modules. 
     Block layer                            Options for > 2TB disk support and disk scheduling support. 
     Processor type and features            CPU specific config. Enable SMP if more than 1 CPU or have a 
                                            hyperthreaded CPU. Enable MTRR for better graphics performance
                                            with AGP or PCI. 
     Power management                       Particularly useful for laptops (acpi or apm). 
     Bus                                    PCI, PCI express and PC card bus options, can also enable 
                                            /proc/pci fs tho' should use lspci instead.
     Executable file formats/emulation      Should enable ELF binary support, enable DOS (DOSEMU) support, 
                                            wrapper-driven binaries such as Java, Python, Emacs-Lisp and 
                                            32-bit emulation to run 32-bit progs if on a 64-bit system. 
     Networking                             Various protocols, infra-red, wireless support options. 
     Device drivers                         Enable support for IDE/ATAPI/SATA or SCSI. DMA (else IDE will
                                            work in slower PIO), RAID, LVM, Parallel Printer support, Audio
                                            and Video support for USB and Firewire (IEEE1384) Also under 
                                            character devices subsection probably want parallel printer and
                                            direct rendering support. 
     Firmware drivers                       Options related to BIOS setting and updating. 
     File systems                           ext2, ext3, networked fs, reiser, jfs, SAMBA, floppy, CD, DVD
                                            ... Partition and Native Language support. 
     Instrumentation                        Experimental profiling. 
     Kernel hacking                         Enable debugging and which features. 
     Security                               Enable and configure SELinux (Security Enhanced Linux). 
     Cryptographic                          Configure several cryptographic algorithms e.g. DES, MD4, SHA256 
     Library routines                       Choice of CRC routines.
    

    Definitely dated

  • Edit the Makefile

    This is in the top of the source directory tree and is edited to reflect that this is a customised version.

    Set versioning info for custom kernel - Makefile

    VERSION = 2
    PATCHLEVEL = 6
    SUBLEVEL = 29
    EXTRAVERSION = .1-mycust
    .....
    

    This can also be done via the 'LOCALVERSION' option when running 'make menuconfig' (or other config type) - this appends the provided version to kernel release parameter in the '.config' file.

  • Specifing compiled output file location

    When compiling the kernel all output files will by default be stored together with the kernel source code. Using the option 'make O=output/dir' allows you to specify an alternate place for the output files (including the .config).

    If this option is used it MUST be used for all invocations of 'make'. Alternatively you can could use 'lndir'.

    Doing so keeps the source and built 'trees' separate - easier to work with in the event of compilation problems.

    Store output files in alternative location

    kernel source code:    /usr/src/linux-2.6.N
    Build directory:       /home/name/build/kernel
    
    $ cd /usr/src/linux-2.6.N
    $ make O=/home/name/build/kernel menuconfig
    $ make O=/home/name/build/kernel
    $ sudo make O=/home/name/build/kernel modules_install install
    

    MUST use 'O=....' for all invocations of 'make'.

  • GNU 'make' utility

    GNU make utility to maintain groups of programs - /usr/bin/make

    'make' uses the Makefile to determine the order in which targets have to be made and the correct sequence of rules to invoke.

    make [ -f makefile ] [ options ] [ targets ... ]
    
    Commonly used options:
     -f <filename>                                Use an alternative makefile in current
                                                  directory.
     -k                                           Keep going when an error is found else 
                                                  stops at first error.
     -i | --ignore-errors                         Ignore errors in all commands executed to 
                                                  remake files.
     -j <int> | --jobs=<int>                      Number of jobs/processes to run.
     -n | --dry-run | --just-print | --recon      Print commands to be executed but do not 
                                                  run them.
     -s | --silent | --quiet                      Do not print commands as they are executed.
     -p | --print-data-base                       Print built in rules.
    
  • The Makefile

    The Makefile contains a set of dependencies and rules. Comments start with #.

    A dependency

    Has a target - the file to be created and a set of source files upon which its creation depends.

    A Rule

    Describes how to make the file/target from the dependencies

    Makefile format

    <target>:<whitespace><whitespace separated list of files/dependencies> where <whitespace> can be one or more spaces or tabs.

    Basic Makefile dependency example

    Dependencies define what files are needed to create the target.

    my-app:    main.o file1.o file2.o                # my-app depends on these three files
    
    main.o:    main.c headera.h                      # main.o depends on these two files
    file1.o:        file1.c headera.h headerb.h      # and so ....
    file2.o:        file2.c headerb.h headerc.h
    

    To make the program 'my-app' (the target) we need three object files - main.o file1.o file2.o.

    To make each of the object files (also targets) we need the source and header files listed.

    If an application requires the making of several files e.g. 'my-app' and 'my-man-pages' then use the phony target all. If all is not specified as the target 'make' will only make the first target it finds in the Makefile.

    Use of phony target in Makefile

    all:     my-app my-man-pages
    .....
    

    Basic Makefile rule and dependency example

    my-app:    main.o file1.o file2.o                # a dependency
        gcc -o my-app  main.o file1.o file2.o        # a rule
    
    main.o:    main.c headera.h
        gcc -c main.c
    file1.o:        file1.c headera.h headerb.h
        gcc -c file1.c
    file2.o:        file2.c headerb.h headerc.h
        gcc -c file2.c
    

    ALL rules must be on lines that start with a TAB. They tell make how to make the target.

  • Dependencies, rules and macros
    a Makefile example
    • Macros can be used in the Makefile by stipulating MACRONAME=value.
    • Macros are accessed/referenced by $(MACRONAME) or ${MACRONAME}. Some versions of make allow $MACRONAME.

    Example Makefile

    all:    my-app                                   # A dependency with phony target
    
    # Which compiler to use
    CC=gcc                                           # A macro, can override by using 'make CC=c89'
    
    # Default location include files
    INCLUDE=.                                        # Override by using 'make INCLUDE=/home/mark/include'
    
    # Options for development
    CFLAGS=-g -Wall -ansi                            # Override by using 'make CFLAGS=-O -Wall -ansi'
    
    # Options for release
    # CFLAGS= -O -Wall -ansi
    
    my-app:    main.o file1.o file2.o                # A dependency and target
        $(CC) -o my-app  main.o file1.o file2.o      # A rule using a macro
    
    main.o:    main.c headera.h
        $(CC) -I$(INCLUDE) $(CFLAGS) -c main.c       # A rule using macros
    file1.o: file1.c headera.h headerb.h
        $(CC) -I$(INCLUDE) $(CFLAGS) -c file1.c
    file2.o: file2.c headerb.h headerc.h
        $(CC) -I$(INCLUDE) $(CFLAGS) -c file2.c