Thomas' Tech Tips

How to manually trim SSD without fstrim

13 October 2023 - Thomas Damgaard

These are some old notes from when fstrim was not available:

Nowadays, you can simply run fstrim on most systems like this:

fstrim -v /

When we did not have fstrim, one way of doing it was as follows:

First, you had to use hdparm. You had to compile it from source, because the one distributed with most Linux distros at that time did not support this feature yet.

Then, with the newest hdparm, you ran:

SIZE=$(sudo blockdev --getsize /dev/sda);
for ((x=0;x<$SIZE/4096;x++)); do
  sudo hdparm --trim-sector-ranges $((x*4096)):4096
done
Filed under: hardware, hdparm, howto, linux, ssd, storage, tips

Back to article list