The Boot

Dr. Billy Harris

-- Linux -- /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. Basic Input/Output System Basic Input/Output System • POST power-on self test

•Video BIOS VGA = 320x200, 256 colors

•Memory test

•Device initialization

• Basic disk drivers

•Setup

•Executes code from the MBR Very first block of disk holds a boot .

The purpose of the boot loader is to load an .

It has 512 for code to do this. Master Boot Record Very 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 maintain the partition table.

Under Windoze systems, the MBR is very simple — it simply loads specified blocks from the disk and JMPs to begin executing. Grand Unified Boot Loader Grand Unified Boot Loader GRUB

•Mounts the boot partition [normally referenced as /boot]

•Configuration is stored as an ordinary text file on the disk.

•Despite its name, it is still specific, and does not support any of the BSD distributions. Other Boot Loaders /boot/loader for BSD systems

LILO [older Linux boot loader] aboot, elilo, milo

All have one purpose: →→ ←← Load Linux The kernel is the operating system

• Memory management

•Interprocess communication

•File I/O

• Various device drivers. Linux Kernel Linux uses a modular kernel, which means that device drivers can be added and removed without rebooting the system.

But what about device drivers that are needed to boot the system (SCSI ?)

-- [initrd] holds copies of these modules and is also loaded by the boot loader. Linux Booting •The kernel loads init

• init launches a whole bunch of programs including a variant of getty.

•getty runs login

• login su's to the user, and executes the user’s .

--slight variations if you use an Xwindows-based login. Files which Modify Boot Behavoir /nologin disables non-root logins.

/fastboot disabled fsck

/forcefsckrequires fsck

/.autofsck requires fsck Configuring Init Old Days Shell scripts init would execute rc, then rc.local

Wanted a new web ? Edit rc.local.

Wanted a new ftp server? Edit rc.local.

Ranted to replace old web server with a new one?

Edit rc.local 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 the service.

The system uses different run levels to determine which services to start and stop. Run Levels Run Level 0: System halt Run Level 1 [S]: Single User Run Level 3: Multi-user; text login Run Level 5: Multi-user; graphical login Run Level 6: System

Also have two customized run levels, A and B, which start or stop services, but do not change the actual run level. Init Scripts #cd/etc/init.d #ls anacron gpm kdcrotate atd halt keytable autofs httpd killall netfsrandom sshd crond identd kudzu functions iptables lpd

#./atdstatus atd(pid883)isrunning...

#./lpdstop Stoppinglpd:[OK] Service #servicehttpdrestart Stoppinghttpd: [OK] Startinghttpd: [OK]

Can also use service--status-all servicehttpd--full-restart Services & Run Levels How does init know which services to start/stop?

•We still have rc.sysinit, rc, and rc.local.

• Better method: each run level has a directory.

Each directory has symbolic links to the init.d scripts

The name of the link determines whether the service should be started/stopped. Services & Run Levels #cd/etc/rc.d/rc3.d #ls K05saslauthdS13portmap S55sshd K65identdS17keytable S56rawdevices S05kudzuS20randomS56xinetd S08iptablesS25netfsS58ntpd S10networkS26upsS60lpd S12syslogS28autofsS78mysqld

#ls-alS60lpd lrwxrwxrwx…S60lpd->../init.d/lpd 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 system is not running, execute the script with “start”

How does init know whether or not the system is running? Configuring Services The RPMS should install the scripts you need. After installing, a simple

#servicestart should work.

Similarly, you can stop a service and use rpm -e to remove it from your system. Chkconfing Chkconfig will add/remove the symbolic links for you.

#chkconfig--level345ntpdon #chkconfig--listntpd ntpd0:off1:off2:off3:on4:on5:on6:off

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

How does chkconfig know what number to use for the S and K links? Chkconfing Chkconfig will add/remove the symbolic links for you.

#chkconfig--level345ntpdon #chkconfig--listntpd ntpd0:off1:off2:off3:on4:on5:on6:off

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

How does chkconfig know what number to use for the S and K links? Chkconfing [init.d]# more sshd #!/bin/bash # # Init file for OpenSSH server # # chkconfig: 2345 55 25 # description: OpenSSH server daemon Redhat Service Confifuration ntsysv menu-based text program redhat-configure-services GNOME based program.

Both give a list of possible services; you can check/uncheck to enable/disable. Inittab # #inittabThisfiledescribes #thesystemina

id:5:initdefault:

#TrapCTRL-ALT-DELETE ca::ctrlaltdel:/sbin/-t3-rnow

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

1:2345:respawn:/sbin/mingettytty1

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