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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
|
<HTML
><HEAD
><TITLE
>More about shutdowns</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="The Linux System Administrator's Guide"
HREF="index.html"><LINK
REL="UP"
TITLE="Boots And Shutdowns"
HREF="boots-and-shutdowns.html"><LINK
REL="PREVIOUS"
TITLE="The boot process in closer look"
HREF="x1929.html"><LINK
REL="NEXT"
TITLE="Rebooting"
HREF="x2012.html"></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"
>The Linux System Administrator's Guide: </TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="x1929.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 8. Boots And Shutdowns</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="x2012.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="sect1"
><H1
CLASS="sect1"
><A
NAME="AEN1977"
></A
>8.3. More about shutdowns</H1
><P
>It is important to follow the correct procedures when you shut
down a Linux system. If you fail do so, your filesystems probably
will become trashed and the files probably will become scrambled.
This is because Linux has a disk cache that won't write things
to disk at once, but only at intervals. This greatly improves
performance but also means that if you just turn off the power
at a whim the cache may hold a lot of data and that what is on
the disk may not be a fully working filesystem (because only
some things have been written to the disk).</P
><P
>Another reason against just flipping the power switch is that
in a multi-tasking system there can be lots of things going on
in the background, and shutting the power can be quite
disastrous. By using the proper shutdown sequence, you ensure
that all background processes can save their data.</P
><P
>The command for properly shutting down a Linux system
is <B
CLASS="command"
>shutdown</B
>. It is usually used in one of
two ways.</P
><P
>If you are running a system where you are the only user,
the usual way of using <B
CLASS="command"
>shutdown</B
> is to quit
all running programs, log out on all virtual consoles, log
in as root on one of them (or stay logged in as root if you
already are, but you should change to root's home directory or
the root directory, to avoid problems with unmounting), then
give the command <B
CLASS="command"
>shutdown -h now</B
> (substitute
<TT
CLASS="literal"
>now</TT
> with a plus sign and a number in minutes
if you want a delay, though you usually don't on a single user
system).</P
><P
>Alternatively, if your system has many users, use the command
<B
CLASS="command"
>shutdown -h +time message</B
>, where
<TT
CLASS="literal"
>time</TT
>
is the
time in minutes until the system is halted, and
<TT
CLASS="literal"
>message</TT
>
is a short explanation of why the system is shutting down.
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
> <TT
CLASS="prompt"
>#</TT
> <TT
CLASS="userinput"
><B
>shutdown -h +10 'We will install a new
disk. System should
> be back on-line in three hours.'</B
></TT
>
<TT
CLASS="prompt"
>#</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
>
This will warn everybody that the system will shut down in
ten minutes, and that they'd better get lost or lose data.
The warning is printed to every terminal on which someone is
logged in, including all <B
CLASS="command"
>xterm</B
>s:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="screen"
> <TT
CLASS="computeroutput"
> Broadcast message from root (ttyp0) Wed Aug 2 01:03:25 1995...
We will install a new disk. System should
be back on-line in three hours.
The system is going DOWN for system halt in 10 minutes !!
</TT
>
</PRE
></FONT
></TD
></TR
></TABLE
>
The warning is automatically repeated a few times before the boot,
with shorter and shorter intervals as the time runs out.</P
><P
>When the real shutting down starts after any delays, all
filesystems (except the root one) are unmounted, user processes
(if anybody is still logged in) are killed, daemons are shut down,
all filesystem are unmounted, and generally everything settles
down. When that is done, <B
CLASS="command"
>init</B
> prints out a
message that you can power down the machine. Then, and only then,
should you move your fingers towards the power switch.</P
><P
>Sometimes, although rarely on any good system, it is
impossible to shut down properly. For instance, if the kernel
panics and crashes and burns and generally misbehaves, it might
be completely impossible to give any new commands, hence shutting
down properly is somewhat difficult, and just about everything
you can do is hope that nothing has been too severely damaged
and turn off the power. If the troubles are a bit less severe
(say, somebody hit your keyboard with an axe), and the kernel
and the <B
CLASS="command"
>update</B
> program still run normally,
it is probably a good idea to wait a couple of minutes to give
<B
CLASS="command"
>update</B
> a chance to flush the buffer cache,
and only cut the power after that.</P
><P
>Some people like to shut down using the command
<B
CLASS="command"
>sync</B
>
<A
NAME="AEN2005"
HREF="#FTN.AEN2005"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
>
three times, waiting for the disk I/O to stop, then turn off
the power. If there are no running programs, this is about
equivalent to using <B
CLASS="command"
>shutdown</B
>. However, it
does not unmount any filesystems and this can lead to problems
with the ext2fs <SPAN
CLASS="QUOTE"
>"clean filesystem"</SPAN
> flag. The triple-sync
method is <EM
>not recommended</EM
>.</P
><P
>(In case you're wondering: the reason for three syncs is
that in the early days of UNIX, when the commands were
typed separately, that usually gave sufficient time for most
disk I/O to be finished.)
</P
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN2005"
HREF="x1977.html#AEN2005"
><SPAN
CLASS="footnote"
>[1]</SPAN
></A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
><B
CLASS="command"
>sync</B
> flushes the
buffer cache. </P
></TD
></TR
></TABLE
><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="x1929.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="x2012.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>The boot process in closer look</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="boots-and-shutdowns.html"
ACCESSKEY="U"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Rebooting</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>
|