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.
Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It only takes a minute to sign up.Sign up to join this community
WARNING: I have not tested this procedure.
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
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!
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.
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
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
/data, but this is mostly what I think you'd want. You can see its progress with
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).