Is it possible to run fstrim in stock android 4.3 from adb shell?
I understand it runs every 24 hours when the device is plugged in and idle but I would like to run on demand to test a few theories.
Is it possible to run fstrim in stock android 4.3 from adb shell?
I understand it runs every 24 hours when the device is plugged in and idle but I would like to run on demand to test a few theories.
WARNING: I have not tested this procedure.
You would need to have fstrim
in system/bin
. This XDA post has a DropBox download link.
start up adb
and then switch users to root.
$ adb shell
from your os terminal.
$ su
to switch to the root user.
To copy fstrim to your /system/bin
path you first need to mount the system path as Read/Write from adb or some other file manager
# mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system
to mount /system as R/W
Then copy fstrim
to the system path.
# cp <pathtofstrim>/fstrim /system/bin
Next you need to change permissions of fstrim to include execute.
# chmod 766 /system/bin/fstrim
to make fstrim executable by root
After setting the correct permissions on fstrim
you can run these commands from adb (as root):
# fstrim -v /data
# fstrim -v /cache
# fstrim -v /system
OR, you could go the EASY WAY. Install the LagFix app, and trigger fstrim on demand, provided your device has fstrim support!
LagFix
and if anyone can find an official fstrim bin that would complete the answer.
– hoss
Aug 12 '13 at 16:15
On newer versions, Android runs fstrim
with a daily schedule, provided that the conditions meet. Or it should run on a reboot if not run for 3+ days. See this answer for details.
However if you want to do TRIM
manually, use Android's commandline tool sm fstrim
. Previously this was vdc fstrim dotrim
but added to Storage Manager in Oreo (1) and removed from vold
in Pie (2).
In order to send FITRIM ioctl
to selected filesystem(s) only, use fstrim
tool; a busybox applet.
Both commands require root, or sm fstrim
can be executed from adb shell
.
vold, the (disk/eMMC) volume management daemon, has this built in. Its shell client is called "vdc" (vold controller I guess, akin to rndc, remote name daemon controller for BIND). The command and its relevant arguments, as the superuser, would be:
vdc fstrim dotrim
Note that at least on my tablet, 4.4.4, this will only trim /cache
and /data
, but this is mostly what I think you'd want. You can see its progress with logcat
(e.g., logcat
from a shell on the device or adb logcat
on a USB connected host). Vold will output a message about each volume it trims and the fact that it's finished (in logcat).