12

It is now in the general knowledge that one should not shut down a computer using its power switch. But why is that exactly? Is it a myth that stuck from past architectures?

Is it solely to prevent corruption of data that's being written at the time of shutting down (bonus: how can it be corrupted exactly?)? I'm pretty sure hard drives' reading tips don't crash on the disk anymore when powered down (or I would be out of HDDs by now).

More precisely, does power cycling a computer with its power switch makes it wear out quicker or even become damaged in any way, and why (hardware only)?

7 Answers7

19

It is purely a software thing.

When you write to disk it doesn't go straight to the disk, but instead goes into a cache, and then at some later point in time that cache gets copied to the actual disk. Either when the cache is full and some extra room needs making in it, or just when the computer's not doing anything else important, or it is specifically instructed to.

One of the last operations during shutdown is to flush the cache to disk.

If you just power off, the data in that cache is going to get lost. Your data, as a result, may get corrupted.

Another important things that happens during shutdown is that all the running processes are instructed to exit, at which point the close any open files and clean themselves up.

Majenko
  • 32,964
5

During boot the filesystem of your computer will be flagged as 'dirty'. During shutdown all buffers are purged to disk and the data on disk is identical to what the Operating System believes it should look like. The disk is subsequently flagged 'clean'.

At next boot the flag is checked. When 'clean', your system boots, when 'dirty' the filesystem is scanned for sanity. Scanning the filesystem can take a long time and that is pretty much why you shouldn't want to do a hard power off. The real problem arises when the scan of the filesystem throws unrecoverable errors, those mean you've lost/corrupted data. Modern filesystems use a technique called 'journalling', to minimize the chance of unrecoverable errors.

In my opinion the hardware couldn't really care less about a hard power off.

jippie
  • 176
3

A modern computer has many levels of data storage caching. This is because most storage devices are faster with larger packets for reading and writing. The OS will hold writes in RAM for a while. Then they are sent to maybe a hard drive. Here they are in temporary storage, while waiting for the hard drive heads to get to the right sector. Then they are written. Data can be lost all along that chain, if a system is not powered down cleanly.

2

This is actually both a software and an hardware issue.

As previously stated in the other answers, current architectures use a lot of caching mechanisms, in order to speed up processes. On power loss, you loose the content that hasn't been written on the non-volatile memory, even if you thought you had written it into a file. This is a data loss. This may also lead to data corruption, as some filesystems don't write on the disk in the same order as the above programs do, in order to improve I/O rate. I have heard of some people disabling out-of-orders writes in ext4 to make some software file corruption prevention mechanisms still work, while ext4 developers tell that such program should use fsync to ensure the filesystem behavior.

There are also hardware issues. Brutal power down may lead to over-voltage or over-current, mostly due to inductive behavior of some electric components, mostly motors. Nevertheless, well designed hardwares should be able to prevent subsequent damages. It's a bit more expensive, but, if you buy computers with one year warranty (even optional), or, a least, handles customer returns, it is less expensive for the manufacturer to add a flyback diode than to handle customer returns. Therefore, I'm not worried here, except with very cheap power supplies.

It is worth to note that today's reasons to avoid brutal shutdown differ from the one from 30 years ago. 30 years ago, filesystems were very sensible to the power failures, and you were able to corrupt the filesystem itself. Today, you may corrupt files, but not the whole filesystem, in theory. Practically, if you want high-end, state of the art performance, you'll switch to SSD. Solid State Drives use managed flash, usually Multi Level Cells NAND flash (this means double level cells), sometimes Triple Level Cells. With those technologies, on power loss during write, you may corrupt the page being written, but also one or two other pages in the same block. At the filesystem level, a modification of one file may corrupt an other file, or even the filesystem data. Due to wear-leveling, garbage collection, and other correct-and-relocate mechanisms, writes may happen even when the filesystem doesn't require any activity from the SSD (this is called background operation), and corruptions are therefore unpredictable from filesystem point of view. To avoid such corruptions, some SSD manufacturers add capacitors to their SSD to allow to end any ongoing operation on flash when powerloss is detected (this requires roughly 10ms of power supply). SD cards and USB flash drives have the same constraints, but can't have such capacitors.

To put it in a nutshell, a well-designed hardware is generally power-loss proof, but more expensive. Software is most of time power-loss proof, but sometimes assumptions may be broken by the evolution of other software. Any attempt to make cheaper design, or to miniaturize design may reduce the ability to make the design power-loss proof. It is also hard to know if your computer will always resist to brutal power-loss.

Jens
  • 629
Jacen
  • 121
2

Electrical switches put transients into the power supply. (Transients are extremely high voltage, extremely narrow width. In fact, they are defined from my four years of electronics college instruction as infinite voltage of infinitely narrow width.) If there is not enough filtering these spikes can damage the electronics. Mechanical switches are also prone to ringing. Ringing is an oscillation on the power line which can cause similar problems.

Although many of the above answers are correct regarding software, electronic hardware must also be considered.

0

An answer which is lacking, but still current is this: A computer when forced shutdown (as in 'removed power cord or alike') can DAMAGE the electronics. (this does not apply to the power switch as it does a 'safe' power cycle that does not harm the electronics, just not that good for a stable HDD state, or and can cause data loss as already answered above).

The sudden surge of power that can occur when the power is removed forcefully (think 'spike') can in rare instances exceed the filter limits / ICs breakdown voltage. If this happens inside CMOS or other Memory it can permanently damage the 'cell' or corrupt data on the 'cell'. It is these days a rare thing and most systems have countermeasures for it (that can fail).

This situation is especially true if motors are used (like for a Disk Drive). Since the spin-down can sometimes cause a spike on one of its lines (+12,+5,-5,0). This does not have to be the power lines of the motor itself (due to 'ghosting').

Signals lower than 5 volts rarely do this as most IC's are designed to operate with 5 volt signals, although there are processors that utilize 3.3V as its max voltage most often there still shielded the same as the 5 V.

@samuel, Yes I am. but the operational voltage indicate what sort of inductive spike you can 'expect' (either the isolators /protaction for it, or the amount of it)

LvB
  • 194
0

It's not just computers! Unplugging a USB device such as a flash drive without doing the "Safely Remove" sequence can have the same effect as in some PCs, that is, the write portion of the sequence may not be completed and the flash contents may be corrupted.