summaryrefslogtreecommitdiff
path: root/misc/slackbook/html/essential-sysadmin-shutdown.html
blob: a97c78f6d2599766d628e122e5ee090fd749c272 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>Shutting Down Properly</title>
<meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" />
<link rel="HOME" title="Slackware Linux Essentials" href="index.html" />
<link rel="UP" title="Essential System Administration" href="essential-sysadmin.html" />
<link rel="PREVIOUS" title="Users and Groups, the Hard Way"
href="essential-sysadmin-hardusers.html" />
<link rel="NEXT" title="Basic Network Commands" href="basic-network-commands.html" />
<link rel="STYLESHEET" type="text/css" href="docbook.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body class="SECT1" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"
alink="#0000FF">
<div class="NAVHEADER">
<table summary="Header navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th colspan="3" align="center">Slackware Linux Essentials</th>
</tr>

<tr>
<td width="10%" align="left" valign="bottom"><a href="essential-sysadmin-hardusers.html"
accesskey="P">Prev</a></td>
<td width="80%" align="center" valign="bottom">Chapter 12 Essential System
Administration</td>
<td width="10%" align="right" valign="bottom"><a href="basic-network-commands.html"
accesskey="N">Next</a></td>
</tr>
</table>

<hr align="LEFT" width="100%" />
</div>

<div class="SECT1">
<h1 class="SECT1"><a id="ESSENTIAL-SYSADMIN-SHUTDOWN"
name="ESSENTIAL-SYSADMIN-SHUTDOWN">12.3 Shutting Down Properly</a></h1>

<p>It is very important that you shut down your system properly. Simply turning the power
off with the power switch 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 managing the system
and keep a lot of files open. When the system's power is switched off, these files are
not closed properly and may become corrupted. Depending on what files become damaged, the
system might be rendered completely unusable! In any case, you'll have to go through a
long filesystem check procedure on the next reboot.</p>

<div class="NOTE">
<table class="NOTE" width="100%" border="0">
<tr>
<td width="25" align="CENTER" valign="TOP"><img src="./imagelib/admon/note.png"
hspace="5" alt="Note" /></td>
<td align="LEFT" valign="TOP">
<p>If you configured your system with a journalling filesystem, like ext3 or reiserfs,
you'll be partially protected from filesystem damage, and your filesystem check on reboot
will be shorter than if you had used a filesystem without journalling, like ext2.
However, this safety net is no excuse for improperly shutting down your system! A
journalling FS is meant to protect your files from events beyond your control, not from
your own laziness.</p>
</td>
</tr>
</table>
</div>

<p>In any case, when you want to reboot or power down your computer, it is important to
do so properly. There are several ways of doing so; you can pick whichever one you think
is the most fun (or least amount of work). Since a shutdown and a reboot are similar
procedures, most of the ways for powering off the system can also be applied to
rebooting.</p>

<p>The first method is through the <tt class="COMMAND">shutdown</tt>(8) program, and it
is probably the most popular. <tt class="COMMAND">shutdown</tt> can be used to reboot or
turn off the system at a given time, and can display a message to all the logged-in users
of the system telling them that the system is going down.</p>

<p>The most basic use of shutdown to power down the computer is:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">shutdown -h now</kbd>
</pre>
</td>
</tr>
</table>

<p>In this case, we are not going to send a custom message to the users; they will see
<tt class="COMMAND">shutdown</tt>'s default message. &#8220;<var
class="OPTION">now</var>&#8221; is the time that we want to shutdown, and the &#8220;<var
class="OPTION">-h</var>&#8221; 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 method
on a multiuser system would be to give everyone a little advance warning:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">shutdown -h +60</kbd>
</pre>
</td>
</tr>
</table>

<p>This would shutdown the system in one hour (60 minutes), which would be just fine on a
normal multiuser system. Vital systems should have their downtime scheduled far in
advance, and you should post warnings about the downtime in any appropriate locations
used for system notifications (email, bulletin board, <tt
class="FILENAME">/etc/motd</tt>, whatever).</p>

<p>Rebooting the system uses the same command, but substitutes &#8220;<var
class="OPTION">-r</var>&#8221; for &#8220;<var class="OPTION">-h</var>&#8221;:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">shutdown -r now</kbd>
</pre>
</td>
</tr>
</table>

