Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

Should I just pull the plug? Or is it best if I exit LXDE and any other running processes first?

share|improve this question
13  
Of course I turn off my Pi properly every time... cough –  berry120 Jun 18 '12 at 10:56
3  
sudo halt -p will do it. –  Thorbjørn Ravn Andersen Aug 1 '12 at 22:07
2  
i'd love to see a "how-to" for a hard button connected to GPIO to tell the OS to shutdown. –  user5570 Jan 23 '13 at 5:12
4  
People who are just pulling power out from under their Pi's should really stop doing that. I've had two full Rasbian installs start kernel panicking because of corrupt file systems from improper shutdowns (eg. pulling the power). I had to re-image the card in both cases and re-do all the work I put in to configure it. –  tavis Apr 1 '13 at 22:55
add comment

10 Answers

up vote 90 down vote accepted

You definitely don't want to just pull the plug this can cause problems with the SD Card and filesystem.

From the command line or a terminal window you can enter the following to do a clean shutdown:

sudo shutdown -h now

or from the LXDE GUI

click the shutdown button (red power button) in the menu bar at the bottom right corner of the screen. then click shutdown.

Once it says "system halted" you can remove the power cord if needed

share|improve this answer
add comment

It's best to always shutdown correctly if you can.

Constantly unplugging the device without shutting down gracefully may have undesireable effects on the SD card (a temperamental object already).

For reference, to shut down from the terminal you can use:

sudo shutdown -h now

or

sudo halt

These commands send SIGTERM to all running processes, notifying them to save their data and exit. It then sends SIGKILL to all remaining processes to halt the system, followed by finally unmounting all filesystems. The screen will then show System Halted and you can pull the plug.

share|improve this answer
3  
sudo poweroff also works just fine. –  Nilpo Jun 24 '12 at 6:19
    
Out of interest, what's the difference between halt, shutdown, and poweroff? –  ACarter Jan 7 '13 at 20:54
1  
@ACarter There's no difference, they all switch the system to runlevel 6. –  Jivings Jan 7 '13 at 22:46
    
Its not exactly the same: aplawrence.com/Linux/halt_shutdown_reboot.html –  Anake Jan 11 '13 at 13:50
    
@Anake Used as described above, yes they are. –  Jivings Jan 11 '13 at 18:20
add comment

Other considerations aside, the power, and other, connectors will be designed for a limited number of insert/disconnect cycles. Often this is a surprisingly low number.

Statistically connectors are a very likely source of equipment failure.

With a view to the overall longevity of your Pi, you might want to moderate the number of connector insert/disconnects it experiences. One way of helping to do this would be to use the mains supply socket's on/off switch.

share|improve this answer
    
So what is the suggestion? Turn the Raspberry Pi off by disconnecting the power supply from the mains (thus reducing the number of insert / remove cycles to the connector on the device)? I find your answer regarding probability of connector failure very interesting. Can you back it up with links to any evidence? Thanks. –  Andrew Fogg Jun 20 '12 at 12:25
2  
@AndrewFogg It's a well know factor in equipment design in Electrical Engineering. In the general case, electronic components do not experience the same degree of mechanical forces as connectors do. Manufacturers mating lifetimes, as you might expect, for connector are obtained in favourable conditions so are often optimistic and do not account for real life human usage.Check data sheets, Edge connectors - 50-100 insertions, RJ45 500-1000 insertions, Micro-USB 5000-10000. So yes, you are correct, turning off at the wall socket is the best choice. –  image_doctor Jun 21 '12 at 7:49
    
Please add the suggestion to your answer. You and I came to the conclusion, but other may not see the implications. –  Bengt Jun 23 '12 at 21:16
    
Also what about switches? Are they designed for more on/off-circles? Would it be a good idea to place a switch on the AC-side of the power supply? –  Bengt Jun 23 '12 at 21:18
2  
If it's reachable (and not going into an even more expensive piece of equipment such as a desktop/laptop) I do find it often preferable to plug-cycle the USB "A" end of the cable. Cables are cheap to replace, and the "A" end generally plugs and unplugs more easily without requiring you to firmly grab the board with your fingers. –  Chris Stratton Aug 1 '12 at 17:51
add comment

Raspberry Pi Shutdown Switch – Safely Turning off the Pi

http://www.3cc.org/blog/2013/01/raspberry-pi-shutdown-switch-safely-turning-off-the-pi/

I followed the project above but set pin 17 to be internally pulled up. Then connect the wires like the above project but leave out any resistors and add the following python script in /etc/rc.local python shutdown_button.py

shutdown_button.py :

import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP)
while True:
    print GPIO.input(17)    
    if(GPIO.input(17) == False):
        os.system("sudo shutdown -h now")
        break
    time.sleep(1)
share|improve this answer
add comment

I've used that shutdown.py solution too.

You'll still need to find a physical switch and solder it to pins 6 and 8 of header 5. I took mine from an an old broken Arduino board. I've also drilled a small hole in the case to make sure that I can push the button with a small wooden pin when the case is closed.

This is how it looks like: enter image description here

share|improve this answer
add comment

To avoid the SD card corruption issues you should always shut down the OS properly, you can automate this by using a power controller hardware solution and a script that is triggered through a GPIO port signal, for example (in addition to the Pi Supply mentioned above) :

The RemotePi Board in the last link has the added functionality of using IR remotes to power on/off the RaspberryPi.

share|improve this answer
add comment

You don't really need a power switch for your raspberry. I use a usb hub for power supply that has on/off switches. So, whenever i want to turn off RPi, i just turn the usb switch off.

share|improve this answer
7  
It is not a good idea to just power of the Pi - YOu could risk data loss or corruption in sudden power downs. Better to always shut down as intended. for example - FreeNAS (based on FreeBSD) is safe to do that because the root is readonly; But, because it is a NAS! data can be lost while writing to your hard drives.. So end of day. Always use implemented shutdown methods! –  ppumkin Nov 1 '12 at 16:43
add comment

There is also a GPIO board called the Pi Supply that has an on switch, power management and hard off for lock ups. Also useful if your plug is behind the TV and hard to get to. You still need to shut down normally but it then powers off the Raspberry Pi. Info Here

If your concerned about wearing the power micro usb port out in normal usage you can get a male to female usb adapter and plug your power supply in to that.

share|improve this answer
add comment

I believe you want to use GPIO 17 (pin 11) not pin 17.

"I followed the project above but set pin 17 to be internally pulled up."

share|improve this answer
add comment

This is not very hard. Go into the command prompt, and type sudo halt. Enter your password if needed. Once there is nothing on the screen, pull the plug.

Info from the Raspberry Pi website.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.