27
The Linux Boot Process Dr. Billy Harris -- Linux booting -- init/services configuration Copyright © 2002 Billy Harris ([email protected]) You are welcome to use and distribute this document so long as you retain this copyright message.

The Linux Boot Process - Unix Edu

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Linux Boot Process - Unix Edu

The LinuxBoot ProcessDr. Billy Harris -- Linux booting -- init/services configuration

Copyright © 2002 Billy Harris ([email protected])You are welcome to use and distribute this document so long as you retain this copyright message.

Page 2: The Linux Boot Process - Unix Edu

Basic Input/OutputSystem

Page 3: The Linux Boot Process - Unix Edu

Basic Input/OutputSystem• POST power-on self test• Video BIOS

VGA = 320x200, 256 colors

• Memory test• Device initialization

• Basic disk drivers• Setup

• Executes code from the MBR

Page 4: The Linux Boot Process - Unix Edu

Master Boot RecordVery first block of disk holds a boot

loader.The purpose of the boot loader is to

load an operating system.

It has 512 bytes for code to do this.

Page 5: The Linux Boot Process - Unix Edu

Master Boot RecordVery first block of disk holds a boot

loader.The purpose of the boot loader is to

load an operating system.

It has 512 bytes for code to do this.Minus whatever it uses to maintainthe partition table.

Under Windoze systems, the MBR isvery simple — it simply loadsspecified blocks from the disk andJMPs to begin executing.

Page 6: The Linux Boot Process - Unix Edu

Grand Unified BootLoader

Page 7: The Linux Boot Process - Unix Edu

Grand Unified BootLoaderGRUB• Mounts the boot partition [normally

referenced as /boot]

• Configuration is stored as an ordinarytext file on the disk.

• Despite its name, it is still x86specific, and does not support any ofthe BSD distributions.

Page 8: The Linux Boot Process - Unix Edu

Other Boot Loaders/boot/loader for BSD systemsLILO [older Linux boot loader]

aboot, elilo, milo

All have one purpose:→→→→ Load Linux←←←←

Page 9: The Linux Boot Process - Unix Edu

Linux KernelThe kernel is the operating system

• Memory management

• Interprocess communication• File I/O

• Various device drivers.

Page 10: The Linux Boot Process - Unix Edu

Linux KernelLinux uses a modular kernel, which

means that device drivers can beadded and removed withoutrebooting the system.

But what about device drivers that areneeded to boot the system (SCS�I ?)

-- Initial ramdisk [initrd] holds copies ofthese modules and is also loaded bythe boot loader.

Page 11: The Linux Boot Process - Unix Edu

Linux Booting• The kernel loads init• init launches a whole bunch of

programs including a variant ofgetty.

• getty runs login• login su's to the user, and executes

the user’s shell.

--slight variations if you use anXwindows-based login.

Page 12: The Linux Boot Process - Unix Edu

Files which ModifyBoot Behavoir/nologin disables non-root logins./fastboot disabled fsck

/forcefsck requires fsck/.autofsck requires fsck

Page 13: The Linux Boot Process - Unix Edu

ConfiguringInit

Page 14: The Linux Boot Process - Unix Edu

Old Days�Shell scriptsinit would execute rc, then rc.local

Wanted a new web server? Editrc.local.

Wanted a new ftp server? Editrc.local.

Ranted to replace old web server witha new one?

Edit rc.local

Page 15: The Linux Boot Process - Unix Edu

System V�Conceptually much more

complicated…Each service provides a shell script

which lives in the init.d directory,and can start, stop, or restart theservice.

The system uses different run levels todetermine which services to startand stop.

Page 16: The Linux Boot Process - Unix Edu

Run Levels�Run Level 0: System haltRun Level 1 [S]: Single UserRun Level 3: Multi-user; text loginRun Level 5: Multi-user; graphical loginRun Level 6: System rebootAlso have two customized run levels, A

and B, which start or stop services,but do not change the actual runlevel.

Page 17: The Linux Boot Process - Unix Edu

Init Scripts�# cd /etc/init.d# ls

anacron gpm kdcrotate

atd halt keytable

autofs httpd killall

netfs random sshd

crond identd kudzu

functions iptables lpd

# ./atd status

atd (pid 883) is running...

# ./lpd stop

Stopping lpd: [ OK ]

Page 18: The Linux Boot Process - Unix Edu

Service�# service httpd restartStopping httpd: [ OK ]

Starting httpd: [ OK ]

Can also useservice --status-all

service httpd --full-restart

Page 19: The Linux Boot Process - Unix Edu

Services & Run Levels�How does init know which services to

start/stop?• We still have rc.sysinit, rc, andrc.local.

• Better method: each run level has adirectory.

Each directory has symbolic links tothe init.d scripts

The name of the link determineswhether the service should bestarted/stopped.

Page 20: The Linux Boot Process - Unix Edu

Services & Run Levels�# cd /etc/rc.d/rc3.d# ls

K05saslauthd S13portmap S55sshd

K65identd S17keytable S56rawdevices

S05kudzu S20random S56xinetd

S08iptables S25netfs S58ntpd

S10network S26ups S60lpd

S12syslog S28autofs S78mysqld

# ls -al S60lpd

lrwxrwxrwx … S60lpd -> ../init.d/lpd

Page 21: The Linux Boot Process - Unix Edu

Telinit�Use telinit to change run levels• Examine each K script. If the system

is running, execute the script with“stop”

• Examine each S script. If the systemis not running, execute the script with“start”

How does init know whether or notthe system is running?

Page 22: The Linux Boot Process - Unix Edu

Configuring Services�The RPMS should install the scripts

you need. After installing, a simple# service <name> start

should work.

Similarly, you can stop a service anduse rpm -e to remove it from yoursystem.

Page 23: The Linux Boot Process - Unix Edu

Chkconfing�Chkconfig will add/remove the symbolic

links for you.# chkconfig --level 345 ntpd on# chkconfig --list ntpd

ntpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off

Can also use --del to remove the linksentirely [but the script is still in init.d] or--add to add a new service.

How does chkconfig know what numberto use for the S and K links?

Page 24: The Linux Boot Process - Unix Edu

Chkconfing�Chkconfig will add/remove the symbolic

links for you.# chkconfig --level 345 ntpd on# chkconfig --list ntpd

ntpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off

Can also use --del to remove the linksentirely [but the script is still in init.d] or--add to add a new service.

How does chkconfig know what numberto use for the S and K links?

Page 25: The Linux Boot Process - Unix Edu

Chkconfing�[init.d]# more sshd#!/bin/bash## Init file for OpenSSH server daemon## chkconfig: 2345 55 25# description: OpenSSH server daemon

Page 26: The Linux Boot Process - Unix Edu

Redhat ServiceConfifuration�ntsysv

menu-based text programredhat-configure-services

GNOME based program.

Both give a list of possible services; youcan check/uncheck to enable/disable.

Page 27: The Linux Boot Process - Unix Edu

Inittab� ## inittab This file describes# the system in a

id:5:initdefault:

# Trap CTRL-ALT-DELETEca::ctrlaltdel:/sbin/shutdown -t3 -r now

l2:2:wait:/etc/rc.d/rc 2

1:2345:respawn:/sbin/mingetty tty1

x:5:respawn:/etc/X11/prefdm -nodaemon