3

Assuming that I do not have keyboard or ssh access to my Pi, but I do have physical access. What is the safest way to power it off and preserve the SD card? (This is the case if I've just done a silent install and need to power off the pi, and I don't have a USB keyboard or wifi access configured yet.)

I can imagine a few approaches:

  1. Turn off the power at mains. Maybe this is bad because the 5v power supply will drop relatively slowly, causing bad things to happen electronically. (I am not an electrical engineer)
  2. Unplug the micro usb power plug. Maybe this is better than the above because the power will drop more abruptly.
  3. Eject the SD card first, then power off using 1 or 2 above. Maybe this is good because I see that the contacts on SD cards are different lengths. Maybe this is so that power to the SD card is lost in an orderly fashion as the different pins lose contact in a defined order when ejected.
  4. Some other way I've not thought of.

Edit: I do not believe this is a duplicate of the questions suggested:

In my case I'm talking about when I do not have ssh or keyboard access in order to type shutdown commands such as sudo poweroff. I called out in my question that this is the case immediately after doing a silent install of an OS, and you may not have network configured yet.

In these cases I found I had to uncleanly power off, plug the SD card into another machine in order to edit files in /etc to configure the network, then plug back into the Pi and boot. So, just once or twice I found I had to uncleanly power off my Pi, and I would like to know the safest way of doing that. I think this is a reasonable question to ask, and is different from the suggested duplicates which are about how to switch off your Pi in the normal day-to-day case.

  • I usually make sure the system is fully idle (no flashing SD access light) and only the terminal interface is active, then unplug. If you unplug while the desktop interface is open some nasty things can happen. – TheJamaicanGuy Mar 1 '15 at 20:00
  • Ejecting the SD card each and every time might lead to more trouble. It's been reported that the contacts wear quite fast. – Ghanima Mar 1 '15 at 20:01
  • @Ghanima that's an interesting point I hadn't considered before. – pauldoo Mar 1 '15 at 20:04
  • 1
    None of those. All those options have a risk of critical failure. Pulling the SD card out has the highest. A good way would be to have a script run shut-down when you trigger a GPIO (frankly, that should be a script bundled in RaspBian and the Pi should have at least 1 button that binds to this, or a safe jumper for halt or reset). The least risky is pulling out the plug, but nobody, from any OS endorses this. You can still SSH into the Pi and halt it. If its standalone then you do heartbeats to reboot the system or write a CRON for safe reboots. – Piotr Kula Mar 1 '15 at 21:41
  • 1
    This is a nice answser. raspberrypi.stackexchange.com/questions/6914/… Basically if you pull somwthing out the USB port it will trigger a halt. I vote for that. Hmm.. Goldilocks answer... weird. – Piotr Kula Mar 1 '15 at 21:46
2

I vote #2, just cut the power as quickly and cleanly as possible. Pulling the SD card while there's power does NOT sound like a good idea.

If you cut the power after the system has been totally idle for a few minutes you should not run into too many problems -- just there's no guarantee. Because of that, it's a good idea to add this to /etc/rc.local (presuming you are using raspbian or something similar):

echo '-y' > /forcefsck

[edit Jan/17] I'm not sure if jessie respects this method; for current versions of Raspbian and other systemd based distros instead add this to /boot/cmdline.txt:

fsck.mode=force

You'll probably notice fsck.repair=yes is already there; together these should give you maximum fsck-ness ;) See also man systemd-fsck. Beware that cmdline.txt must remain all one line; separate parameters with a space.

This will force fsck to run on the root filesystem at every boot. It may add 5-10 seconds or more to your boot time depending on how big the fs is, but it will decrease your chances of ending up with an inconsistent filesystem.

Alternately, I have a suggestion here about how to rig the system to shut down properly when you remove something from a USB jack.

  • 1
    raspberrypi.stackexchange.com/a/4722/894 - Why would you suggest pulling SD card if you wrote this? – Piotr Kula Mar 1 '15 at 21:48
  • But he does not suggest that. – Ghanima Mar 1 '15 at 22:00
  • @ppumkin By "sketchy" I meant, "not advisable" or "risky" (as in, "That is one sketchy stretch of road.."). I've clarified that. – goldilocks Mar 2 '15 at 9:20
0

I have run into this problem a few times. So far method #2 never caused damage to the card. Pulling the card seems less ideal because of wearing the contacts. There are a few things you have to consider:
1) I've configured my device to keep log files in memory so the card is less often written to.
2) If you shutdown the device unclean, the device will notice it anyway and keeps complaining about possible damage until you check the file system.

The safest option still remains to shutdown the device as it is supposed to be.

Recently a safe method to shutdown/reset has appeared on the internet. 3 Methods are featured in this article: http://www.linuxuser.co.uk/tutorials/raspberry-pi-reset-switch-tutorial of which one involves some soldering and the other two only use cheap components that are available everywhere and involve no soldering or any type of modification of your device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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