Next Previous Contents

4. Boot Loaders 4.1 Concepts
1. Invocation

Invocation of the boot loader usually occurs in one of two ways:
o o

BIOS loads the first stage boot loader from the drive's MBR. BIOS loads another boot loader which then loads the first stage boot loader from a partition's boot sector.

The first stage boot loader is also known as Initial Program Loader (IPL). It must be less than 512 bytes in size, so it is fairly limited. It's primary job is to load a more functional boot loader (a.k.a. the second stage boot loader).
2. Configuration

There are two different ways to configure a boot loader:
o o

Install the first stage of the boot loader on the MBR. It can then be configured to pass control to any desired operating system. Install the first stage of the boot loader in the boot sector of a partition. Another boot loader is then installed on the MBR. This other boot loader must be configured to pass control to the Linux boot loader.

4.2 Lilo
1. Configuration File
o /etc/lilo.conf

Sample File:
prompt timeout=50 default=linux boot=/dev/hda6 boot loader) # # # # Present lilo prompt so user can interact with lilo Timeout in milliseconds to wait for user interaction Default image to boot Specifies boot device (Location to install primary

map=/boot/map install=/boot/boot.b password=some_passwd restricted prompt message=/boot/message displayed at boot time. linear

# # # # #

To install in the MBR, specify /dev/hda Location of map file Location of Second stage boot loader A password required to boot Password only required if options are entered at boot

# Text message or splash screen (PCX) that will be

image=/boot/vmlinuz-2.4.7-10 memory compressed kernel label=linux initrd=/boot/initrd-2.4.7-10.img # Initial RAM Disk read-only root=/dev/hda9 # Location of root file system other=/dev/hda1 optional label=windows # Image definition

# Image definition # Specifies location of the virtual

See lilo.conf man page for an example. 2. Command Line Options o -t - Test lilo configuration, but don't actually install. o -v - Verbose 3. Boot Time arguments

Command line options can be entered at the boot prompt by appending it to the image that you are booting. For example:
linux root=/dev/hda5 mem=128M 1

Tells lilo to boot the kernel with a label of "linux" into runlevel 1 using /dev/hda5 as the root filesystem. It also states the machine has 128 MB of RAM. If lilo has been password protected, you will be required to enter the password before booting.
4. Errors

The 'LILO' prompt itself can be used to help diagnose boot related errors. The number of letters presented at the LILO prompt can indicate the success or failure of the boot loader.
o L = First stage boot loaded and started. Usually indicates disk problems or invalid options in /etc/lilo.conf.

o o o o o

LI = Second stage boot loaded from /boot, but /etc/lilo.conf has invalid parameters or /boot/boot.b was moved without re-running /sbin/lilo. LIL = Second stage loader started, but the descriptor table can't be loaded due to a bad disk or invalid parms in /etc/lilo.conf. LIL? = Second stage loaded at an incorrect address because of invalid parms in /etc/lilo.conf or /boot/boot.b was moved without re-running /sbin/lilo. LIL- = Descriptor table is corrupt. Caused by invalid parms in /etc/lilo.conf or /boot/boot.b was moved without re-running /sbin/lilo. LILO = All of LILO loaded correctly.

5. Limitations o Must be installed on the 1st or 2nd IDE drive. o Limited by BIOS (uses BIOS to load kernel off of disk). o Must re-run /sbin/lilo every time you change your configuration. 6. Fixing a corrupt MBR

Use lilo to fix:
/sbin/lilo

7. Uninstalling LILO

When LILO overwrites an existing boot sector, it saves a copy of the original boot sector in /boot. The name of the original boot sector will be boot.MMmm where 'MM' is the major device number and 'mm' is the minor device number. So, the original boot sector from /dev/hda will be /boot/boot.0300. To restore the original boot sector, use the dd command:
dd if=/boot/boot.0300 of=/dev/hda bs=446 count=1

