Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade

How to Safely Shutdown Your Raspberry Pi

Properly shutting down your Raspberry Pi is crucial to avoid data corruption and ensure the longevity of your device. Unlike traditional computers, simply unplugging the Raspberry Pi can lead to file system corruption, which may render your SD card unusable. This article will guide you through the correct methods to shut down your Raspberry Pi safely using command-line instructions and physical buttons.

Examples:

  1. Shutdown via Command Line: The most straightforward way to shut down your Raspberry Pi is through the command line. Open a terminal window or connect to your Raspberry Pi via SSH and use the following command:

    sudo shutdown -h now

    This command will halt all processes and power down the Raspberry Pi immediately.

  2. Scheduled Shutdown: You can also schedule a shutdown for a specific time. For instance, to shut down your Raspberry Pi in 10 minutes, use:

    sudo shutdown -h +10

    This command schedules a shutdown 10 minutes from the current time.

  3. Shutdown via Physical Button: If you prefer a physical method, you can set up a button to safely shut down your Raspberry Pi. Here’s how you can do it:

    • Hardware Setup:
      • Connect a momentary push-button to GPIO pin 5 (GPIO 3) and ground.
    • Software Setup:

      • Create a Python script to monitor the button press and initiate a shutdown.
        
        import RPi.GPIO as GPIO
        import time
        import os

      Set up the GPIO pin

      GPIO.setmode(GPIO.BCM) GPIO.setup(3, GPIO.IN, pull_up_down=GPIO.PUD_UP)

      def shutdown(channel): os.system("sudo shutdown -h now")

      Add event detection on the button

      GPIO.add_event_detect(3, GPIO.FALLING, callback=shutdown, bouncetime=2000)

      Keep the script running

      try: while True: time.sleep(1) except KeyboardInterrupt: GPIO.cleanup()

      - Save this script as `shutdown_button.py` and run it at startup by adding it to `/etc/rc.local` before the `exit 0` line:
      ```bash
      sudo nano /etc/rc.local

      Add the following line:

      python /path/to/shutdown_button.py &

By following these methods, you can ensure that your Raspberry Pi shuts down safely without risking data corruption.

To share Download PDF

Gostou do artigo? Deixe sua avaliação!
Sua opinião é muito importante para nós. Clique em um dos botões abaixo para nos dizer o que achou deste conteúdo.