Reducing Force shutdown time to 5 seconds

I want to reduce force shutdown time to 5 seconds. When i measured force shutdown time it shows aprox 8 seconds. And also want to know about os data corruption due to force shuy down, is there any work aroud for that?

Any file system with caching will corrupt. A journaled system will try to correct for this, but it does mean some part of the data is lost. You can call sync first, and then if there are no changes, then forced shutdown won’t hurt. Mostly you’d expect there to be changes.

An alternative is to mount the filesystem either in read-only mode (not practical for obvious reasons) or synchronous. Synchronous will imply a big performance penalty, and will also seriously shorten the life of any solid state drive (including the eMMC). Always keep in mind that any time you force write to actual long term solid state memory without using cache life goes down. Write does normally have to occur at the end of a boot, but if you implement this wrong your device may die early.

Perhaps the best workaround compromise might be a command to force remount of the file system read-only, and then shutdown…assuming the remount is fast enough you won’t lose anything…but you are not guaranteed how long the remount would take.

To see all mounted file systems run “df -T”. Most will be in RAM and not a real file system. Those which are ext4 are real file systems and most likely running on the eMMC and the ones you are interested in. To see specifically the ones which are ext4 (and likely there is only rootfs) run “df -T -t ext4”.

If as root you run “mount” with the “remount” option, and also specify read-only, this should occur. See “man mount”. The trick is that anything using this will prevent this from happening…you’d have to be able to find and kill anything using this first…which is part of shutdown anyway.

“fsfreeze --freeze” can stop writing to a disk…but that might also include stopping cache from writing.

A lazy umount might do the job…not sure…there would still need to be some time to flush cache:

sudo umount -l /

Or this probably seems like a solution, but I believe it doesn’t actually work as expected:

mount -f -o remount,ro /

Probably a better way to proceed is to find out what it is you actually need to happen and what you can afford to do in terms of performance or device life. There are no good ways to deal with this, so it is a question of what your particular case actually needs.

That’s the PMIC activity. Most of them can’t programing. You can check the PMIC data sheet for further confirm.

When I shut down the system, most of the time is spent in systemd unwinding a bunch of system processes that don’t really need unwinding.
If you have a working “poweroff” tool, then this script should be able to power off the system fairly quickly without file system corruption:

sleep 0.5
/sbin/poweroff -f

Of course, if you had some other process running which was hoping to write state to disk, that state won’t be written to disk.

(And, yes, multiple sync calls is old UNIX sysadmin voodoo, because some kernels at some point would block a call to sync() until a previous call had completed, meaning that two syncs in a row guarantee that even a large backlog of writes will complete. No idea whether that at all applies these days.)