UNIX - SigmaNet

Download Report

Transcript UNIX - SigmaNet

Runlevel initialization

Boot to Linux

Master Boot Record Partition 1: 100M EXT3 (Linux) /boot Partition 2: 10GB NTFS (Windows XP) MBR Passes control to the /boot partition GRUB GRUB then boots to an OS (Windows or Linux) Partition 3: 512MB Linux Swap Partition 4: 10GB EXT3 (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.

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

Kernel is loaded into memory

GRUB decompresses the Linux kernel and loads it into memory /boot vmlinuz-2.6.12-1447_FC4 GRUB also passes “kernel command line” (255bytes) to the loaded Linux kernel Memory

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/hdb default=0 timeout=10 splashimage=(hd0,1)/grub/splash.xpm.gz

title 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.img

title 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.img

title Windows 2000 rootnoverify (hd0,0) chainloader +1 Specifies the default boot image will be the first hard entry Grub will wait for 10 seconds for input from the user before continuing to boot.

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

Example lilo.conf File

boot=/dev/hda map=/boot/map install=/boot/boot.b

prompt timeout=50 default=linux image=/boot/vmlinuz-2.2.12-20 label=linux initrd=/boot/initrd-2.2.12-20.img

read-only root=/dev/hda1

Kernel starts the init process

Kernel passes desired runlevel to the

init

pocess as argument

Partition 4: 10GB EXT3 (Linux) /

/etc (Configuration files) If runlevel not specified, then

# Default runlevel id:5:initdefault:

/etc/inittab /etc/init.d

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

/etc/rc.d

Resource (RC) scripts are stored here and are called depending on the system runlevel rc5.d

BOOTFLAGS the following flags:

System V initialization system RHEL 4

It is possible to pass a number of flags to init from the boot monitor (eg. LILO). Init accepts -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.

/etc/inittab

# The default runlevel is defined here id:5:initdefault: # First script to be executed si::sysinit:/etc/rc.d/rc.sysinit

# /etc/init.d/rc takes care of # runlevel handling l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 ls:S:wait:/etc/init.d/rc S # what to do when CTRL-ALT-DEL is pressed ca::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 name 1:2345:respawn:/sbin/mingetty --noclear tty1 2:2345:respawn:/sbin/mingetty tty2 3:2345:respawn:/sbin/mingetty tty3 4:2345:respawn:/sbin/mingetty tty4 5:2345:respawn:/sbin/mingetty tty5 6:2345:respawn:/sbin/mingetty tty6

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.

/etc/init.d/rc   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

).  All initialization scripts are located in /etc/init.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 service is running, stop it then restart it. If it is not running, start it.

If the reload configuration without stopping and restarting the service.

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

status current status of service.

Show the

/sbin/rc

unix root # more /sbin/rc #!/bin/bash trap ":" INT QUIT TSTP source /sbin/functions.sh

# Only source this when this is a livecd booting ... [ -f /sbin/livecd-functions.sh ] && source /sbin/livecd-functions.sh

umask 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 ...

init scripts start other processes

/etc/rc.d/rc5.d

K35smb K35vncserver K35winbind K50netdump K50snmptrapd K73ypbind K74nscd S50snmpd S55cups S55sshd S56rawdevices S56xinetd S58ntpd S60nfs K = Kill S = Start /etc/init.d

Scripts for each runlevel are symbolic links to their / etc/init.d counterpart cups netdump nfs nscd ntpd rawdevices smb snmpd snmptrapd sshd vncserver winbind xinetd ypbind The system first runs the scripts whose names start with K to kill the associated processes  /etc/rc.d/init.d/ stop The system runs the scripts whose names start with S to start the processes  /etc/rc.d/init.d/ start

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/saslauthd lrwxrwxrwx 1 root root 13 Jun 2 2005 K20nfs -> ../init.d/nfs lrwxrwxrwx 1 root root 14 Jun 2 2005 K24irda -> ../init.d/irda lrwxrwxrwx 1 root root 15 Jun 2 2005 K25squid -> ../init.d/squid lrwxrwxrwx 1 root root 16 Jun 2 2005 S09pcmcia -> ../init.d/pcmcia lrwxrwxrwx 1 root root 16 Jun 2 2005 S40smartd -> ../init.d/smartd lrwxrwxrwx 1 root root 14 Jun 2 2005 S55sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 16 Aug 11 2005 S55sshdlp -> ../init.d/sshdlp ...

lrwxrwxrwx 1 root root 15 Jun 2 2005 S97rhnsd -> ../init.d/rhnsd lrwxrwxrwx 1 root root 11 Jun 15 2005 S99local -> ../rc.local

[juris@ns1 rc4.d]

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.

System V initialization

System service manipulation command

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

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.

System V initialization

Init reacts to several signals SIGHUP Has the same effect as telinit q.

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

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.

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.

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

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 filesystems  System Administrator intervene to fix problem