Unix Shutdown and Reboot

It is critical for system administrators to have a firm understanding of how the machine is being used and actively involve the users in scheduling downtime. For example, on most systems (except Cray to my knowledge), a shutdown will cause all user processes to be killed. If users on a system are running jobs that take days or weeks to complete then shutting the system down and cause all processes to be killed could severly impact the productivity of users. Whenever possible, users should be given as much lead time as possible when scheduling a shutdown. Once brought up to multi-user mode it is not uncommon for the system to run for many days, possibly even months, without being shutdown or rebooted. There are valid reasons for shutting down the system, these include:

Methods of shuting down and rebooting

There are three possible states you can end up in when you start to shutdown the system, these are:

Single-user mode

Previously when we discussed single-user mode we went over some of the tasks you may want to accomplish here. To leave multi-user mode under a BSD system you can enter the command shutdown time [message] , where time can be in absolute or relative terms. For relative time, use a value such as +5 to refer to five minutes from now. Absolute time is referenced as HH:MM and uses 24 hour notation. Finally, the keyword now may be specified to start a shutdown immediately. The message parameter is optional, but highly recommended. This should be enclosed in quotes and give a brief explanation of the reason for the shutdown and when the machine may be back up again.

Under System V, shutdown is acccomplished by issueing the command shutdown -y -i1 -g### . Where the -y option informs shutdown to auto-answer all questions with yes; -i1 instructs the system to go to init level 1 (single-user mode); -g### is the grace period to give users before shutting down. The ### symbols should be replace with the number of seconds to wait. Note that there is no message field to use under System V. It is strongly recommended that the system manager use a command such as wall to send a message to all users informing them of the reason for the shutdown and the time when the machine will be available again.

A complete shutdown

A complete shutdown is often done when hardware maintenance is planned for the machine or any other time the machine is to be powered off. On BSD based systems the shutdown command may be specified with the command option of -h to specify that the system should be completely shutdown and the processort halted. As mentioned above, the shutdown command accepts options for the grace time to give before shutdown and a message to send to users. In addition, most systems have a command name halt. In fact, the shutdown -h command usually just invokes the halt command. When you halt the system, all processes are killed, and the sync command is called to write the memory-resident disk buffers to disk. After which, the CPU is halted.

Under System V. based systems the same shutdown command is used as was described above except the init-level is set to zero, as in

shutdown -y -i0 -g### . Again, as in BSD based systems, all processes are killed and the sync command is called to write the memory-resident disk buffers to disk before halting the CPU.

The system is being rebooted

Systems are rebooted when changes have been made to the operating system and the Unix kernel must be restarted to take advantage of those changes. This is the case when Unix kernel parameters are changed. Often, for many changes software application changes a reboot is not required but may simplify the process of installing a new or updated piece of software.

Under BSD based systems, the shutdown command is again used to accomplish a reboot. The -r option is specified to the shutdown command and causes the system to be shutdown and then automtically rebooted. Similar to the halt, command there is a seperate command named reboot which is what the shutdown -r command actually invokes.

Under System V. based systems the same shutdown command is used as was described above except the init-level is set to six, as in

shutdown -y -i6 -g### .

As was mentioned previously, it is good policy to issue a wall command before starting the shutdown so you can inform users of the upcoming reboot.

Other ways to bring your system down, NOT!

Powering the machine off will shutdown the system, however it is very likely that some amount of disk corruption will occur when this happens. This is because the disk buffers cannot be written out to disk via a sync command. While the system performs a sync command at periodic intervals, if the system has heavy disk IO taking place corruption is likely to occur. That said, there are times when the system is hung, usually waiting on some device, and no keyboard input will be accepted.