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

Boot loaders

  • Linux boot managers

    A boot loader/manager's primary role is to locate, load and start a selected kernel. They allow for kernel selection and passing of user params to the kernel.

    There are two in general use on linux:

    LILO (LInux Loader)

    default kernel parameters in /etc/lilo.conf

    GRUB (GRand Unified Bootloader)

    default kernel parameters in /boot/grub/grub.conf or /boot/grub/menu.lst

    Distributions may vary in the way these are implemented.

    LILO requires the lilo command to be run after any changes to it's configuration file, GRUB does not. GRUB may need to be reinstalled if the partition table is altered.

  • Boot loader
    LILO

    A two stage boot loader

    • The first stage is loaded and run by the BIOS, the second stage is
    • A map installer utility - the lilo interactive command

    Example lilo configuration - /etc/lilo.conf

    boot=/dev/sda                      # Name of disk to boot from, install itself onto
    map=/boot/map                      # Location of map file
    install=/boot/boot.b               # Use this file as new boot sector, contains
                                       # bootstrap code
    compact                            # Allows lilo faster access to disk, may need
                                       # to remove on old disks
    prompt                             # Boot loader will prompt user, or use 
                                       # 'Shift & CTRl or ALT'
    timeout=30                         # Waits (0.1sec) for user input before continuing
    default=linux                      # Set image/OS with this label as the default
    message="Hi"                       # Optional message to display before the LILO 
                                       # prompt, less than 64KB
    #message=/boot/message2            # Message parameter may refer to a text file or a
                                       # specially created file in PCX format. If no message
                                       # parameter then a terse prompt is displayed - LILO:
    lba32                              # Optional - lba32 instead of Linear Sector addressing
    password="cleartxt"                # Optional - password required to boot.  Clear text
    restricted                         # Optional - password required when passing parameters
                                       # to kernel
    image=/vmlinuz-2.6.24-23           # Default image to load. (/boot is a separate partition)
       label=linux                     # Label displayed to user
       alias=shrike                    # Optional alias
       initrd=/initrd.img-2.6.24-23    # Optional - ram disk. (/boot is a separate partition)
       root=/dev/sda2                  # Partition that contains the linux image to boot
       read-only                       # Mount root filesystem as read-only, is changed later
       append="vga=0x317"              # Optional parameters to pass to kernel
    other=/dev/sda1                    # Like 'image' but refers to partition of non-linux OS
       label=win2k                     # Label to display in OS selection screen
    
  • LILO interactive command
    /usr/sbin/lilo
    lilo [options]
    
    Common options:
     -q                Query current config
     -u                Uninstall and restore previous boot record
     -C                use specified config file
    

    Install LILO

    # lilo
    

    LILO will install itself to wherever the 'boot=' directive in '/etc/lilo.conf' points to.

    lilo.conf boot directive examples

    boot=/dev/fd0     (LILO will be installed to the diskette in floppy drive fd0)
    boot=/dev/hda     (LILO will be installed into the MBR of the first ide disk drive)
    boot=/dev/sda     (LILO will be installed into the MBR of the first scsi disk drive)
    
  • Boot loader
    GRUB

    A three stage boot loader, Stages 1, 1.5 and 2. It consists of a text based configuration file, usually /boot/grub/menu.lst. This file may well be a symlink to /boot/grub/grub.conf.

    • Provides a menu interface instead of LILO's prompt
    • It can use a password encrypted with the MD5 algorithm as opposed to the plain text password of LILO
    • Changes made to the GRUB configuration file do not require GRUB to be reinstalled.
    • Does not require a partition to be mounted in order to configure a boot entry for it.
    • If you want a different background image for GRUB, you are limited to 14 colours.
    • The grub interactive command behaves as a small shell. It provides several commands that allow you to do things such as edit the commands before they are executed, find and load a configuration file, display files using the cat command ...
  • GRUB device naming
    Format Meaning
    (fd0) First floppy
    (fd1) Second and so on ...
    (hd0) First disk
    (hd1) Second and so on ...
    (hd0,3) Fourth partition on first disk
    (hd2,1) Second partition on third disk
  • Example grub configuration
    /boot/grub/menu.lst
    default saved                                      # 0=>first OS listed, 
                                                       # 1=>second and so on
    timeout 10                                         # Wait (0.1 sec) for user input
    #splashimage (hd0,1)/grub/splash.xpm.gz            # Optional splash image to use
    #password --md5 $1$gLhU0/$a....Uoe/                # Optional md5 encrypted password
    #password topsecret                                # Or plain text
    
    title Windows 2000                                 # Title of first OS
     root (hd0,0)                                      # Use the boot record here
     makeactive                                        # Activate a non-linux boot partition
     chainloader +1                                    # Non-linux OS, load file in 1st. sector
    
    title kernel 2.6.24-27                             # Title of second OS
     root (hd0,1)                                      # Use the boot record here
     kernel /vmlinuz-2.6.24-27 root=/dev/sda5 ro       # Kernel image and any parameters
     initrd /initrd.img-2.6.24-27                      # Ram disk image to load
     savedefault                                       # Default OS if 'default saved' exists
    
    title kernel 2.6.24-27 (Recovery)                  # Title of third OS
     root (hd0,1)
     kernel /vmlinuz-2.6.24-27 root=/dev/sda5 ro vga=0x317 single
     initrd /initrd.img-2.6.24-27
    
  • Grub install script
    /usr/sbin/grub-install

    Installs GRUB on a drive. It copies GRUB images into the [DIR]/boot directory specified by '--root-directory' option and uses the grub shell to install grub into the boot sector.

    Command usage

    grub-install [option] install_device
    
    Some options:
     install_device                  Can be a GRUB device name or a system device filename
     --root-directory=DIR            Install GRUB images under the directory DIR instead of the root directory
     --grub-shell=FILE               Use FILE as the grub shell
     --no-floppy                     Do not probe any floppy drive
     --force-lba                     Force GRUB to use LBA mode even for a buggy BIOS
     --recheck                       Probe a device map even if it already exists
    

    Install in MBR of first hard disk

    $ grub-install /dev/sda
                                     (or)
    $ grub-install '(hd0)'
    

    Install to floppy

    $ umount /dev/fd0
    $ grub-install '(fd0)'
                                     (or)
    $ grub-install /dev/fd0
    

    Install to second partition of second disk

    $ umount /dev/sdb
    $ grub-install '(hd1,1)'
                                     (or)
    $ grub-install /dev/sdb2
    

    Check device.map - grub-install

    # grub-install --recheck /dev/sda
    Probing devices to guess BIOS drives.  This may take a long time.
     Searching for GRUB installation directory ... found: /boot/grub
     .....
    

    'grub-install' looks for '/boot/grub/device.map'. If file does not exist GRUB guesses.

  • The grub shell
    /usr/sbin/grub

    Command usage

    grub [OPTION]...
    
    Some options:
     --config-file=FILE              Specify stage2 config_file [default=/boot/grub/menu.lst]
     --device-map=FILE               Use the device map file FILE
     --no-config-file                Do not use the config file
     --read-only                     Do not write anything to devices
    

    Install in MBR of first hard disk

    $ grub
    grub> root (hd0,0)
    grub> setup (hd0)
    

    Install to floppy

    $ grub
    grub> root (fd0)
    grub> setup (fd0)
    
  • Generate a menu.lst file
    /usr/sbin/update-grub

    Program to generate GRUB's menu.lst file.

    • Looks in /boot for all files which start with "vmlinuz-". Treats these as kernels and creates a menu entry for each.
    • Adds initrd lines for ramdisk images found with the same version as kernels found e.g. /boot/vmlinuz-2.4.5 and /boot/initrd-2.4.5
    • Creates the initial 'menu.lst' if none exists, after prompting the user.
    • After 'update-grub' has been run for the first time, the user is required to edit the generated 'menu.lst'.

    Run update-grub

    # update-grub [-y]
    

    Default update-grub settings - /boot/grub/menu.lst

    # kopt=root=/dev/hda1 ro               # Options passed to the linux kernel as
                                           # parameters - everything after "kopt="
    # groot=(hd0,1)                        # Grub device from which to load kernel
    # alternative=true                     # Create the alternative boot options in
                                           # the menu entries. 'false' - do not create
    # lockalternative=true                 # Lock the alternative boot options
    # lockold=true                         # Lock the old kernels. 'false' - do not lock
    # altoptions=(recovery option) single  # Controls what is used for the alternative 
                                           # boot options, multiple 'altoptions lines' 
                                           # are allowed. Format: 
                                           # altoptions=(desc.) kernel cmd-line options
                                           # Desc. is placed in '()', the kernel 
                                           # command line options follow
    # updatedefault=true                   # Should grub update the default entry to keep 
                                           # booting the same kernel even if a new one is   
                                           # installed. 'false' - do not update
    
  • Grub2
    recovery mode

    Grub2 is the later version of grub, big changes. Most modern Linux systems will be using this. It supports EFI boot.

    Grub2 enters recovery mode when it cannot find anything - one thing that will cause this to happen, when labels (UUID) are not being used, is removing partitions that cause the remaining partitions to be re-ordered. When this happens you need to tell grub where it's files are then have it go ahead as normal.

    Recover from rearranged partitions - tell grub where everything is

    grub recovery>
    grub recovery> set prefix=(hd0,X)/boot/grub      # where X is the partition number where
                                                     # /boot/grub resides. If /dev/sda5 then X=5
    grub recovery> set root=(hd0,X)                  # Where root partition resides  
    grub recovery> insmod normal
    grub recovery> normal                            # Causes grub to continue as normal
    

    This just gets you booted, you still need to ensure that grub is aware of the rearranged partitions. Once the system has booted, open a terminal

    Update grub with new partition info

    # update-grub                                    # Re-creates all the grub config files
    
    # grub-install /dev/sda                          # Re-installs grub in MBR of first disk
    
  • Run update-grub script 'automagically'
    /etc/kernel-img.conf

    When certain things happen 'update-grub' will be run automatically depending on the configuration in this file.

    Example configuration - kernel-img.conf

    do_symlinks = yes
    relative_links = yes
    do_bootloader = no
    do_bootfloppy = no
    do_initrd = yes
    link_in_boot = no
    postinst_hook = update-grub
    postrm_hook   = update-grub
    

    'update-grub' is a stub for 'grub-mkconfig -o /boot/grub/grub.cfg'