-
Notifications
You must be signed in to change notification settings - Fork 2
/
trimly.sh
61 lines (52 loc) · 2.96 KB
/
trimly.sh
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
#!/bin/bash
# Copyright (c) 2023 Alex313031
## TrImLy
# trimly.sh
## VER. 0.5.2
# constants (for coloring stdout)
YEL='\033[1;33m' # Yellow
CYA='\033[1;96m' # Cyan
RED='\033[1;31m' # Red
GRE='\033[1;32m' # Green
c0='\033[0m' # Reset Text
bold='\033[1m' # Bold Text
underline='\033[4m' # Underline Text
NC='\033[0m' # No Color
#start
printf "${RED}--------------------------------------------------------------------------------${NC}\n"
printf "\n"
printf "${RED}== TrImLy - Your fstrim automator and defrag script for ChromiumOS ==${NC}\n"
printf "\n"
printf "${RED}Note: This script must be placed in /usr/local/bin,\n made executable with 'sudo chmod +x trimly.sh',\n and run with sudo (root) priveleges.\n"
printf "\n"
# conditional defrag (*will not work entirely on bind mounts used on /)
printf "${YEL}You may optionally run e4defrag -v on the stateful_partition and root (/), note this will take some time, and\n is not needed very often on SSDs, but one should use this if installed to an HDD, as ChromiumOS has no auto-defrag. \nPlease answer 1 or 2.▼${NC}\n"
printf "\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "\n" && printf "${YEL}Defragmenting HDD...${NC}" && printf "\n" && e4defrag -v /dev/sda1 && printf "\n ${RED}Continuing...${NC}" && printf "\n"; break;;
No ) printf "\n ${RED}Continuing...${NC}" && printf "\n"; break;;
esac
done
# conditional trim (for SSD performance and longevity)
# -run fstrim on all relevant partitions and mount points.
# -mount rootfs to temp dir and fstrim them.
printf "\n${YEL}You may now optionally run fstrim on all relevant partitions, mount points,\n and the two rootfs partitions A and B. Note that the time for completion\n depends on SSD size/speed, and the amount of deletions made since last trim. \nPlease answer 1 or 2.▼${NC}\n"
printf "\n"
select yn in "Yes" "No"; do
case $yn in
Yes ) printf "\n" && printf "${YEL}TRIMming SSD...${NC}\n" && fstrim -a -v && fstrim -v /mnt/stateful_partition/encrypted && fstrim -v /usr/share/oem && fstrim -v /mnt/stateful_partition && fstrim -v / && mkdir /rootfs_A && mount /dev/sda3 /rootfs_A && fstrim -v /rootfs_A && umount /dev/sda3 && mkdir /rootfs_B && mount /dev/sda5 /rootfs_B && fstrim -v /rootfs_B && umount /dev/sda5 && printf "fstrim -v completed successfully with status code 0" && printf "\n"; break;;
No ) printf "\n ${RED}Skipping TRIM...${NC}" && printf "\n"; break;;
esac
done
# cleanup and exit
printf "\n"
printf "\n ${RED}Done!${NC}\n"
printf "\n-Cleaning up temporary rootfs mountpoints... (if you used TRIM)\n"
rmdir /rootfs_A
rmdir /rootfs_B
printf "\n${YEL}TrImLy has optimized your storage device for faster I/O operations!${NC} *yay*\n"
printf "${RED}--------------------------------------------------------------------------------${NC}\n"
exit
# Thanks to Ted Larson for motivating me to make this, my fellow nerd dad for too much to list here, and JCloud for fun chitchat.
# Ted Larson and JCloud are users on the CloudReady user forums.