## Halt, reboot, or bring the system to single-user mode ##

[Author](authors.html): [[KevinDKinsey]]

[Reviewer](technical_reviewers.html): _name_ _[[contact]]_ _[[BSD_flavour]]_

[Reviewer](technical_reviewers.html): _name_ _[[contact]]_ _[[BSD_flavour]]_

----

### Concept ###

Understand the ramifications associated with halting, rebooting, or bringing a system to single-user mode,
recognize when it may be necessary to do so and how to minimize the impact on a server system.

### Introduction ###

Early computers were large, expensive machines, and companies and educational institutions that owned them were somewhat dismayed by the long lines of users in their hallways, waiting anxiously with "baited breath" and a stack of punchcards for a few minutes of computer time.  Later operating systems were developed so that multiple users could access the system from a network of terminals so that the universities and businesses that owned computers wouldn't have to pay people for standing around waiting for terminal access.  The BSDs have deep roots in this tradition, and are also "multi-user" operating systems.

The advent of the PC ("personal computer") made it possible for each user in some organizations to have their own machine, but many BSD machines are still used by more than one user; in fact, most system "daemons" (servers) are classed as "users" as well.  So are "client" computers that are connecting to your machine's mail, web, or other services.  Rebooting while a program is performing an operation can cause problems.  Also, it might be considered downright rude to halt a system while a user is still working on an important project.  For this reason, it is important to consider the issue of halting or rebooting a system.  Doing things the Right Way(tm) can benefit you greatly in the long run.

### System States ###

From a purely logical point of view, the computer system has two states:  OFF and ON.  However, in reality, there are more possibilities:  the system could be booting (going from OFF to ON), or powering-down (going from ON to OFF), or "rebooting" (going from ON to OFF to ON again).  In addition, when a BSD system is ON, it can be in either single-user or multi-user mode.

#### Single-user and Multi-user modes ####

During a "normal" boot process, `init(8)` attempts to bring the system up to "multi-user" mode.  System tty's are made available; all daemons, whether for the base system or third-party software marked "enabled" by `rc.conf` are started; network interfaces are configured and brought "up", and so on.  If errors occur during this process, `init` will start "single-user" mode instead.  "Single-user" mode may also be forced from the boot menu during second stage booting.  Finally, you can "downgrade" a system to single-user mode using commands similar to those used to halt, reboot, or power-down the system.

In single-user mode, there are no ttys available, the network is not brought up, etc.  The only possible "login" is as `root`, from the console.  Generally, no password is required for root in single-user mode.  This can be changed by editing the `ttys(5)` file and marking the console as "insecure", in which case init(8) will ask for the root password before allowing a shell in single-user mode.  In cases where unauthorized personnel may have access to the physical machine, it's a good idea to make this change.

### Shutdown(8) ###

`shutdown(8)` is a slightly nicer interface to the underlying system calls `halt(8)`, `fasthalt(8)`, and `reboot(8)`.  It allows a warning message to be sent to other users, allows you to set a time in the future for the change in system state to begin, and has other handy features.

#### Shutdown flags and arguments ####

`Shutdown` is called with a optional (but usually desired) flag and a required *time* argument.

* "-p" = "power down"
* "-r" = reboot
* "-h" = halt the OS  

The *time* parameter is one of: "now", a (positive) integer for "minutes", or an absolute datetime of "yymmddhhmm" (2-digit year, month, date, hour, minute).

### Examples ###

When called with no flags, shutdown will bring the system from multi-user down to single-user mode:

""**# shutdown now**

Turn the system off immediately (dependent on hardware support); if the system cannot be powered off automatically, halt the operating system (equivalent to `shutdown -h now`) instead:

""**# shutdown -p now**

Reboot the system in 45 minutes (see `shutdown(8)` for more information about what will happen in the meantime):

""**# shutdown -r 45**

Power down one second prior to New Year's Day, 2010:

""**# shutdown -p 0912312359**

"Kick" mode (kick off all users except root and disable non-root logins, but leave the system in multi-user mode):

""**# shutdown -k now**

TODO: about halt and reboot commands

TODO: on NetBSD (and check others) shutdown runs /etc/rc.shutdown then it runs "halt".

### Practice Exercises ###

1.  Use `shutdown` to "downgrade" a system from multi-user to single-user mode.

2.  Use `shutdown` to halt and reboot a system.

3.  Attempt to use `shutdown` to power-down a system.

4.  Optional:  If your system will **not** power-down with `shutdown -p`, research the following:

>* Motherboard make and model.
>* BIOS manufacturer and date.  Is an updated BIOS available?
>* does the system's BIOS use ACPI (Advanced Configuration and Power Interface) or the older APM (Advanced Power Management) as its Power Management API?  Which Power API is supported by your OS in its current configuration?

### More information ###

* shutdown(8)
