Proper way to get to a state where power can be removed
I know about the busybox poweroff/halt/reboot, I know about sending an 'o' to sysrq-trigger, but I simply want to get to a state where power can safely be removed.
Busybox (linux syscall) will end up rebooting of course, and by the time I get to the omega2 to pull the power its already back up and running again. The sysrq-trigger will turn the power led off and appears to end up in a while(1) loop. I tried to trace the various paths in source code to figure out what happens with these various methods, but ended up thinking that the sysrq_poweroff_op should be the same result as when using busybox, but that cannot be true, so I'm not following the trail correctly.
Maybe the sysrq-trigger method is ok, but I'm not really sure as I really don't know what is actually happening. Somewhere along the way of testing these things I ended up with an omega2 which I had to reload firmware (garbage files/folders ended up in root folder), and not sure of the cause or when it happened.
I don't care about actually powering off, I just want to get to a state where I can pull the power safely (ssh into omega2, run a script of some kind, get to omega2 physical location a minute or two or three later and just pull the power). If I can also keep the ssh going and also see that I'm in the proper state, that would be nice (instead of doing something, losing ssh, hoping the right thing happened).
Is there some idea I can borrow from the oupgrade process, or anything else that can get me to a state where flash is no longer being written to?
Is something like this ok?
#!/bin/sh #safepower.sh sync sleep 2 mount -o ro,remount /overlay sleep 2 echo Safe to remove power... #blink [S]afe[T]o[S]hutdown echo morse > /sys/class/leds/omega2\:amber\:system/trigger echo STS > /sys/class/leds/omega2\:amber\:system/message echo 150 > /sys/class/leds/omega2\:amber\:system/delay
I'm assuming by remounting /overlay as read-only, no writes can take place, so no possible flash corruption when yanking the power. I'm also assuming this is the only mount point that gets to writable flash.
I expanded on the previous script a little-
I may be the only one who wants this, but if anyone else would like to use/modify this script, feel free. I added the ability to 'cancel' the SafePower mode by just running the script again.
Its possible this turns out to be a bad idea, but it cannot be worse than just pulling the power. I have not tried it, but I imagine running in SafePower mode would also not present much problems as ultimately there just is not a lot of flash writing going on (at least in my case).