In this guide, I will take you through all the steps on how to shutdown a Raspberry Pi correctly.
As you may have already noticed, there is no button to switch the Raspberry Pi on or off. Your first instinct is probably to pull the power cord, but this is highly not recommended.
There are many reasons why pulling the power cord while your operating system is still running is not a good idea.
Firstly, by pulling the power cord out early, you heighten the risk of your SD card becoming corrupt.
Secondly, anything that is running will not make a graceful exit and save. This forced exit may cause data loss depending on what your Raspberry Pi was doing at the time.
There are more issues that can arise from removing the power cord without first shutting down the operating system, but I am sure you get the point. Incorrectly shutting down the Pi can cause issues.
Luckily shutting down the Raspberry Pi is extremely easy, just see below for all the steps on how to do it correctly.
The Shutdown Command
The easiest way to shutdown the Raspberry Pi correctly is to use a very simple command. You can find the command right below.
sudo shutdown -h now
It will do the following process to ensure the operating system shutdowns gracefully.
1. It will send SIGTERM to all the running processes, so they can save and exit gracefully.
2. After an interval, it sends SIGKILL, so that any remaining processes will be halted.
3. Lastly, it will unmount all the file systems.
4. The screen will now show System Halted.
5. You can now remove the power cord with minimal risk to your Raspberry Pi and the operating system.
6. To start the Raspberry Pi simply plug back in the USB power cord.
There are further ways you can improve on this such as building your own power button by making use of the GPIO pins. I will go into how to do this in the near future.
I hope that this very short but important guide has shown you how to shutdown a Raspberry Pi correctly. If you have any feedback on this tutorial, then be sure to leave a comment below.
How does one shut down a R Pi if there is no screen to view the steps nor keyboard to initiate the steps?
You will need to connect to it remotely using SSH.
Alternatively, you can remove the power cable, but you risk data corruption.
One would assume that you’d SSH into that pi and do the same command to shut it down.
Absolutely the correct way to shut down the RPi. This is one of the reasons why, in my humble opinion, RPi should not be used for industrial purposes. If power fails, and we do not have battery backup, the OS can get corrupted resulting in machine failure. But if a properly designed backup is provided, maybe we can use this. However, this results in increased maintenance – battery backups require monitoring.
Any other thoughts welcome, I am ready to learn.
I disagree, the pi can be and is often used for industrial and commercial purposes, I have over 50 in the field like this, it’s no different from any server having the rug pulled out from under it.
It should be noted that most times on a power failure the Pi will recover fine. I run about 10 Pi’s in the house and do to stupidity, most of them have had a power failure a time or two.
You can also use ” sudo halt ” for an immediate shutdown.
I wish that RPi case manufactures would put at least one push-button ( nice to have would be a three colour LED as well) so one can perform a programmed shutdown.
Once the RPi is shutdown, you could use a On/Off Power Switch to cut the power. This saves wear and tear on the power cord and the port on the RPi.
https://www.adafruit.com/product/3723
Not for EU use. The switch is rated at 120V.
There is a USB Power switch which I have used you a couple of years. It switches the 5V line into the Rpi and so in internationally compatible.