<p>You can use same time notation with <tt class="COMMAND">shutdown -r</tt> that you
could with <tt class="COMMAND">shutdown -h</tt>. There are a lot of other things that you
can do with <tt class="COMMAND">shutdown</tt> to control when to halt or reboot the
machine; see the man page for more details.</p>

<p>The second way of shutting down or powering off the computer is to use the <tt
class="COMMAND">halt</tt>(8) and <tt class="COMMAND">reboot</tt>(8) commands. As the
names indicate, <tt class="COMMAND">halt</tt> will immediately halt the operating system,
and <tt class="COMMAND">reboot</tt> will reboot the system. (<tt
class="COMMAND">reboot</tt> is actually just a symbolic link to <tt
class="COMMAND">halt</tt>.) They are invoked like so:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">halt</kbd>
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">reboot</kbd>
</pre>
</td>
</tr>
</table>

<p>A lower-level way to reboot or shutdown the system is to talk directly to <tt
class="COMMAND">init</tt>. All the other methods are simply convenient ways to talk to
<tt class="COMMAND">init</tt>, but you can directly tell it what to do using <tt
class="COMMAND">telinit</tt>(8) (note that it only has one &#8220;l&#8221;). Using <tt
class="COMMAND">telinit</tt> will tell <tt class="COMMAND">init</tt> what runlevel to
drop into, which will cause a special script to be 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.</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">telinit 0</kbd>
</pre>
</td>
</tr>
</table>

<p>Runlevel 0 is halt mode. Telling <tt class="COMMAND">init</tt> 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
and modern desktop computers, this will also cause the machine to be turned off.</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">#</samp> <kbd class="USERINPUT">telinit 6</kbd>
</pre>
</td>
</tr>
</table>

<p>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.</p>

<p>For the curious, when switching to runlevel 0 or 6, whether by using <tt
class="COMMAND">shutdown</tt>, <tt class="COMMAND">halt</tt>, or <tt
class="COMMAND">reboot</tt>, the script <tt class="FILENAME">/etc/rc.d/rc.6</tt> is run.
(The script <tt class="FILENAME">/etc/rc.d/rc.0</tt> is another symbolic link, to <tt
class="FILENAME">/etc/rc.d/rc.6</tt>.) You can customize this file to your tastes--but be
sure to test your changes carefully!</p>

<p>There is one last method of rebooting the system. All the other methods require you to
be logged in as <tt class="USERNAME">root</tt>. However, it is possible to reboot the
machine even if you aren't root, provided that you have physical access to the keyboard.
Using <b class="KEYCAP">Control</b>+<b class="KEYCAP">Alt</b>+<b
class="KEYCAP">Delete</b> (the "three-fingered salute") will cause the machine to
immediately reboot. (Behind the scenes, the <tt class="COMMAND">shutdown</tt> command is
called for you when you use <b class="KEYCAP">Control</b>+<b class="KEYCAP">Alt</b>+<b
class="KEYCAP">Delete</b>.) The salute doesn't always work when using X Windows--you may
need to use <b class="KEYCAP">Control</b>+<b class="KEYCAP">Alt</b>+<b
class="KEYCAP">F1</b> (or another Function key) to switch to a non-X Windows terminal
before using it.</p>

<p>Finally, the file that ultimately controls every aspect of startup and shutdown is the
<tt class="FILENAME">/etc/inittab</tt>(5) file. In general, you should not need to modify
this file, but it may give you insight into why some things work the way they do. As
always, see the man pages for further details.</p>
</div>

<div class="NAVFOOTER">
<hr align="LEFT" width="100%" />
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" align="left" valign="top"><a href="essential-sysadmin-hardusers.html"
accesskey="P">Prev</a></td>
<td width="34%" align="center" valign="top"><a href="index.html"
accesskey="H">Home</a></td>
<td width="33%" align="right" valign="top"><a href="basic-network-commands.html"
accesskey="N">Next</a></td>
</tr>

<tr>
<td width="33%" align="left" valign="top">Users and Groups, the Hard Way</td>
<td width="34%" align="center" valign="top"><a href="essential-sysadmin.html"
accesskey="U">Up</a></td>
<td width="33%" align="right" valign="top">Basic Network Commands</td>
</tr>
</table>
</div>
</body>
</html>