Shutting Down Linux

Shutting Down Linux

As clean and stable an OS as Linux is, there are still some gotchas. Similar to Windows, one of those things that you never want to do is to turn off your machine in the midst of a session. Explaining the reason for a proper shutdown procedure also opens an opportunity to talk about how Linux uses system memory.

As with Windows, killing the power on a machine is wrong, wrong, wrong. Linux, like most Unix-like systems, doesn’t immediately send to disk the data that’s written by processes. Instead, that data is temporarily stored, or “cached” in system memory. This process allows the system to cluster a bunch of operations into a single write to the disk. It also allows the system to accumulate writes to consecutive sectors on a disk and then execute them all at once. The idea behind all this is, simply, efficient performance. Most OSs, in fact, utilize similar caching schemes.

The downside becomes pretty obvious once you understand the process. When you kill the power to your box, you also eradicate the disk writes waiting in the cache. The resulting data corruption can be disastrous.

So what’s the proper way to shutdown your finely-tuned Linux system? Most desktop environments offer a GUI option for shutting down. Or, you can jump back into the console and dance again with the command line.

shutdown -r now reboots the system
shutdown -h now halts the system
reboot reboots the system
shutdown -h [number] starts a timer to shut down the system in [number] seconds and sends a console message warning to all users

Any of these options will flush all writes from the cache to the disk before shutting down the machine. And that can mean blissful migraine avoidance.

Article Written by