I am using juice4halt (a small super-capacitor UPS) on my Raspberry Pi, but I found out that the amount of time halt is taking is too long, and so the system will poweroff because of undervoltage.

So my goal is to shutdown the system as fast as possible, best would be 5 seconds.

My idea is having a script that does this, that does save only the important stuff onto persistent storage:

sudo service mysql stop
halt -f

My questions are:

1) Is this safe? Will sync wait until the changes are sync'ed, or will the sync be invoked, and halt -f will interrupt it?

2) To debug/verify that everything works, is there a command that shows if there are buffers that have not been written to disk?

System: Linux ras3 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux


the commands you posted will be executed one by one, not in parallel, so halt will execute only after sync completed.

if you added & to sync, so

sync & 
halt - f

sync would work in background and coukd not finish in time, as halt would run at the same time.

summing up, you're safe with sync executing in full before halt is invoked.

NOTE: It's not common to manually invoke sync. Most often, this command is run before you execute some other command that you suspect could destabilize the Linux kernel, or if you believe that something bad is about to happen (e.g., you're about to run out of battery on your Linux-powered laptop) and you don't have time to execute a full system shutdown.

When you halt or restart the system, the operating system automatically syncs data in memory with persistent storage, as needed.

  • 3
    I know that they are executed one by one. This is exactly what I want. My question is, if "sync" waits until all disks are sync'ed, or if sync just tells the kernel to do so, and immediately returns. Jun 13 '19 at 21:11
  • 2
    yes, it will wait. note I've edited my comment, added some info that might be useful for you.
    – Bart
    Jun 13 '19 at 21:12
  • Note according to the question, the OP believes that something bad is about to happen (i.e, they are about to run out of battery/capacitor) and they don't have time to execute a full system shutdown. Jun 13 '19 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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