Linux+: Linux Install 08 – OS Shutdown

J

Jarret W. Buse

Guest
Linux+: Linux Install 08 – OS Shutdown

All Operating Systems (OS) at some point need to shutdown. With any OS, it is important to know the various procedures for stopping the OS. It may also be interesting to know what occurs during the shutdown process as well.

NOTE: This is a basic overview which can vary between distros.

Before getting to the shutdown, you need to understand how Linux is currently operating. The operations is defined as a runlevel. Linux has three basic runlevels common to all distros:

  • Runlevel 0 – Shutdown the system
  • Runlevel 1 – Single-user mode
  • Runlevel 6 – Reboot the system

Other possible runlevels can be:

  • Runlevel 2 – Multiuser mode and no networking
  • Runlevel 3 – Multiuser mode and networking
  • Runlevel 4 – Multiuser mode, networking and X Windows

NOTE: For your specific distro, check the documentation for exact runlevel numbers.

To determine the current runlevel, open a Terminal and type 'runlevel' at the prompt. You should receive a response of two numbers or an 'N' and a number. The first number shows the previous runlevel which an 'N' shows the runlevel before was 'None'. When a system boots and the runlevel has not been changed from the default, you will see the 'N'.

To change the runlevel, you type 'telinit #' at the prompt and specify the runlevel number (in place of #) you wish to switch to for this session.

Different runlevels can be useful. For instance, to recover data or a whole filesystem, it may be best to operate in a single-user environment so that the items to recover are not being accessed by others.

The Shutdown procedure is as follows:

  • Alert logged in users are notified that a shutdown is occurring
  • New logins are prevented
  • All processes are notified of the shutdown
  • Init is called to do the following:
    • Stop quotas
    • Stop accounting
    • Stop swapping information to the swap partition
    • Unmount all disks
  • Runlevel is changed appropriately
    • 0 – Shutdown
    • 1 – Single user mode
    • 6 – Reboot

In most cases, there is a quit button in any Graphical User Interface (GUI), unless it has been disabled. Another option is by pressing CTRL-ALT-DEL and then selecting shutdown or restart from the displayed screen. When the GUI is used, it is similar to entering the 'shutdown' command at a command prompt.

Within a Terminal at a command prompt, the command 'shutdown' can be issued with the following parameters:

  • -a - use the file '/etc/shutdown.allow'
  • -c – cancels the shutdown processes
  • -f – reboot fast
  • -F – Force fsck on boot
  • -h – system should be halted or powered down when the shutdown process is completed
  • -H – requests that the system is halted after a shutdown
  • -k – alert logged in users that system is shutting down and prevent new logons, but do not shutdown the system
  • -n – shutdown performs tasks and not Init
  • -P – system should be powered off after the shutdown
  • -r – system should be rebooted after shutdown

NOTE: Use the 'man shutdown' command to see the parameters which are used for your specific distro.

A TIME option can be specified to set an amount of time before the shutdown occurs. The time can be specified as minutes or hours:minutes. It is possible to specify the word 'now' to perform the shutdown immediately.

NOTE: Users are not notified and new logons prevented until the time reaches 5 minutes. The alert happens immediately if the time is less than 5 minutes.

When a delay time is set, a file '/etc/nologin' is created. When a user attempts to login, the file is checked an if it exists the login is prevented. The file is left and when the system starts back up, the boot process checks for the file. If the file exists, then fsck is not run since the system was shutdown properly. The file is deleted if 'init' is not executed to change the runlevel. Once the system is restarted, the '/etc/nologin' file is deleted.

When a fast reboot is performed (-f), a file '/fastboot' is created which shows on startup not to perform an fsck since the system was properly shutdown.

When a force fsck is performed (-F), the system checks for the file '/forcefsck' which was created during the shutdown process. If the file is present, an fsck is performed no matter the shutdown state.

When the -a parameter is used, the system will check for the existence of the file '/etc/shutdown.allow'. If the file is not present, the parameter will be ignored. If the file is present, it will be parsed to find the name of the current user to determine if the user has permission to perform a shutdown. The file is a simple text file with one name per line with a maximum of 32 names in the file.
 

Attachments

  • slide.jpg
    slide.jpg
    42.4 KB · Views: 53,841

Members online


Top