Why is it not recommended to shut down a computer "brutally" (power switch)? [duplicate]
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)?
Solution 1:
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.
Solution 2:
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.