vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

If RPi gets unplugged, sometimes it stalls during boot

Thu Aug 30, 2018 4:17 am

I am trying to determine the cause of this error. Once in a while there will be a power outage or a circuit breaker will trip and my RPi Zero W will stall on the next boot when power comes back up. It seems the only way I can fix the problem is to unplug it and plug it back in.

I've looked through the logs and haven't found the reason (syslog) but perhaps I don't know where to look. I've determined it stalls somewhere after the default GPIO is setup and connection to the network is established. The boot process is normal and everything is updated and upgraded. It doesn't have anything special installed, just LAMP. The pi mounts a network drive that should be available (most of the time unless the pi with the network drive loses power too). There is a possibility that this is the problem, but how would I go about tracking that down?

I added a sleep 20 in my rc.local file before sudo mount -a to give the server pi some time to get booted and make the drive available.

W. H. Heydt
Posts: 12646
Joined: Fri Mar 09, 2012 7:36 pm
Location: Vallejo, CA (US)

Re: If RPi gets unplugged, sometimes it stalls during boot

Thu Aug 30, 2018 4:22 am

It's likely to be taking longer to run fsck (file system check).

LTolledo
Posts: 3424
Joined: Sat Mar 17, 2018 7:29 am
Location: Anime Heartland

Re: If RPi gets unplugged, sometimes it stalls during boot

Thu Aug 30, 2018 6:19 am

and usually automatically reboots itself (at most) 1 time.
then rechecks the volume again.

If you're using the desktop version and set it by default you might get the impression that it is stalling
but if you disable Splash screen during startup (can be set via Raspberry Pi Configuration menu, or raspi-config) you will see the boot-up sequence, and see where it is stalling.
"Don't come to me with 'issues' for I don't know how to deal with those
Come to me with 'problems' and I'll help you find solutions"

Some people be like:
"Help me! Am drowning! But dont you dare touch me nor come near me!"

vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

Re: If RPi gets unplugged, sometimes it stalls during boot

Fri Aug 31, 2018 1:43 am

It is a headless Pi Zero W on Raspbian Lite, so no desktop or VNC and a Mini HDMI port (and I don't have an adapter) so there's really no way to actually "see" what's going on. It's why I've fallen back to the logs. It stalled again today though when I pulled out the plug (without instructing it to shutdown). The network drive was online at the time, so perhaps this isn't the problem.

epoch1970
Posts: 5131
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: If RPi gets unplugged, sometimes it stalls during boot

Fri Aug 31, 2018 8:01 am

If you encounter a lot of power events, it would be preferable to run the system off RAM as much as possible (and hosting the DB there might not be the best idea). Otherwise filesystem corruption will arise and if you’re unlucky enough your SD might even die/turn read only due to unexpected power loss.

It looks like you can install and run LAMP on piCore (Tiny Core Linux) for example. This OS is a bit different from Debian/Raspbian. It is designed to run mostly/completely off RAM once booted.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

Re: If RPi gets unplugged, sometimes it stalls during boot

Fri Aug 31, 2018 3:54 pm

I'll do some more investigation through the logs and try to recreate the event. It's always exciting trying to debug.

tpylkko
Posts: 409
Joined: Tue Oct 14, 2014 5:21 pm

Re: If RPi gets unplugged, sometimes it stalls during boot

Sat Sep 01, 2018 10:35 am

The most likely candidate is fsck, like mentioned earlier, because you are doing an unclean unmount when you pull the plug and Raspbian does a fsck on the disks. This takes some time. If you wait a bit longer it might come up. Or you can check for entries in journalctl (but may need to make the logs persistent if you are not patient enough to wait.

The other option is that there is already some level of corruption or hardware failure (sd card) and since the boot sequence is not identical (parallelism and all that) , it hangs only at times, but not other times..

Pulling the plug constantly is not wise. If you need to shut down a headless machine at times without having the change to log in (via ssh/vnc or whatever), then you could for example make a shutdown service that is run at some event managed in a udev rule (say plug in a usb stick). There are tutorials for this all over the net. Or use a button. or a serial connectionl, or run from RAM, a watchdog, or even do periodic reboots. Anything else than pulling the plug.

vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

Re: If RPi gets unplugged, sometimes it stalls during boot

Sat Sep 01, 2018 2:36 pm

I didn't realize the risk involved with pulling a plug. I don't intend on pulling the plug ever or doing any sort of scheduled reboots, etc but I'm in the middle of developing a project.

I am planning to put a battery in between the power supply and the pi so even if there are power interrupts the RPi still stays live.

I'm just thinking out loud, but there may be extended power interrupts. Perhaps the solution to this issue is a voltage sensor before the battery? If the voltage drops below charge level, the RPi can set itself for shut down if it occurs?

Return to “General discussion”