How Do You Properly Shut Down Your Raspberry Pi? (8 Best Tips)
Unlike an actual laptop, a Raspberry Pi doesn’t come with a power switch built into the board. Consequently, some Raspberry Pi users (including me) would just pull the power cord to power off the Raspberry Pi. However, as I got more experienced, I realized this was a bad thing to do. Now, you may be wondering: “Why can’t you pull the plug on your Raspberry Pi?”
Removing power from your Raspberry Pi is a brute force method of shutting down your Raspberry Pi, and it can be bad for your device. For instance, if your Raspberry Pi is in the middle of writing to your SD card and you shut it down, the SD card will become easily corrupted (or useless). Moreover, if your device was processing data, and it was abruptly turned off, the data will be lost.
If you want to know if your Raspberry Pi can read your SD card or not, then you’ll need to check its lights. I made a Raspberry Pi lights guide that can help you troubleshoot this issue and other ones like power problems.
For the rest of the article, I will go over 8 different ways you can shut down your Raspberry Pi properly.
8 Ways To Properly Shut Down Your Raspberry Pi
For methods 1-7, you’ll need to open up the terminal in your Raspberry Pi or SSH into Raspberry Pi.
If you want to learn how to use SSH and avoid any issues you might encounter using it, then you need to check out my SSH guide for Raspberry Pi!
1. Halt Command
sudo halt
This command will halt your Raspberry Pi system, and it’s a shorthand for method number 2. The keyword “halt” tells the hardware components on your Raspberry Pi to stop all CPU (Central Processing Unit) processes.
2. Shutdown & Halt Command
sudo shutdown -h now
This command will shutdown your Raspberry Pi the moment you press enter. Moreover, the “-h” is shorthand notation for halt, which means all CPU functions also stops.
Here’s a behind the scene glimpse of what actually happens when you enter this command:
- The SIGTERM signal will be sent to all the processes that are still running. This basically lets them know that they need to finish what they’re doing since the system is shutting down.
- After a while, the SIGKILL signal will be transmitted, which means that any of the processes that are still remaining after they’re given a warning by the SIGTERM signal will be forced to be stopped.
- SIGKILL is different from SIGTERM because SIGTERM’s signal can be blocked, ignored, or handled whereas SIGKILL’s signal cannot be ignored or blocked.
- Next, the system will unmount all the file systems. Unmounting is basically where the system ejects the external storage device that’s inserted into the Raspberry Pi.
- Finally, you can unplug your Raspberry Pi since it’s properly turned off.
3. Power Off Command
sudo poweroff
The keyword “poweroff” transmits an ACPI (Advanced Configuration and Power Interface) signal to the system, which tells it to power down. The ACPI basically gives power management control to the operating system.
4. Shutdown Command
sudo shutdown
This command (like poweroff) will shutdown your Raspberry Pi. However, it will only do so after 1 minute has passed, which gives you the opportunity to cancel it if you change your mind.
To cancel the shutdown, you need to type in the following command:
sudo shutdown -c
This command will cancel the shutdown since the “-c” is a shorthand notation for “cancel”.
5. Shutdown Now Command
sudo shutdown now
This command has two components: the “shutdown” keyword tells the system to shut down in a secure and graceful manner, and the “now” keyword demands the shutdown to happen at the exact moment you hit the enter key to put the command into action.
6. Shutdown (At Set Time) Command
sudo shutdown -h 05:00
This command is great for shutting down your Raspberry Pi at a specific time. In the example above, the code tells the Raspberry Pi to shut down at 5 am. Remember, the terminal uses the 24-hour clock system. This means that if you want to shut down your Raspberry Pi at 11:00 pm, you’ll need to replace “05:00” with “23:00”.
7. Shutdown Timer Command
sudo shutdown -h 30
This command is great for shutting down your Raspberry Pi in a set amount of time. In the example above, the code tells the Raspberry Pi to shut down 30 minutes after the user presses enter. Remember that this is in terms of minutes, so if you want the Raspberry Pi to shut down in 2 hours, you’ll need to replace “30” with “120”.
8. Shutdown Using Desktop GUI
Now, if you don’t feel like memorizing these commands or if you don’t like using the terminal, you can directly use the Raspberry Pi’s Desktop GUI (Graphical User Interface). Here are the 3 simple steps to help you get started:
- Open the start menu (click on the Raspberry Pi icon on the top left corner of your screen)
- Click on “Logout”
- Finally, click on “Shutdown”
Note: The other two options are “Reboot” and “Logout”. “Reboot” basically shuts down your Raspberry Pi and turns it on again. “Logout” will sign you out of your account and another user can sign in.
Summary – tl;dr (Too Long; Didn’t Read)
Here are some of the key takeaway points you’ll need to keep in mind after reading this article:
- You can’t just pull the plug on your Raspberry Pi. It will corrupt your SD card if you’re in the middle of writing to it and/or the data that’s being processed will be lost.
- Consequently, you’ll need to pick 1 (or more) of the following 8 methods to safely turn off your Raspberry Pi
- Use the halt command:
- sudo halt
- Use the shutdown and halt command:
- sudo shutdown -h now
- Use the power off command:
- sudo poweroff
- Use the regular shutdown command:
- sudo shutdown
- Use the shutdown now command:
- sudo shutdown now
- If you want to shutdown your device at a specific time:
- sudo shutdown -h 05:00
- If you want to shutdown your device after a specific amount of time:
- sudo shutdown -h 30
- Do it directly on the Desktop GUI
- First, click on the start menu (the Raspberry Pi logo on the top left corner of your screen)
- Secondly, click on “Logout”
- Finally, click on “Shutdown”
- Use the halt command:
In the end, I hope this article was informative and didn’t turn you off!