The original boot sector is actually 512 bytes in length, but the remaining bytes after 446 are part of the partition table and we don't want to overwrite that in case it's changed.
8. Initial RAM Disk o Need: Allows necessary drivers to be loaded at boot time that aren't compiled directly into the kernel. o Creation: Use mkinitrd to create the initial RAM disk:
o o mkinitrd /boot/initrd-2.4.7-10 2.4.7-10 Setup: Specify in /etc/lilo.conf file as shown above.

4.3 Grub
1. Features o Command line interface available at boot prompt. o Can boot from multiple file systems including ext2/3, Reiserfs, FAT, minix, and FFS

Password protection using MD5 Changes to configuration file take effect immediately. Don't have to re-install MBR. 2. Configuration File
o /boot/grub/grub.conf

o o

Sample Configuration
# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/hdb5 # initrd /initrd-version.img #boot=/dev/hdb default=0 # Default to First definition for booting timeout=10 # Time in seconds to wait for user interaction splashimage=(hd1,0)/grub/splash.xpm.gz # Splash Screen password -簋饋菎$Z.............. # Password protection title Red Hat Linux (2.4.17) # First definition root (hd1,0) kernel /vmlinuz-2.4.17 ro root=/dev/hdb5 title Red Hat Linux (2.4.17pre2-pk) # Second definition root (hd1,0) kernel /vmlinuz-2.4.17pre2-pk ro root=/dev/hdb5 title Red Hat Linux (2.4.17pre2) root (hd1,0) kernel /vmlinuz-2.4.17pre2 ro root=/dev/hdb5 title Windows 98SE rootnoverify (hd0,0) makeactive chainloader +1

3. Boot Time arguments

In order to pass arguments to the image being booted, you must enter menu editing mode, or enter the grub command line. If GRUB has been password protected, you'll need to enter 'p' followed by your password first. To enter menu editing mode, select and entry and press 'e'. This will allow you to modify an existing boot setup and pass options to the kernel as well as init.

The GRUB command line allows you to create boot commands that don't exist in your grub.conf file. You can also run diagnostic tests and view the contents of files on your file systems.
4. Device Names according to Grub o (fd0) - First floppy drive detected by BIOS o (hd0) - First hard drive detected by BIOS (SCSI or IDE) o (hd1,3) - Fourth partition on the 2nd hard drive detected by the BIOS 5. Fixing a corrupt MBR

Use grub-install to fix:
/sbin/grub-install /dev/hda

6. Multi-disk scenario

In this situation, we have a nameless OS installed on /dev/hda and Linux installed on /dev/hdb. We need to setup grub to boot both OSes. This involves installing the first stage of grub on the MBR of /dev/hda and the second stage of grub on the /boot partition of /dev/hdb. We will use the grub configuration file listed above. This scenario assumes you either have a working system or are running in rescue mode chroot'd to /mnt/sysimage.
o

Launch a grub shell:
/sbin/grub

Note: The remaining steps will performed from within the "grub shell".
o

Set the root device:
root (hd1,0)

o

Specify where to install various boot stages:
install (hd1,0)/grub/stage1 d (hd0) (hd1,0)/grub/stage2 p (hd1,0)/grub/grub.conf

The above command line can be broken down as follows:
install <stage-1> d <install-disk> <stage-2> p <config file>

4.4 DOS Based
1. Loadlin - Capable of booting multiple OSes 2. Syslinux - Used by RH installation program.

Next Previous Contents

5. Boot up 5.1 Steps
1. BIOS loads first stage boot loader from the first sector of available disks (floppy, hard drive, cdrom, etc.) 2. First stage boot loader then loads the second stage boot loader. 3. Second stage boot loader allows user to choose what kernel to boot. 4. Chosen kernel then booted and devices are initialized. 5. Kernel then executes init process. 6. Init starts services according to /etc/inittab: o rc.sysinit - System initialization scripts 1. Mounts /proc. 2. Configures Kernel parameters (via sysctl) 3. Configures system clock. 4. Sets host name. 5. Initialize USB and HID devices. 6. Configure PnP. 7. Determines module dependencies. 8. Setup any RAID devices. 9. Performs file system checks if needed. 10. Mounts file systems. 11. Starts user quotas. 12. Enable process accounting. 13. Starts swap. 14. Initialize serial ports. 15. Dump boot messages to /var/log/dmesg 16. Much more.... o rc - Configures services based on runlevel 1. Stop services that begin with "K" in /etc/rcX.d where X is the runlevel. 2. Start services that begin with "S" in /etc/rcX.d where X is the runlevel. o rc.local - Configures any system specific information (deprecated). o Other, runlevel specific services started according to /etc/inittab. 1. mingetty (except for runlevel 1). 2. xdm (runlevel 5).

