It is very important that the system is shut down properly. Simply turning the power off can cause serious filesystem damage. While the system is on, files are in use even if you aren't doing anything. Remember that there are many processes running in the background all the time. These processes are controlling the system and keep a lot of files open. When the system just gets powered-off, these files are not closed properly and become damaged. Depending on what files become damaged, the system might be permanently damaged. In any case, you'll have to go through a long filesystem check procedure on the next reboot.
So, when you go to reboot or power down your computer, it is important to do so the right way. There are several ways of doing this; you can pick whichever one you think is the most fun. Most of the ways for turning off the system can also be applied to rebooting.
The first method is through the shutdown(8) program, and it is probably the most popular. shutdown can be used to reboot or turn off the system at a given time, and can display a message to all the users of the system telling them that the system is going down.
Basic usage of shutdown to turn off the computer is:
# shutdown -h now |
In this case, we are not going to send any special message to the users; they will see shutdown's default message. “now” is the time that we want to shutdown, and the “-h” means to halt the system. This is not a very friendly way to run a multi-user system, but it works just fine on your home computer. A better way on a multiuser system would be to give everyone a little advance warning:
# shutdown -h +60 |
This would shutdown the system in one hour (60 minutes), which would be just fine on a normal multiuser system. Really important systems should schedule their downtime far in advance and post warnings about it in the /etc/motd(5).
Rebooting the system uses the same command, but substitutes “-r” for “-h”:
# shutdown -r now |
You can use same time notation with shutdown -r that you could with shutdown -h. There are a lot of other things that you can do with shutdown to control when to halt or reboot the machine. See the man page for more details.
The second way of shutting down or powering off the computer is to use the halt(8) and reboot(8) commands. As the names indicate, halt will immediately halt the operating system, and reboot will reboot the system. reboot is simply a symbolic link to halt. They are invoked like so:
# halt # reboot |
A lower-level way to reboot or shutdown the system is to directly talk to init. All the other methods are simply convenient ways to talk to init, but you can directly tell it what to do using telinit(8) (note that it only has one “l”). Using telinit will tell init what runlevel to drop into, which will cause a special script to get run. This script will kill or spawn processes as needed for that runlevel. This works for rebooting and shutting down because both of those are special runlevels.
# telinit 0 |
Runlevel 0 is halt mode. Telling init to enter runlevel 0 will cause all processes to be killed off, the filesystems unmounted, and the machine to be halted. This is a perfectly acceptable way to bring down the system. On many laptops, this will also cause the machine to be turned off.
# telinit 6 |
Runlevel 6 is reboot mode. All processes will be killed off, the filesystems will be unmounted, and the machine will be rebooted. This is a perfectly acceptable method of rebooting the system.
There is one last method of rebooting the system. All the other methods required you to be root. However, it is possible to reboot the machine if you aren't root, provided that you have physical access to the keyboard. Doing a three-fingered salute (control-alt-delete) will cause the machine to be immediately rebooted. What this really does is run the program /usr/sbin/ctrlaltdel(8). So, if that program has strange permissions or is not present, pressing all those keys down won't do any good.