How to Safely Shut Down or Reboot a Raspberry Pi

ampheoampheo
2 min read

To avoid data corruption or SD card damage, you should never just unplug the power from a Raspberry Pi. Instead, use one of these safe methods:


1. Shut Down via Command Line (SSH/Terminal)

A. Immediate Shutdown

bash

sudo shutdown -h now
  • -h = Halt (completely powers off the system).

  • After this, it’s safe to unplug the power.

B. Scheduled Shutdown (e.g., in 5 minutes)

bash

sudo shutdown -h +5  # Shuts down in 5 minutes
  • Cancel with sudo shutdown -c.

2. Reboot the Raspberry Pi

bash

sudo reboot

or

bash

sudo shutdown -r now  # -r = Reboot

3. Using the Desktop GUI (Raspberry Pi OS)

  1. Click the Menu (top-left corner).

  2. Select Shutdown.

  3. Choose Shutdown or Reboot.


4. Hardware Power Button (If Configured)

Some cases have a physical power button connected to GPIO pins.

  • Requires a shutdown script (Python or systemd service).

5. Emergency: If the System Freezes

If the Raspberry Pi is unresponsive:

  1. Ctrl + Alt + Del (if a keyboard is connected).

  2. If nothing works:

    • Cut power (last resort—may corrupt the SD card!).

Important Notes

Always shut down properly before unplugging—otherwise, SD card corruption may occur.
✅ For headless setups (no monitor), use ssh to run shutdown or reboot.
✅ For auto-shutdown (e.g., during power loss), use a UPS (Battery Backup) or a shutdown script.


Quick Command Summary

CommandAction
sudo shutdown -h nowShut down immediately
sudo shutdown -r nowReboot immediately
sudo rebootAlternative reboot command
sudo shutdown -h +10Shut down in 10 minutes

Pro Tip: For automated shutdowns, use cron or systemd timers!

0
Subscribe to my newsletter

Read articles from ampheo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

ampheo
ampheo