5.2 /etc/inittab
This file contains information needed by init to configure the system. Entries in the file have a specific format:

id:runlevel:style:command to run

1. id - A 1-4 character field the creates a unique identifier for the entry. 2. runlevel - Specifies the runlevel(s) that the entry applies to. 3. style - Specifies how the command is executed. o respawn - Process is restarted if it ever dies. o wait - Process is started once when the specified runlevel is entered. Init will wait for it to finish before proceeding. o once - Process will be executed once when the specified runlevel is entered. o boot - Process will be executed during system boot (runlevel field is ignored). o bootwait - Same as boot, except init will wait for it to complete before continuing. o initdefault - Specifies default run level (command field ignored). o sysinit - Process executed during boot before any boot or bootwait entries. o powerwait - Process executed when power goes down. Init waits for it to complete. o powerfail - Same as powerwait, except init doesn't wait for it to complete. o powerokwait - Executed when power is restored. Init waits for it to complete. o powerfailnow - Executed when battery on UPS is almost dead. o ctrlaltdel - Process executed when init receives SIGINT signal (CTRL+ALT+DEL was pressed). 4. command - Specifies process to execute.

5.3 Viewing boot up information.
1. Boot information displayed during boot up is stored in /var/log/dmesg. 2. Use 'dmesg' command to view.

5.4 Run Levels
0 1 2 3 4 5 6 Halt (Don't set default runlevel to this!) Single User mode Multi-user mode without NFS Full multi-user mode Unused X11 (with networking) Reboot (Don't set default runlevel to this!)

5.5 Default Run Levels
1. 2. 3. 4. Workstation/Laptop = 5 Server = 3 Custom with X = 5 Custom w/o X = 3

Next Previous Contents

6. Service Management 6.1 Types of services
1. System V services o Managed by System V init scripts o Scripts are stored in /etc/init.d 2. xinetd services o Services started by the xinetd daemon. o xinetd service control files located in /etc/xinetd.d o Defaults for xinetd set in /etc/xinetd.conf o xinetd itself is a System V service. 3. init services o Configured in /etc/inittab. o Provides respawn capability if service dies.

6.2 Management tools
1. System V services o service - Start/Stop services (CLI).

Example: To restart Apache:
service httpd stop service httpd start

or
service httpd restart

o

chkconfig - Configure services by runlevel (CLI). Doesn't affect currently running services. Defaults to runlevels 3,4, and 5 if none specified.

To enable Apache on runlevels 3, 4, and 5:
chkconfig httpd on # If runlevels aren't specified, default is 345

To enable Apache only on runleves 3 & 5:
chkconfig --level 35 httpd on

o

ntsysv - Configure services by runlevel (TUI).

Default is to configure current run level. Use "--level" option to specify a different runlevel.
o tksysv - Configure services by runlevel (GUI) (Deprecated). 2. xinetd services o chkconfig - Configures running services. Takes effect immediately on xinetd services.

To start vsftp:
chkconfig vsftp on

o

Edit service configuration file in /etc/xinetd.d/ directly. To enable, specify "disable = no". To disable, specify "disable = yes". After changing file, xinetd must either be given a USR2 signal so it re-reads it's configuration file or be restarted.
killall -USR2 xinetd

o o

3. init services

The only way to modify init based services is to edit /etc/inittab. After modifying the file, activate the changes by executing "init q".

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.