2

When is it safe to switch off the power supply to the pi after it was halted?

I am using ssh to access my Pi (runs Raspbian), and sudo poweroff to shut it down (the wifi dongle keeps blinking for a good 10-15 seconds after that). However I am not sure when exactly its safe to switch off the power after to prevent any possible SD card damage.

Is there any way to tell? For example when both lights stop blinking, etc?

4 Answers 4

4

Rpi's green light flashes for 10 times (It may be only true for raspbian, not sure about other OSes) with a regular interval before getting completely turned off. So, you should wait for that.

(Source : Experience)

8
  • OK, I just done that and it seems it ran a fsck on boot: dosfsck 3.0.13, 30 Jun 2012, FAT32, LFN /dev/mmcblk0p1: 53 files, 2427/7161 clusters
    – YemSalat
    Commented Jun 21, 2015 at 17:56
  • Make sure that both the file systems were clean before. If I remember old dosfsck utility was unable to clear dirty bit and hence it would not be effective. (link : raspberrypi.org/forums/viewtopic.php?f=28&t=61879) Solution : Use a linux box with updated fsck utility. Check both the partitions by "sudo fsck.fat -trawl /dev/mmcblk0p1" and "sudo e2fsck /dev/mmcblk0p2". Unmount them properly and then run a test. Hope it helps. Commented Jun 21, 2015 at 18:06
  • If you're unable to do it on a linux box, here is a quick solution. Follow this post to dosfsck tools on Rpi. raspberrypi.org/forums/viewtopic.php?p=504636#p504636 Don't forget to install those tools by "sudo make install" (Install step is not mentioned in the guide) Commented Jun 21, 2015 at 18:12
  • @YemSalat Did you try it ? Did it work ? Commented Jun 28, 2015 at 9:30
  • yep it seems to work, but it still writes to fsck log on every boot, I'm not sure if this is normal behaviour.
    – YemSalat
    Commented Jun 28, 2015 at 17:06
1

As a rule of thumb, as soon as the display turns off, your Raspberry Pi is safe to disconnect from the power source.

If you are still not satisfied, leave it for around 30 seconds before disconnecting the power just to be on the safe side.

2
  • I am using ssh, don't have no display. I heard that when both leds light up - it means its booting, so that would be too late to turn it off I guess? do you know if thats true?
    – YemSalat
    Commented Jun 21, 2015 at 15:32
  • The green light blinks but then stays on for me permanently after issuing a shutdown and no longer responds to ssh requests. [ Raspian on Pi 3 ] So, I'm assuming that blinking and then transitioning to solid green means it's safe to power down. Commented Mar 19, 2016 at 6:03
0

I'm not sure you can accept this as an answer, but maybe you need to know what happens when the pi is powered off as by disconnecting the power with a mechanical switch. For my purpose I needed this approach, so I gave it a try recently.

I placed the switch between the 5 volt cable. I didn't get in trouble after about 50 times toggling between "on" and "off".

Also I tried to switch on/off with really quick intervals, specifically when the file systems were being mounted.

After each "power off" without issuing

shutdown -h now

the 'dirty bit' was discovered by fsck at the subsequent new boot, and this bit was nicely fixed when the above command was used.

So, my conclusion from practical experience is that it seems safe to power off the PI by disconnecting it from power.

I'm curious what others have experienced, and if the PI is actually designed for this kind of brute force power off.

Having said all this, I think it is best practice (and best education too) to let any system have a decent way of dealing with its logic and current operations, before the power that makes the system possible in the first place gets interrupted. Information might get lost or corrupted otherwise.

Thanks for asking the question

3
  • 2
    I think you misread the question -- the OP is asking about when the proper shutdown has completed, not about whether it is okay to not bother with. I agree w/ you that it is not a huge risk to kill the power, at least if the system is fairly idle (except you will then have to wait an extra 10+ seconds for fsck when it boots again) -- but probably not worth making a habit of when you don't have to.
    – goldilocks
    Commented Jun 21, 2015 at 16:01
  • I've heard many times that it can significantly lower SD card's life expectancy. I think its best to avoid 'brute force' shutdowns.
    – YemSalat
    Commented Jun 21, 2015 at 16:48
  • I know this answer is a bit old, but I feel compelled to share my experience. I have killed at least 10 SD cards (actual hardware faults, not just corrupted filesystems) by having an unexpected power outage on a Raspberry Pi. I completely disagree that it's somehow "safe" to pull the power. A proper shutdown is essential.
    – davidA
    Commented Mar 20, 2021 at 9:07
0

So you have ssh connection but do have a visual on the leds? If you are using ssh the network connection is lost before shutdown completes. You'll notice that the network connector leds stop blinking before the green led on the board stops.

Some processes might take real time before they are actually stopped after shutdown has send them the TERM signal. Although the TERM signal is send before the network is brought down, some processes might still being busy to stop. Therefore it is difficult to know exactly on beforehand what the last blink of the onboard green led will be.

If you want to be sure not to lose data of jobs you started yourself, you'll need to quit these in a proper way before the shutdown. Other jobs are better keeping care of by the shutdown process.

I guess waiting about 5 seconds after the last green blink is safe for a new boot. If you see a 'dirty bit' report during boot, you know that you have powered off too quickly. You can check the file /var/fsck/checkfs whether dirty bit was set or not.

Dastaan has the same experience as I have, 10 times green blink seems to indicate that shutdown completed, but I haven't found any documentation about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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