Posts Tagged ‘root’

Freeing up resources for use by GNU/Linux on your android device

December 7, 2014 1 comment

I had an old samsung galaxy 3(GT-15801) which was lying around unused with a broken screen and decided why not install GNU/Linux on it. If raspberry pi can run raspbian well, then this phone could try to do as well. Have a look at my earlier post here on how I installed debian wheezy on it. While I was able to install and run debian successfully, this phone has only 256 MB of RAM and android uses most of it, there was only 4-6 MB that was free at any time. I removed all the extra apps from installed play store and some bloatware installed on the system partition and kept only the essential ones in case I need it later.

But android always makes use of all the available free memory to make apps open faster and I’m only going use debian on it. I connect remotely to debian on the phone using ssh. But simply killing the running android system processes wont work as android will restart them immediately.

My guide builds on the one used here :

Remember these commands must be run on an adb shell and not to be typed directly on your android device.

Get root on your android device and issue,

stop zygote   #or just stop

This stops the zygote and system server process from running and will not be restarted again automatically. Now if you check the available RAM in your device, you can see more that 50% of it is free. As there is no android’s virtual machine running none of the android apps will run and you will not be able use your device physically. If you still need more memory you can just use the stop command to free up other unused system processes.

To restart it if your want to use android back on the device, just use

start zygote #or just start

In general, issue ps command and look for processes that have its PPID (parent process id) as 1, which means that these processes are started by init as a service. you can get service name for this processes from /init.rc file on android and use stop command to prevent it from running.

Let’s take a look at how to stop mediaserver process for an example.

Filter the output of ps command to look for processes with parent process id 1. Below is the output from my phone, when i grep the ps output to get processes having id 1.

# ps | grep ” 1 ”
root      1     0     272    248   c030f5dc 0000ef8c S /init
system    2164  1     176    116   c050be58 0001264c S /system/bin/akmd2
shell     2165  1     680    316   c03fc378 afd0da1c S /system/bin/sh
system    2166  1     752    296   c0510ed4 afd0dcbc S /system/bin/servicemanager
root      2167  1     3688   580   ffffffff afd0e35c S /system/bin/vold
system    2168  1     1852   336   ffffffff afd0e35c S /system/bin/notified_event
root      2169  1     3672   552   ffffffff afd0e35c S /system/bin/netd
root      2170  1     628    308   c0559cec afd0e67c S /system/bin/debuggerd
system    2172  1     8764   868   ffffffff afd0e67c S /system/bin/drexe
system    2173  1     1036   348   c0292b1c afd0eca8 S /system/bin/npsmobex
media     2175  1     50960  7276  ffffffff afd0dcbc S /system/bin/mediaserver
bluetooth 2179  1     1208   720   c030f5dc afd0eb2c S /system/bin/dbus-daemon
root      2181  1     756    320   c05eba1c afd0da1c S /system/bin/installd
keystore  2182  1     1560   404   c0559cec afd0e67c S /system/bin/keystore
shell     2183  1     3308   176   ffffffff 0000ecd4 S /sbin/adbd
shell     2199  1     308    128   c030f5dc 0000fffc S /system/bin/immvibed
radio     2298  1     14480  2172  ffffffff afd0e35c S /system/bin/rild
root      4282  1     6120   1040  c030f5dc 40419364 S /usr/sbin/sshd
wifi      4333  1     2300   1340  c030f5dc afd0dde4 S /system/bin/wpa_supplicant
root      7823  1     122864 28164 c030f5dc afd0dde4 S zygote
dhcp      9231  1     800    404   c030f5dc afd0eb2c S /system/bin/dhcpcd

From the above output, to stop /system/bin/mediaserver we have to find the service name for the process used by android. To find it, look for the process name in /init.rc file used by init process.

# grep “/system/bin/mediaserver” /init.rc
service media /system/bin/mediaserver

This is my output, when i look for the process mediaserver in /init.rc file. The service name for the process is the second word of the output which is media here. Now to stop mediaserver process just use,

stop media

In general to stop an android service use the format,

stop <servicce-name>

This will stop the service from running. If you need to start a stopped service use the format,

start <service name>

This way more than 60-70 % of RAM can be made available for use by your debian or ubuntu or any other GNU/Linux installed on android and android will not get in your way.

One important thing to note is that if your root access is controlled by an android app like Superuser or SuperSU, to notify or to get permission from user for root access, once zygote is stopped and you exit as root on your shell, you’ll not be able to gain root again without restarting the device, as you stopped the android runtime and your su will fail with segmentation fault without the controlling app running.