Importance of Proper System Shutdown
When you have finished using your computer, it is important that you shut it down properly. Because FreeBSD often has several files open and is often doing several things at the same time, you can't simply turn off the power. Doing so could result in serious damage to your file system. Before you turn off your computer, you must issue one of the FreeBSD shutdown commands. This ensures that all running programs are stopped in an orderly fashion, all data has been successfully written to the disks, and all open files have been properly closed. There are several ways to shut down the system, but I'm only going to cover one of the commands here because this is the one you should almost always use. Note that you will need to be the root user to shut down the system. If you are still logged in under your normal user account, log out using the procedure discussed in the previous section. Then, at the login: prompt, enter the user name root, followed by whatever password you assigned to root during the system installation. Note that the command prompt will be different this time. Instead of bash$, you will have simply #. The different command prompt serves as a constant reminder that you are logged in as root and that you need to be especially careful about issuing commands. At the prompt, enter the command shutdown h now, and press Enter. You will see several messages on the screen. When the following message
System halted Please press any key to reboot
appears, you can safely turn off your computer. Or, if you want to reboot, you can simply press any key as it says, and the system will reboot.The syntax of the shutdown command as used previously contains the action that you want shutdown to perform, followed by when you want that action performed. In this case, h means that we want shutdown to halt the system, and we want it done now. Another commonly used option to shutdown is r rather than h. r tells shutdown that you want to reboot the system rather than halt it.
CAUTION
If you are sitting at the system you want to reboot, you can, of course, use the h option and then press any key to reboot as the system instructs. However, if you are logged in to the system from a remote location, it is very important to remember that the network connection will be shut down before the system is halted. This means that from a remote location, you cannot reboot the system using the h option because you will not get the chance to press any key to reboot the system. The result is that the system will remain offline until someone can physically reboot the system. If this all seems confusing to you at this point, simply remember this: If you are logged in to a system that you are not physically at and you want to reboot it, you must use the r option and not the h option.
NOTE
If you come from a Windows or Macintosh background, the second parameter that shutdown takes (when you want it to perform the action) might seem somewhat confusing to you. After all, why would you ever want to issue a command that tells the system to shut itself down later? The main reason for wanting to do this is the multiuser nature of FreeBSD. On a server that can have multiple people using it, it is rather rude to simply shut down the system with no warning, which in effect is "pulling the rug" out from under the users, causing them to lose any unsaved changes they might have in open files, and so on. Issuing a shutdown command with a delay will cause broadcast messages to be sent to all users letting them know of the impending shutdown and what time it will occur. The messages will become more frequent as the shutdown time gets closer. This allows users to make sure that they have saved any open files and such before the shutdown actually occurs. We will look at how to set a delayed shutdown in a later hour.