Online Book Reader

Home Category

UNIX System Administration Handbook - Evi Nemeth [31]

By Root 2804 0
that the system is being shut down and give the time remaining until the event; you can also supply a short message of your own. Your message should tell why the system is being brought down and should estimate how long it will be before users can log in again. On most systems, users cannot log in when a shutdown is imminent, but they will see your message if you specified one.

Most versions of shutdown let you specify whether the machine should halt, go to single-user mode, or reboot. Sometimes, you can also specify whether you want to fsck the disks after a reboot. On modern systems with large disks, a complete fsck can take a long time; you can generally skip the checks if you shut the system down cleanly. Some systems automatically skip the fsck checks whenever the filesystems were properly unmounted.

Table 2.6 outlines the shutdown command-line arguments on our example systems.

Table 2.6 The many faces of shutdown

a. R = Reboot, H = Halt, S = Enter single-user mode, F = Skip fsck

halt: a simpler way to shut down


The halt command performs the essential duties required to bring the system down. It is called by shutdown -h but can also be used by itself. halt logs the shutdown, kills nonessential processes, executes the sync system call (called by and equivalent to the sync command), waits for filesystem writes to complete, and then halts the kernel.

halt -n prevents the sync call; it’s used after fsck repairs the root partition, to prevent the kernel from overwriting repairs with old versions of the superblock that have been cached in memory. halt -q causes an almost immediate halt, without synchronization, killing of processes, or writing of logs. This flag is rarely appropriate.

reboot: quick and dirty restart


reboot is almost identical to halt, but it causes the machine to reboot from scratch rather than halting. reboot is called by shutdown -r. Like halt, it supports the -n and -q flags.

Sending init a TERM signal


The results of killing init are unpredictable and often nasty. Consult your documentation before sending any signals. When the BSD version of init receives a TERM signal, it usually kills all user processes, daemons, and gettys and returns the system to single-user mode. This facility is used by shutdown.

To send a signal to a process, you normally need to look up its process ID number with ps; however, init is always process 1. Use the kill command to send the signal:

# sync; sync

# kill -TERM 1

See page 51 for more information about kill.

More information about signals is given in Chapter 4.

telinit: change init’s run level


On systems with the beefy multilevel init, you can use the telinit command to direct init to go to a specific run level. For example,

# telinit S

takes the system to single-user mode on Solaris and HP-UX. Under Red Hat, you need to change to run level 1; otherwise, you’ll just start a root shell without actually changing the run level:

# telinit 1

When you use telinit, you do not get the nice warning messages or grace period that you get with shutdown. The command

# shutdown -i1

brings the system to the same state with more grace. telinit is most useful for testing changes to the inittab file. telinit -q makes init reread the inittab file.

Killing init


init is so important to the operation of the system that if it is killed with kill -KILL or kill -9, most computers will reboot automatically (some kernels just panic). This is a rough way to reboot; use shutdown or reboot instead.

1. Some modern “high availability” systems can have hardware added as the system is running. Although this feature is becoming more common as time goes on, most systems still need to be shut down in order for new hardware to be added safely and recognized correctly.

2. Some systems will also have /usr mounted.

3. Except under Solaris, which uses a more complex system.

4. We once had a corrupted keymap file, and since Red Hat loads the keymap file even in single-user mode, single-user was useless. Setting init=/bin/sh

Return Main Page Previous Page Next Page

®Online Book Reader