- runlevels
- inittab
- init.d
- init / telinit
- reboot
- shutdown
- upstart
Runlevels:
Runlevel | Info | More Info |
0 | HALT | Standard acrosss all distributions |
1 | Single User Mode (recovery) | no network, root access, no password to login, standard across all distributions |
2 | Debian/Ubuntu | Default mode for both X and text mode |
3 | RedHat/SuSE | text mode for RH/SUSE, servers |
4 | Wildcard (not used by default) | can be customizable |
5 | Redhat/Suse | Loads X11 |
6 | Reboot | Standard acrosss all distributions |
Debian
sudo vi /etc/inittab
/etc/inittab: init(8) configuration.
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $
# The default runlevel.
id:2:initdefault:
# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS
# What to do in single-user mode.
~~:S:wait:/sbin/sulogin
# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.
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
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
# What to do when CTRL-ALT-DEL is pressed.ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
# Action on special keypress (ALT-UpArrow).
#kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."
# What to do when the power fails/returns.
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
#: : :
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6
# Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
CentOS 5
#
# inittab This file describes how the INIT process should set up
# the system in a certain run-level.
#
# Author: Miquel van Smoorenburg,
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:5:initdefault:
# System initialization.
si::sysinit:/etc/rc.d/rc.sysinit
l0:0:wait:/etc/rc.d/rc 0
l1:1:wait:/etc/rc.d/rc 1
l2:2:wait:/etc/rc.d/rc 2
l3:3:wait:/etc/rc.d/rc 3
l4:4:wait:/etc/rc.d/rc 4
l5:5:wait:/etc/rc.d/rc 5
l6:6:wait:/etc/rc.d/rc 6
# Trap CTRL-ALT-DELETE
ca::ctrlaltdel:/sbin/shutdown -t3 -r now
# When our UPS tells us power has failed, assume we have a few minutes
# of power left. Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly.
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
# Run gettys in standard runlevels
1:2345:respawn:/sbin/mingetty 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
# Run xdm in runlevel 5
x:5:respawn:/etc/X11/prefdm –nodaemon
It will read the prefdm to see the DM needed (KDE, GNOME, XDM)
[ovidiu@centos init.d]$ ls
acpid hidd messagebus rpcgssd
anacron hplip microcode_ctl rpcidmapd
apmd hsqldb multipathd rpcsvcgssd
atd httpd netconsole saslauthd
auditd ibmasm netfs sendmail
autofs ip6tables netplugd single
avahi-daemon iptables network smartd
avahi-dnsconfd irda NetworkManager snmpd
bluetooth irqbalance nfs snmptrapd
capi iscsi nfslock sshd
conman iscsid nscd syslog
cpuspeed isdn ntpd tcsd
crond killall oddjobd vmware-tools
cups krb524 pand vncserver
cups-config-daemon kudzu pcscd wdaemon
dnsmasq lircd portmap winbind
dund lisa psacct wpa_supplicant
firstboot lm_sensors rawdevices xfs
functions lvm2-monitor rdisc ypbind
gpm mcstrans readahead_early yum-updatesd
haldaemon mdmonitor readahead_later
halt mdmpd restorecond
[ovidiu@centos init.d]$
[ovidiu@centos etc]$ ls -l | grep rc.
lrwxrwxrwx 1 root root 11 Mar 6 14:50 init.d -> rc.d/init.d
-rw-r--r-- 1 root root 0 Jun 4 2007 Muttrc.local
lrwxrwxrwx 1 root root 7 Mar 6 14:55 rc -> rc.d/rc
lrwxrwxrwx 1 root root 10 Mar 6 14:55 rc0.d -> rc.d/rc0.d
lrwxrwxrwx 1 root root 10 Mar 6 14:55 rc1.d -> rc.d/rc1.d
lrwxrwxrwx 1 root root 10 Mar 6 14:55 rc2.d -> rc.d/rc2.d
lrwxrwxrwx 1 root root 10 Mar 6 14:55 rc3.d -> rc.d/rc3.d
lrwxrwxrwx 1 root root 10 Mar 6 14:55 rc4.d -> rc.d/rc4.d
lrwxrwxrwx 1 root root 10 Mar 6 14:55 rc5.d -> rc.d/rc5.d
lrwxrwxrwx 1 root root 10 Mar 6 14:55 rc6.d -> rc.d/rc6.d
drwxr-xr-x 10 root root 4096 Mar 6 14:55 rc.d
lrwxrwxrwx 1 root root 13 Mar 6 14:55 rc.local -> rc.d/rc.local
lrwxrwxrwx 1 root root 15 Mar 6 14:55 rc.sysinit -> rc.d/rc.sysinit
[ovidiu@centos etc]$
The rc.numer.d means the different commands at the diffrent runlevel
Different runlevel have different options
[ovidiu@centos rc3.d]$ ls
K01dnsmasq K69rpcsvcgssd S09isdn S26hidd
K02avahi-dnsconfd K73ypbind S10network S26lm_sensors
K02NetworkManager K74nscd S11auditd S26lvm2-monitor
K02oddjobd K85mdmpd S12restorecond S28autofs
K05conman K87multipathd S12syslog S50hplip
K05saslauthd K88wpa_supplicant S13cpuspeed S55sshd
K05wdaemon K89dund S13irqbalance S56cups
K10lircd K89netplugd S13iscsi S56rawdevices
K10psacct K89pand S13portmap S58ntpd
K10tcsd K89rdisc S14nfslock S80sendmail
K15httpd K91capi S15mdmonitor S85gpm
K20nfs K99readahead_later S18rpcidmapd S90crond
K24irda S00microcode_ctl S19rpcgssd S90xfs
K35vncserver S03vmware-tools S22messagebus S95anacron
K35winbind S04readahead_early S25bluetooth S95atd
K36lisa S05kudzu S25netfs S97yum-updatesd
K50ibmasm S07iscsid S25pcscd S98avahi-daemon
K50netconsole S08ip6tables S26acpid S99firstboot
K50snmpd S08iptables S26apmd S99local
K50snmptrapd S08mcstrans S26haldaemon S99smartd
[ovidiu@centos rc3.d]$
S – Start
K – Kill
## – number to start or stop in order
[ovidiu@centos rc1.d]$ ls
K01dnsmasq K20nfs K74nscd K89iscsi
K01smartd K24irda K74ntpd K89iscsid
K02avahi-daemon K25sshd K75netfs K89netplugd
K02avahi-dnsconfd K30sendmail K85mdmonitor K89pand
K02NetworkManager K35vncserver K85mdmpd K89rdisc
K02oddjobd K35winbind K85messagebus K90bluetooth
K03yum-updatesd K36lisa K85rpcgssd K90network
K05anacron K44rawdevices K85rpcidmapd K91capi
K05atd K50ibmasm K86nfslock K91isdn
K05conman K50netconsole K87irqbalance K92ip6tables
K05saslauthd K50snmpd K87mcstrans K92iptables
K05wdaemon K50snmptrapd K87multipathd K95firstboot
K10cups K60crond K87portmap K95kudzu
K10hplip K69rpcsvcgssd K87restorecond K99microcode_ctl
K10lircd K72autofs K88auditd K99readahead_early
K10psacct K73ypbind K88pcscd K99readahead_later
K10tcsd K74acpid K88syslog K99vmware-tools
K10xfs K74apmd K88wpa_supplicant S13cpuspeed
K15gpm K74haldaemon K89dund S26lvm2-monitor
K15httpd K74lm_sensors K89hidd S99single
[ovidiu@centos rc1.d]$
Everything is mostly stopped
Summary init
The inittab show the init process how to start and tells init what to do, sets default runlevel
The order in which it stops is inportant so as not to leave abandoned processes.
root@debian:/etc# cd rc2.d/
root@debian:/etc/rc2.d# ll
total 4
lrwxrwxrwx 1 root root 19 Mar 8 01:02 K01bluetooth -> ../init.d/bluetooth
-rw-r--r-- 1 root root 677 Jan 1 2011 README
lrwxrwxrwx 1 root root 22 Feb 20 04:47 S01vmware-tools -> ../init.d/vmware-tool
symlinks to ../init.d/
Reboot and Notify the users
shutdown –k now “Message”
ovidiucs@debian:/etc/rc2.d$ sudo shutdown -k now "Message"
[sudo] password for ovidiucs:
Broadcast message from root@debian (pts/1) (Sat Mar 10 17:22:45 2012):
Message
The system is going down to maintenance mode NOW!
Shutdown cancelled.
ovidiucs@debian:/etc/rc2.d$
ovidiucs@debian:~$ sudo shutdown +3 "Message" &
[1] 3465
ovidiucs@debian:~$
Broadcast message from root@debian (pts/1) (Sat Mar 10 17:26:02 2012):
Message
The system is going DOWN to maintenance mode in 3 minutes!
ovidiucs@debian:~$
ovidiucs@debian:~$ sudo shutdown -c
Shutdown cancelled.
ovidiucs@debian:~$
telinit
root@debian:~# telinit
Usage: telinit {-e VAR[=VAL] | [-t SECONDS] {0|1|2|3|4|5|6|S|s|Q|q|A|a|B|b|C|c|U|u}}
root@debian:~#
With telinit you tell the init which mode you want to go into
root@debian:~# which telinit
/sbin/telinit
root@debian:~# ll /sbin/telinit
lrwxrwxrwx 1 root root 4 Feb 20 03:49 /sbin/telinit -> init
root@debian:~#
Although telinit is a symbolic link, in UNIX systems you are not allowed to do this except if you use telinit, even the root is unable to use init.
No comments:
Post a Comment