4

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.

pauldoo
  • 161
  • 1
  • 4

2 Answers2

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.

goldilocks
  • 60,325
  • 17
  • 117
  • 234
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.

wie5Ooma
  • 296
  • 1
  • 3
  • 11