23
Runlevel initialization

Runlevel initialization. Boot to Linux Grub interface

Embed Size (px)

DESCRIPTION

Grub interface

Citation preview

Page 1: Runlevel initialization. Boot to Linux Grub interface

Runlevel initialization

Page 2: Runlevel initialization. Boot to Linux Grub interface

Boot to Linux

Master Boot Record

Partition 1: 100MEXT3 (Linux)

/boot

Partition 2: 10GBNTFS (Windows XP)

Partition 3: 512MBLinux Swap

Partition 4: 10GBEXT3 (Linux)

/

GRUB

MBR Passes control to the /boot partition

GRUB then boots to anOS (Windows or Linux)

Page 3: Runlevel initialization. Boot to Linux Grub interface

Grub interface

Page 4: Runlevel initialization. Boot to Linux Grub interface

LILO interface

Once LILO has successfully loaded, you will see a LILO prompt.

You may let LILO time out (after 10 seconds), which will boot the default the Linux partition.

Second, you can press the TAB key, which will list a selection of operating systems to boot from. In our example we would get "Linux" and "WindowsXP" as our options. Typing either of these will load up that OS.

Page 5: Runlevel initialization. Boot to Linux Grub interface

Changing runlevel at boot time

LILO: append the runlevel to the boot command : LILO: linux 3 or LILO: linux 5

