Tuesday, April 11, 2023

Planning orderly shutdown at power removal

LINUX SYSTEM MIGHT BE UPDATING SD DISK WHEN POWER DROPS

The SD Card is a disk drive for the Linux system, as well as containing the various cartridge images that can be 'loaded' virtually into the disk drive. At any instant when power might drop, the system or the cartridge image file may have writes in progress such that with an abrupt stop, the state of the file or file system on the SD Card is corrupted. 

We want to protect against that by having all writes complete and the file system be closed out properly. This is done by issuing the shutdown command to a Linux shell prompt, usually via a terminal window. Shutdown -h now requests that Linux ask all tasks to politely but quickly stop, after which the system itself shuts down. 

PROVIDING TIME TO FINISH AN ORDERLY SHUTDOWN

It will take perhaps one minute for Linux to complete writes to the SD Card, then shut down. I must provide sufficient power to operate at least that long. I plan to install large capacitors that will sustain the supply for that period. 

CAUSING LINUX TO SHUTDOWN WHEN POWER DROPS

I decided to hook up to the HPS side User pushbutton as it is a signal that I can poll easily to discover whether a power failure has occurred. A wire tacked to the high side of the physical switch needs to be pulled down to ground when there is no incoming power to the box (before the capacitors). A MOSFET transistor will do the job nicely.

My program will fire off a process that does nothing but loop watching the HPS User Key signal for it to drop to ground. If it does, the process injects the command shutdown -h now to a shell. 

WAYS POWER CAN DROP WITHOUT WARNING

The operator might have flipped the system power switch off, or pulled the emergency power off knob. The building power might go off due to a utility outage or tripping circuit breaker. Internal power supplies in the 1130 might trip their circuit breaker to stop the power delivered to my box. There are multiple possible scenarios but the solution to all is the same - loan temporary power and ask Linux to shut down properly. 

No comments:

Post a Comment