-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfstrim.sh
More file actions
executable file
·78 lines (58 loc) · 2.11 KB
/
fstrim.sh
File metadata and controls
executable file
·78 lines (58 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/system/bin/sh
# Run fstrim on cache, system and data.
# ipdev @ xda-developers
# To Use:
#
# Copy this script to the device.
#
# Run from adb shell (or a terminal app) as root using the sh command.
# sh fstrim.sh
#
# Run from a file manager that is able to execute a script file as root.
# Note: May or may not work depending on the file manager..
# Note:
#
# Currently fstrim is not included in Android.
#
# BusyBox is required.
#
# If BusyBox is not installed.
# This script will use Magisk's BusyBox if it exists.
#________________________________________________________________________________________________________
# Description.
# fstrim is used on a mounted filesystem to discard (trim) blocks which are not in use by the filesystem.
# This is useful for solid-state drives (SSDs) and thinly-provisioned storage.
# Warning.
# Running fstrim frequently, might negatively affect the lifetime of poor-quality devices.
#________________________________________________________________________________________________________
# Running on an Android device?
[ -f /system/bin/sh ] || [ -f /system/bin/toybox ] || [ -f /system/bin/toolbox ] && ANDROID=TRUE;
if [[ -z $ANDROID ]]; then
echo ""; echo " This script needs to be run an Android device."; echo "";
exit 0
fi
# Running as root?
if [ ! "$(whoami)" = "root" ]; then
echo ""; echo " This script needs to be run as root."; echo "";
exit 0
fi
# Run fstrim on cache, system and data.
if [ $(command -v fstrim) ]; then
fstrim -v /cache 2>&1
fstrim -v /system 2>&1
fstrim -v /data 2>&1
elif [ $(command -v /data/adb/magisk/busybox) ]; then
/data/adb/magisk/busybox fstrim -v /cache 2>&1
/data/adb/magisk/busybox fstrim -v /system 2>&1
/data/adb/magisk/busybox fstrim -v /data 2>&1
else
echo ""
echo " The fstrim command is not currently included in Android."
echo " BusyBox is required and not installed."
echo ""
echo " Install BusyBox before running this script again."
echo ""
fi
# Finish script
echo ""; echo " Done."; echo "";
return 0; exit 0;