GRUB: press the `e' key to edit the boot configuration append the runlevel to the end of the boot command as shown: kernel /vmlinuz ro root=/dev/hda1 5

Page 6: Runlevel initialization. Boot to Linux Grub interface

Kernel is loaded into memory

/boot

GRUB decompresses the Linux kernel and loads it

into memory

vmlinuz-2.6.12-1447_FC4

Memory

GRUB also passes “kernel command line”

(255bytes) to the loaded Linux kernel

Page 7: Runlevel initialization. Boot to Linux Grub interface

grub.conf# 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,1)# kernel /vmlinuz-version ro root=/dev/hdb3# initrd /initrd-version.img#boot=/dev/hdbdefault=0timeout=10splashimage=(hd0,1)/grub/splash.xpm.gztitle Linux Fedora (2.6.5-1.358smp) root (hd0,1) kernel /vmlinuz-2.6.5-1.358smp ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.5-1.358smp.imgtitle Linux Fedora-up (2.6.5-1.358) root (hd0,1) kernel /vmlinuz-2.6.5-1.358 ro root=LABEL=/ rhgb quiet initrd /initrd-2.6.5-1.358.imgtitle Windows 2000 rootnoverify (hd0,0) chainloader +1

Specifies the default boot image willbe the first hard entry

Grub will wait for 10 seconds for input fromthe user before continuing to boot.

The root partition is the second partitionon the first hard drive.

Page 8: Runlevel initialization. Boot to Linux Grub interface

Example lilo.conf File

boot=/dev/hdamap=/boot/mapinstall=/boot/boot.bprompttimeout=50default=linux

image=/boot/vmlinuz-2.2.12-20label=linuxinitrd=/boot/initrd-2.2.12-20.imgread-onlyroot=/dev/hda1

Page 9: Runlevel initialization. Boot to Linux Grub interface

Kernel starts the init process

Partition 4: 10GBEXT3 (Linux)

/

(Configuration files)

/etc

/etc/init.d

/etc/rc.d

/etc/inittab

# Default runlevelid:5:initdefault:

Resource (RC) scripts are stored here and are called depending on the system

runlevel

acpid*anacron*apmd*atd*auditd*...

rc5.d

Kernel passes desired runlevel to the init pocess as argument

If runlevel not specified, then

Page 10: Runlevel initialization. Boot to Linux Grub interface

System V initialization system RHEL 4BOOTFLAGS

It is possible to pass a number of flags to init from the boot monitor (eg. LILO). Init accepts the following flags:

-s, S, single - Single user mode boot. In this mode /etc/inittab is examined and the bootup rc scripts are usually run before the single user mode shell is started.

1-5 - Runlevel to boot into.

-b, emergency - Boot directly into a single user shell without running any other startup scripts.

-a, auto - The LILO boot loader adds the word "auto" to the command line if it booted the kernel with the default command line (without user intervention). If this is found init sets the "AUTOBOOT" environment variable to "yes".

-z xxx - The argument to -z is ignored. You can use this to expand the command line a bit, so that it takes some more space on the stack. Init can then manipulate the command line so that ps(1) shows the current runlevel.

Page 11: Runlevel initialization. Boot to Linux Grub interface

/etc/inittab

# The default runlevel is defined hereid:5:initdefault:

# First script to be executedsi::sysinit:/etc/rc.d/rc.sysinit

# /etc/init.d/rc takes care of # runlevel handlingl0:0:wait:/etc/init.d/rc 0l1:1:wait:/etc/init.d/rc 1l2:2:wait:/etc/init.d/rc 2l3:3:wait:/etc/init.d/rc 3l4:4:wait:/etc/init.d/rc 4l5:5:wait:/etc/init.d/rc 5l6:6:wait:/etc/init.d/rc 6ls:S:wait:/etc/init.d/rc S

# what to do when CTRL-ALT-DEL is pressedca::ctrlaltdel:/sbin/shutdown -r -t 4 now

# getty-programs for the normal runlevels# The "id" field MUST be the same as the# last characters of the device name1:2345:respawn:/sbin/mingetty --noclear

tty12:2345:respawn:/sbin/mingetty tty23:2345:respawn:/sbin/mingetty tty34:2345:respawn:/sbin/mingetty tty45:2345:respawn:/sbin/mingetty tty56:2345:respawn:/sbin/mingetty tty6

Page 12: Runlevel initialization. Boot to Linux Grub interface

rc.sysinit

Setting the path and the hostname, and checking whether networking is activated.

Mounting the /proc filesystem Setting the kernel parameters Setting the system clock Loading keymaps and fonts Starting swapping Initializing the USB controller along with the attached devices. Checking the root filesystem. Remounting the root filesystem as read-write. Loading modules as appropriate.

Page 13: Runlevel initialization. Boot to Linux Grub interface

/etc/init.d/rc

All initialization scripts are located in /etc/init.d.

Scripts for changing the runlevel are also found there, but are called through symbolic links from one of the subdirectories (/etc/init.d/rc0.d to /etc/init.d/rc6.d).

Because every script can be executed as both a start and a stop script, these scripts must understand the parameters start and stop.

Possible init Script Options Option Description start Start service. stop Stop service. restart If the service is

running, stop it then restart it. If it is not running, start it.

reload Reload the configuration without stopping and restarting the service.

force-reload Reload the configuration if the service supports this. Otherwise, do the same as if restart had been given.

status Show the current status of service.

Page 14: Runlevel initialization. Boot to Linux Grub interface

/sbin/rcunix root # more /sbin/rc#!/bin/bash

trap ":" INT QUIT TSTPsource /sbin/functions.sh# Only source this when this is a livecd booting ... [ -f /sbin/livecd-functions.sh ] && source /sbin/livecd-functions.shumask 022

try() { local errstr local retval=0

if [ -c /dev/null ]; then errstr="$((eval $*) 2>&1 >/dev/null)" else errstr="$((eval $*) 2>&1)" fi retval=$? if [ "${retval}" -ne 0 ] then # Progressbar begin if [ -c /dev/null ]; then rc_splash "stop" &>/dev/null & else rc_splash "stop" & fi # Progressbar end...

Page 15: Runlevel initialization. Boot to Linux Grub interface

init scripts start other processes/etc/rc.d/rc5.d /etc/init.d

K35smbK35vncserverK35winbindK50netdumpK50snmptrapdK73ypbindK74nscdS50snmpdS55cupsS55sshdS56rawdevicesS56xinetdS58ntpdS60nfs

cupsnetdumpnfsnscdntpdrawdevicessmbsnmpdsnmptrapdsshdvncserverwinbindxinetdypbind

K = KillS = Start

Scripts for each runlevel are symbolic links to their /

etc/init.d counterpart

The system first runs the scripts whose names start with K to kill the associated processes /etc/rc.d/init.d/<command> stop

The system runs the scripts whose names start with S to start the processes /etc/rc.d/init.d/<command> start

Page 16: Runlevel initialization. Boot to Linux Grub interface

System V initialization system RHEL 4

[juris@ns1 rc4.d]$ pwd/etc/rc.d/rc4.d[juris@ns1 rc4.d]$ ls –l...lrwxrwxrwx 1 root root 19 Jun 2 2005 K05saslauthd -> ../init.d/saslauthdlrwxrwxrwx 1 root root 13 Jun 2 2005 K20nfs -> ../init.d/nfslrwxrwxrwx 1 root root 14 Jun 2 2005 K24irda -> ../init.d/irdalrwxrwxrwx 1 root root 15 Jun 2 2005 K25squid -> ../init.d/squidlrwxrwxrwx 1 root root 16 Jun 2 2005 S09pcmcia -> ../init.d/pcmcialrwxrwxrwx 1 root root 16 Jun 2 2005 S40smartd -> ../init.d/smartdlrwxrwxrwx 1 root root 14 Jun 2 2005 S55sshd -> ../init.d/sshdlrwxrwxrwx 1 root root 16 Aug 11 2005 S55sshdlp -> ../init.d/sshdlp...lrwxrwxrwx 1 root root 15 Jun 2 2005 S97rhnsd -> ../init.d/rhnsdlrwxrwxrwx 1 root root 11 Jun 15 2005 S99local -> ../rc.local[juris@ns1 rc4.d]

Page 17: Runlevel initialization. Boot to Linux Grub interface

Benefits of init Scripts One of the benefits of using init directory scripts is that

they are easily tested. The scripts may be manually invoked with the stop and start

arguments as a check to determine whether they function correctly before creating the links to the rc directories, and trying them under actual system boot conditions.

This procedure is recommended because it can help you catch mistakes that might interrupt the boot process and leave the system unusable.

Page 18: Runlevel initialization. Boot to Linux Grub interface

System V initialization System service manipulation command

[juris@ns1 init.d]$ /sbin/serviceUsage: service < option > | --status-all | [ service_name [ command | --full-restart ] ][juris@ns1 init.d]$ /sbin/service sshdlpUsage: /etc/init.d/sshdlp {start|stop|restart|reload|condrestart|status}[juris@ns1 init.d]$

Page 19: Runlevel initialization. Boot to Linux Grub interface

Changing Run Levels The following commands are typically reserved for

system maintenance activities. UNIX shutdown Command The System V init 0 Command The telinit Command

NOTE: The shutdown, telinit, and init 0 commands can only be executed with root access.

Page 20: Runlevel initialization. Boot to Linux Grub interface

System V initialization

SIGHUP Has the same effect as telinit q.

SIGUSR1 On receipt of this signals, init closes and re-opens its control fifo, /dev/initctl. Useful for bootscripts when /dev is remounted.

SIGINT Normally the kernel sends this signal to init when CTRL-ALT-DEL is pressed. It activates the ctrlaltdel action.

SIGWINCH The kernel sends this signal when the keyboardSignal key is hit. It activates the kbrequest action.

Init reacts to several signals

Page 21: Runlevel initialization. Boot to Linux Grub interface

The OS Kernel UNIX Run Levels

All flavors of UNIX, and UNIX- work-alikes use similar foundations for the system run modes.

As far as UNIX and its ilk are concerned, there are basically two run modes:

single user (sometimes called maintenance mode), and multi-user.

There may be several forms of the multi-user mode (with services, without services, and so on) on any given UNIX OS.

Page 22: Runlevel initialization. Boot to Linux Grub interface

The OS Kernel Typically, BSD variants include a run control (also known as an rc) script

in the /etc directory. This allows the administrator to edit a single /etc/rc script to make it start a

new service at boot time. Other BSD variants have simply increased the number of rc files in the

/etc directory. For example, the FreeBSD start-up directory contains scripts with names

such as /etc/rc.atm, /etc/rc.firewall, and /etc/rc.network. These individual scripts, respectively, configure the ATM network

cards, cause the system to become a firewall, and configure the network links respectively.

These scripts are called by the master script, /etc/rc

Page 23: Runlevel initialization. Boot to Linux Grub interface

Sample BSD Startup Scripts/etc/rc.boot

First rc script to run is /etc/rc.boot The first two lines set HOME and PATH environment variables Executes basic system commands during boot hostname file in /etc for each network interface

enables IP networking on each interface Find hostname from other machine on NW using hostconfig

program and use NFS to mount filesystemsSystem Administrator intervene to fix problem