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)?

9
  • 2
    For consumer devices, it's actually the other way around: with MS-DOS you could just pull the plug; when Windows took over you had to learn to shut down properly.
    – Pete Becker
    Commented Jan 19, 2015 at 15:27
  • SSDs might be an issue similar to HDDs. They write by erasing data in large blocks and re-writing the new data, so if that operation is not completed for the block there would be data corruption. The O/S may be smart enough to recover from that, but it's not 'nice', and eventually you might have an unrecoverable error. Commented Jan 19, 2015 at 15:35
  • 3
    Let me point out that the potential side effects of "pulling the plug", while technically correct, are typically greatly overblown. I've "brutally" shut down my computer countless times. I've never ever had corrupted files, or hardware problems. Not even once. In over 15 years. Commented Jan 19, 2015 at 20:24
  • 5
    @AndreasBonini "I've never ever had corrupted files, or hardware problems." Just to be a pedant, you've never had corrupted files that you've noticed or that had a big impact (e.g., are you sure that no continually written log files or temporary files were corrupted?), or that couldn't be repaired when the system booted against (those "system wasn't properly shut down, checking for errors..." messages) or hardware that completely stopped functioning (e.g., lots of hardware, and especially storage, has built in mechanisms for detecting and working around damaged parts). Commented Jan 19, 2015 at 22:23
  • 1
    Actually, for a modern computer, I'd sum it up like this: assuming you've saved all your files, a power failure is most likely acceptable in most cases, although it may shorten your power supply's life a bit. It's still never a good idea to unplug your computer when it tells you not to. Windows updates, for example, or flashing the BIOS. Interrupting those processes could leave your OS or even your hardware inoperable. That's probably the biggest risk you can take, purposefully interrupting core updates.
    – phyrfox
    Commented Jan 20, 2015 at 0:21

7 Answers 7

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.

7
  • 3
    There may be some hardware-issues too. If the power is just cut, the read/write head may "dip" and scratch the surface of the disk. Also if the computer is moved or subjected to shock, a wayward head may damage the surface. When powered-down properly on the other hand, the head is parked where it neither can damage nor get damaged. Commented Jan 19, 2015 at 14:52
  • 6
    @BaardKopperud Maybe with a 40 year old disk, but not a modern one. "Parking" of disk heads is no longer needed.
    – Majenko
    Commented Jan 19, 2015 at 14:53
  • 2
    @Majenko well, 40 years is a bit of an overstatement... some particular 1990's disks and CD-ROMs were prone to head crash if the power was cut off too, possibly due to vibrations/damping issues - I experienced that myself with 13 GB drive, and it wasn't pretty what I saw looking at the discs afterwards. Also, I've had a similar issue with CD audio player destroying a CD. While I haven't had that trouble since then, 20 years old equipment is not that rare in e.g. server or academy environments, so I'd concur with Baard on this one; it doesn't have to be a purely software thing.
    – user201265
    Commented Jan 19, 2015 at 15:01
  • 8
    @Majenko Most people.
    – nanny
    Commented Jan 19, 2015 at 16:10
  • 2
    Back when stepper motor drives ruled, one would (ideally) park the hard drive (placing the heads over a non-writeable cylinder) before shutting down (with physical power switch). Park software would also clear the write caches. Servo drives eliminated that parking need as they added a retract mechanism when power is lost, so you paused a few seconds before power off. The heads will retract to the parking cylinder before the air cushion allows the heads to settle to the surface. It was years after that when we actually got a "soft" power off buttons. Historically it was always a hard power off. Commented Jan 19, 2015 at 17:34
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.

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.

2
  • Why is it that flash drives cannot have such capacitors? Cost?
    – nanofarad
    Commented Jan 20, 2015 at 1:13
  • This feature requires to maintain power supply for 10ms for both NAND chip and internal controller. Higher charge capacity requires higher physical space. This does not fit in an SD card, this definitely does not fit in a microSD card. On USB flash drives, it depends on the actual shape of the flash drive.
    – Jacen
    Commented Jan 20, 2015 at 13:36
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.

3
  • 4
    The power switch on modern PC supplies doesn't directly switch power, it just controls the supply. 'Forced Power Off' (by holding down the power switch long enough) should not be any different from the CPU instructed power down, regarding transients and so forth. And, properly designed modern supplies should not generate dangerous DC transients even if you pull the plug.
    – greggo
    Commented Jan 19, 2015 at 21:44
  • @greggo Correct. In terms of modern power supplies (ATX-24 standard), pulling the plug is the exact same as the computer's motherboard turning the power supply off.
    – AStopher
    Commented Jan 19, 2015 at 22:44
  • I guess there needs to be clarification between the toggle switch on the PS itself and the standby switch on the front of the pc. Yes, the standby switch doesn;t effect power directly but the toggle switch is the same as yanking the power cord, (probably with better hardware filtering in the mechanical parts of the contacts/springs.) Thanks, Greggo, for pointing out that distinction! Commented Aug 12, 2015 at 15:25
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.

1
  • an USB device can (when normally used and not receiving additional power from an other place than the data port) NOT get damaged by pulling it from the system (its a port designed to be 'hot-plugable' you can however lose data if you do due to caches not being written to disk.
    – LvB
    Commented Jan 20, 2015 at 9:55
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)

6
  • 2
    recommend using "." key on your keyboard it is so little thing to use that and your post is so hilarious without it
    – peterh
    Commented Jan 19, 2015 at 16:05
  • 1
    The operating voltages don't matter, you're talking about inductive spikes, high current is the concern there.
    – Samuel
    Commented Jan 19, 2015 at 17:39
  • In modern computers it's not possible to damage the electronics from 'pulling the plug'.
    – AStopher
    Commented Jan 19, 2015 at 22:45
  • @cybermonkey What do you mean by modern? My sister in law killed either the psu or mobo by hitting the switch on a power strip. This computer was built in 2005.
    – user287352
    Commented Jan 20, 2015 at 4:35
  • @cybermonkey I am afraid that is simply not true, you can and it does happen. its not as common as 'in ye olden days' but that is due to better design and safeguards. these do not remove the problem however and there are environmental factors as well as poor (cheap) hardware that causes these problems. or when a system is stretched to the limit these problems occur. It is well known in the data-centers and by server operators that these things matter. only for underutilized 'consumer' hardware would I call 'safe' to just unplug. And that is with the warning that damage can still occur!
    – LvB
    Commented Jan 20, 2015 at 9:52

Not the answer you're looking for? Browse other questions tagged .