31

I'm looking for the best / friendliest way to reboot my rooted android 4.1.1 device. I found these solutions so far:

  • su -c "reboot" - Causes problems with wifi after restart on my device... I read that this can cause a currupt file system in some cases... Doesn't work via ssh for me.
  • toolbox reboot - Same concerns here, but works via ssh.
  • reboot -d 8 -f - causes problems after restart e.g. some apps wont start
  • busybox killall system_server - "Hot Reboot" (not really a system restart)
  • start|stop - Starts/stops Android Runtime (not really a system restart)

What is the device doing exactly when I'm pushing the (hardware) power button? I guess that's the most friendly way.

2
  • su -c "reboot" runs the reboot command, which is defined in reboot.c. reboot.c hasn't changed much over the years. It has always called sync() and then rebooted the device. Also, thanks to this commit, modern versions of reboot.c also unmount all filesystems. Android 4.1.1 includes the commit I mentioned, and so I don't see how su -c "reboot" on Android 4.1.1 could ever cause filesystem corruption. Commented Dec 14, 2015 at 1:45
  • Dear acy: Firelord's late answer (su -c 'am start -a android.intent.action.REBOOT') works for me on Android 4.1.2, and seems to me to be the best of the existing answers. If it works for you on Android 4.1.1, or if you're too busy to try it, please click the green checkmark in order to make it float to the top of the answer section. Commented Jun 5, 2016 at 23:19

3 Answers 3

17

What is the device doing exactly when I'm pushing the (hardware) power button? I guess that's the most friendly way.

You get to see a dialog with an option to power off the device (stock Android doesn't offer reboot). It appears that ShutdownActivity is called upon when you long press Power button.

Anyhow, this is what you can try, remotely or locally, but only with root access:

su -c 'am start -a android.intent.action.REBOOT'

It will do a graceful shutdown followed by the reboot. I was looking for an intent when I noticed it here.

Method is tested on Android 4.2.1, 5.0.2 and 6.0.1 and should work for Android 4.1.1 as well

Update

Tested on stock Android 5.0 and 6.0.1:

su -c 'svc power reboot'

Per the source code here, KitKat builds should also support the command.

1
  • 1
    Exactly what I needed. I still do find it odd that it says "Powering off..." when there are values for the reboot text.
    – Allison
    Commented Mar 12, 2016 at 17:13
14

Simple, really:

  • Android is safely shutting down vital parts of the runtime.
  • The OS is also broadcasting intents to tell apps and services to gracefully close. These, in turn, flush their caches of all data and shared preferences, save what-nots to the sqlite database, et cetera.

In other words, apps and services are given a chance to do their cleanup systematically.

The commands that you have tried are harsher. They actually bypass the safety mechanisms for a graceful shutdown.

Android is not Linux per se, in the sense of an ordinary desktop version of Linux where those commands could be issued to shutdown the Linux environment.

It might be possible to create a wrapper script such as this:

#!/system/bin/sh
am broadcast android.intent.action.ACTION_SHUTDOWN
sleep 5
reboot

You could save this as safe_shutdown.sh, with permissions of 0755. Your mileage may vary, depending on handsets and ROMs — so no guarantees there.

10
  • 1
    thanks for this explination! is it possible to do this remotely e.g. via ssh (not adb)?
    – acy
    Commented Apr 15, 2013 at 16:12
  • 4
    I think he want's to know how he can mimic the button shutdown with a command.
    – Flow
    Commented Apr 15, 2013 at 16:14
  • if that's the friendliest/safest/best way to shut down the device, then yes :)
    – acy
    Commented Apr 15, 2013 at 16:17
  • @Flow adb reboot? I am not certain if that's safe!?! Maybe a wrapper script around it to send a broadcast ACTION_SHUTDOWN then call adb reboot?
    – t0mm13b
    Commented Apr 15, 2013 at 16:18
  • Not sure broadcastingACTION_SHUTDOWN will do what you want either: "Apps will not normally need to handle this, since the foreground activity will be paused as well." Sounds like most apps therefore won't handle it. Is pausing the activity sufficient? Commented Apr 15, 2013 at 21:28
11
killall zygote

This will kill the root zygote process and cause a Android system refresh.

This does not restart your phone's hardware, only the Android processes.

By default (in Linux), the kill/killall commands do give the processes a graceful way to shut down, though it depends on the zygote implementation whether this in turn gracefully shuts down your running Android apps.

Note: you must run this as root, whether you use su -c, connect via SSH or ADB, or another method.

Other names for this action:

  • soft reboot
  • hot reboot
3
  • I have noticed on some devices, the Wifi will not reconnect properly after this command (so I have to disable the Wifi, wait a minute, and then re-enable the Wifi again).
    – palswim
    Commented Mar 18, 2015 at 20:55
  • 2
    For readers: In Lollipop, the standard way to restart the Android framework is am restart. This requires root access though.
    – Firelord
    Commented Nov 28, 2015 at 7:49
  • Does killall zygote give processes a graceful way to shut down? Interesting question. Someone would have to look at the zygote source code in order to know. Commented Dec 18, 2015 at 13:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .