Saturday, October 17, 2009

Starting and Stopping the System

The job of booting and rebooting a machine falls to a special program called init. Init is responsible for finishing the boot process once the kernel is done loading, launching the services necessary to run the computer. Init is also responsible for stopping services when needed and for shutting down or rebooting the computer when instructed.

For decades, the software handling these duties was called SysVinit, or System V init. Modern Linux distributions have begun switching to a replacement called Upstart (a less common replacement, init-ng, we will not discuss). The traditional model, facilitated by SysVinit, divides potential system states into multiple runlevels, each with a distinct purpose. Runlevel 3, for example, indicates a standard booted system; runlevel 6 indicates a reboot. When entering a runlevel N, SysVinit runs all of the commands in the directory /etc/rcN.d. In this manner, the scripts in /etc/rc3.d handle a system’s booting while those in /etc/rc6.d handle a reboot. Various commands (see accompanying table) allow a system administrator to force the system into a given runlevel. The file /etc/inittab specifies what runlevel is entered on boot, as well as configuration for the system’s tty’s.

Upstart replaces this functionality with a more general mechanism for the stopping, starting, and monitoring of services. Upstart operates asynchronously and is a much more powerful system than SysVinit. Thankfully, however, it is backward compatible with SysVinit and most distributions use it in a way in which much of the preceding paragraph remains accurate. Indeed, most modern Linux distributions have moved to Upstart but still manage runlevels via SysVinit-style scripts in /etc/rcN.d.

The biggest change with Upstart is with configuration. Instead of an inittab, Upstart maintains a directory of configuration scripts, /etc/event.d. Files within this directory describe how Upstart should handle tty’s and SysVinit-style runlevels: /etc/event.d/ttyN configures ttyN while /etc/event.d/rcN configures runlevel N.



Common Command on Starting and Stopping the System

chkconfig Manage which services run in a runlevel.
ctrlaltdel Shut down and then soft reboot system.
halt Stop or shut down system.
initctl Manage the Upstart init daemon.
reboot Shut down and then hard reboot system.
runlevel Print system runlevel.
shutdown Shut down system.
telinit Change the current runlevel.
uptime Display uptimes of local machines


Source of Information : OReilly Linux in a Nutshell 6th Edition

No comments: