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

BOOT

System run-levels

  • Run levels

    A linux system can be booted into one of a number of runlevels. These runlevels, primarily, determine the services that will be provided.

    Level Function
    0 Halt the system - very quickly - a transitional device
    1, s, S Single-user-mode sometimes called maintenance mode. Network and other system services not started. Used for interactive filesystem maintenance
    2 Multi-user-mode. On Debian this is the default, RedHat default is multi-user without NFS
    3 Full multi-user-mode (RedHat). Not used on Debian
    4 Typically unused
    5 Full multi-user-mode with GUI login (RedHat) i.e. runlevel 3 plus X11
    6 Reboot - very quickly - a transitional device

    A default run level is defined in /etc/inittab. 'init' reads /etc/inittab for a line containing 'initdefault' and then runs all scripts in the corresponding /etc/rc.d/ directory.

    Configuring the default runlevel - /etc/inittab

    id:n:initdefault:                                # Where 'n' is a valid runlevel number
    
    Configure Ubuntu's default run level

    Ubuntu by default, does not come with a /etc/inittab file. It's default runlevel is = 2.

    If you wish to alter this default the easiest way is to create a /etc/inittab file. Ubuntu uses '/etc/event.d/rc-default' script to first check if an inittab file exists, if so its uses the default setting there, if not it will use 2.

    You could just modify the 'rc-default' script to use a different runlevel however there is little point as

    - it already caters for /etc/inittab if it exists
    - any changes will get overwritten if this script is updated
    - it's messy
  • Display system runlevel
    /sbin/runlevel

    Output previous and current runlevel

    runlevel [option]... [utmp]
    
    Options:
     --set=Runlevel             Runlevel should be one of 0123456S.
     --reboot                         Store a record of the time the system was booted in the utmp file.
    

    Display previous and current runlevel

    # /sbin/runlevel
    N 5                                      (Previous runlevel, current runlevel)
    

    If previous value=N, then no change since last boot, 5 is the current session runlevel.

  • The init process

    When the kernel finishes loading, it usually starts '/sbin/init'.

    '/sbin/init'

    • boots the rest of the system by running a series of scripts
    • it remains running until the system is shut down
    • it is always assigned process ID=1.

    The location of the scripts varies (one reason behind Linux FSH). On Ubuntu/Debian they are in /etc/rcN.d/ directories where N is the runlevel. These directories contain symbolic links to start scripts in /etc/init.d/.

    Other distributions may have the rc directories named differently or have init.d located elsewhere.

    • init.d directory, however, contains the actual scripts
    • _rc directories contain symlinks to the scripts

    Startup or rc scripts perform services such as setting the system's hostname, checking the filesystem for errors, mounting additional filesystems, enabling networking, starting print services and so on.

    The file /etc/rc.local or /etc/init.d/rc.local is usually used for customising some aspect of the startup process.

    'init' startup files:

    File Name Purpose
    /etc/rc.sysinit (RedHat)monolithic script run by init at boot time - runs essential tasks to prepare system for use
    /etc/init.d/rcS (Debian)same as above but uses a number of smaller scripts to achieve the same result
    /etc/rc.local Called after all other init scripts. Local customisation - not overwritten when upgraded
    /etc/rc Used to change between runlevels
    /etc/init.d/ Starting/Stopping Services via files/symlinks in the directory. Scripts take a standard form - valid args include, at least, stop, start and may include restart, status, reload. Scripts are not run directly by 'init' but via symlinks in the rc.d directories
    /etc/rc0.d - rc6.d One per runlevel. init runs all scripts in the /etc/rcn.d dir that corresponds to its runlevel. Each script is of the form [K|S]NNname where K=kill, S=start, NN=two digit number specifying the relative order in which to run, the lowest is the first, highest is the last and name=name of script being linked

    Sample level 5 entries - /etc/rc5.d/

    lrwxrwxrwx  1 root root   18 2007-11-08 23:53 K89netplugd -> ../init.d/netplugd
    lrwxrwxrwx  1 root root   15 2007-11-08 23:51 K89rdisc -> ../init.d/rdisc
    lrwxrwxrwx  1 root root   25 2007-11-08 23:56 S04readahead_early -> ../init.d/readahead_early
    lrwxrwxrwx  1 root root   15 2007-11-08 23:58 S05kudzu -> ../init.d/kudzu
    .....
    

    When the scripts complete, 'init' starts a program called 'getty' which displays the login prompt on consoles.

  • Change system runlevel
    /sbin/init, telinit

    Change to another runlevel

    init [0123456Ss]
    
    telinit [-t sec] [0123456sSQqabcUu]
    
    Some options:
      0,1,2,3,4,5 or 6             Switch to the specified run level
      S or s                       Switch to single user mode
    
  • The /etc/inittab file

    The inittab file describes which processes are started at bootup and during normal operation.

    Format - [name]:[runlevel]:[action]:[script]

    Configuration line name (1-4 chars in recent versions of init,1-2 in ancient ones)
    :
    runlevel - 0, 1, s, S, 2, 3, 4, 5, 6
    :
    action     Some actions are "special" e.g. :ctrlaltdel:,  most relate to spawning. 
    
      respawn       process is restarted whenever it terminates.
      wait          process is started once when the specified  runlevel is entered, init will wait for its termination.
      once          process is executed once when the specified runlevel is entered.
      boot          process is executed during system boot (but after sysinit). The runlevels field is ignored.
    :                       
    Process, script to run.
    

    Runlevel-neutral system initialisation

    # /etc/inittab - actions are performed by entries like:
    
    # System initialisation.
    si::sysinit:/etc/rc.d/rc.sysinit (Red HAT)     # A monolithic script that performs all the initialisation.
    si::sysinit:/etc/init.d/rcS      (Debian)      # A script that runs each of the scripts matching '/etc/rcS.d/[Ss]??*'
    

    Runlevel-specific system initialisation

    # /etc/inittab - actions are performed by entries like:
    
    l0:0:wait:/etc/rc.d/rc 0
    l1:0:wait:/etc/rc.d/rc 1
    l2:0:wait:/etc/rc.d/rc 2
    l3:0:wait:/etc/rc.d/rc 3
    l4:0:wait:/etc/rc.d/rc 4
    l5:5:wait:/etc/rc.d/rc 5
    l6:6:wait:/etc/rc.d/rc 6
    
    • '/etc/rc.d/rc' will run all the files matched by the pattern '/etc/rc$1.d/[KkSs]??*'
    • K or k are kill scripts that end processes or clean up their actions.
    • S or s are startup scripts, launch new processes or configure the system to run at that runlevel.

    Most of these files will be shell scripts, most will be links (often to files in /etc/init.d/).

    Additional '/etc/inittab' commands and options

    # Trap CTRL-ALT-DELETE
    ca::ctrlaltdel:/sbin/shutdown -t3 -r now
    
    # What to do if power fails - assumes working UPS
    pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
    
    # If power was restored before the shutdown kicked in, cancel it.
    pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
    
  • Configure the login process
    /etc/inittab

    'getty' ('agetty', 'mgetty' or 'mingetty') runs to handle the login process.

    Configure a login process in '/etc/inittab'

    # Run gettys in standard runlevels
    1:2345:respawn:/sbin/mingetty tty1
    2:2345:respawn:/sbin/mingetty tty2
    3:2345:respawn:/sbin/mingetty tty3
    4:2345:respawn:/sbin/mingetty tty4
    5:2345:respawn:/sbin/mingetty tty5
    6:2345:respawn:/sbin/mingetty tty6
    
    Field Function
    First number determines the virtual terminal where the getty runs.
    Next set of numbers determine which runlevels the command should be run in.
    Action - respawn restart the process whenever it terminates
    Script or program handles the login process
    ttyn the number of the virtual console
  • Configure launch of additional services
    /etc/inittab

    Such as a display manager for logging into a graphical environment.

    Configure xdm startup in '/etc/inittab'

    # Run xdm in runlevel 5
    x:5:respawn:/etc/X11/prefdm -nodaemon