Optimising Ubuntu SSDs with TRIM and fstrim
Optimising Ubuntu for SSD drives with trim and fstrim matters when a solid-state drive begins to feel slower while copying files or launching applications. The aim is not a mysterious speed switch. TRIM tells the controller which storage blocks are no longer needed, helping it reuse space efficiently and maintain steadier performance over time.
TRIM is the operation understood by the drive; fstrim is the command-line utility that finds eligible free space and passes those regions to the drive for cleanup. Recent Ubuntu releases normally handle this through a scheduled systemd timer. Most people are better off checking the existing setup than adding repeated background jobs.
No special kernel, fresh partition table or destructive optimisation is required. A handful of commands can show whether your disk supports discard, whether the timer is active and how much space fstrim released. Keep a separate backup of irreplaceable files, because maintenance is not a substitute for recovery.
Why SSDs need block cleanup
Unlike a mechanical hard drive, an SSD stores data in pages and reserves extra space for garbage collection and over-provisioning. When files are deleted, the filesystem can mark their blocks free even though the controller still has old data to manage. Sending TRIM lets the controller identify genuinely unused space, reducing the work needed before future writes and limiting unnecessary write amplification.
There are two common ways to pass on this information. Continuous discard adds the discard mount option so the filesystem sends TRIM as blocks become free. Periodic fstrim scans the free space of a mounted filesystem and submits a batch. Ubuntu normally favours the scheduled approach, and running both approaches together is usually unnecessary.
Support depends on the whole chain: the filesystem must be able to discard blocks, and the SATA or NVMe device must pass the command through to its controller. ext4, XFS and Btrfs all work with fstrim. Many USB SSD enclosures also work, but some bridges do not forward discard. Encrypted Ubuntu installations with LUKS or LVM normally present no obstacle; the device names can simply look different. A USB enclosure that hides discard support may still work as ordinary storage, just without routine trimming.
Checking Ubuntu's trim support
Start by identifying the filesystem mounted at the root of your Ubuntu installation. Run:
lsblk -f
Find the line whose MOUNTPOINT is / in the lsblk output. It shows the partition, filesystem type and mount point. On many laptops this is /dev/nvme0n1p2 with ext4, while SATA systems often use /dev/sda2. For another view of the root filesystem type, findmnt -no FSTYPE / prints just the relevant value. You need the mounted filesystem, not merely the physical SSD, when you later target a particular directory.
Then inspect the device's discard capabilities with:
sudo lsblk -D
The DISC-ALN, DISC-GRAN and DISC-MAX columns describe alignment, minimum granularity and maximum discard size. A value of zero can indicate that the device or its bridge does not report support. The output is informational rather than a speed test, so do not treat a missing maximum as proof that the SSD is defective.
To see whether discard is already enabled through the mount options, use:
findmnt -no OPTIONS /
If discard appears in the result, continuous trimming is configured. Its absence is normal for a standard Ubuntu installation and does not mean the weekly fstrim service is broken. Editing /etc/fstab incorrectly can leave Ubuntu unable to mount its root filesystem, while fstrim requires no such change. Leave the standard mount options alone unless you have a measured reason to change them.
Running fstrim by hand
Ubuntu normally installs fstrim as part of util-linux. You can confirm it is present and run it against the root filesystem with:
command -v fstrim
sudo fstrim -v /
Normally, the first command prints a path such as /usr/bin/fstrim. The second reports the amount trimmed on the filesystem mounted at /. It informs the SSD's controller; it does not erase the files you can still see. If /home is a separate ext4 or XFS mount, target it with sudo fstrim -v /home; otherwise /home is part of the root filesystem and does not need a separate pass.
To inspect every supported mounted filesystem in one pass, use:
sudo fstrim -av
The -a option covers local filesystems that support trimming, while -v prints the result for each one. Separate /home, /var or data mounts can receive their own entries. fstrim passes ranges of free blocks, not the contents of live files. Network shares, unusual filesystems and some external media may be skipped or report an error; a message about one mount does not imply that your main Ubuntu filesystem failed.
Run time is normally short because fstrim submits block addresses rather than rewriting data. The trimmed total measures eligible space reported as unused, not data that has been securely erased or physical capacity instantly returned. It is also not a performance score. fstrim can help a drive that has accumulated stale blocks, but it cannot overcome a slow interface, a nearly full filesystem or hardware that cannot sustain the requested write speed. Leave some free capacity and judge any change over normal daily work.
Automating maintenance with systemd
Modern Ubuntu uses systemd to run fstrim on a schedule. The timer is the schedule; fstrim.service is the one-shot job it triggers. Check the timer and its next run with:
systemctl list-timers fstrim.timer
systemctl status fstrim.timer
The timer normally calls fstrim.service about once a week. Its exact time can vary because systemd adds a randomised delay. If the timer is missing on your system, enable it with:
sudo systemctl enable --now fstrim.timer
Enabling a timer does not necessarily perform an immediate trim; it ensures the scheduled job is available. You can trigger the service separately with sudo systemctl start fstrim.service.
Inspecting the units and recent results is useful when you want to confirm that maintenance is actually happening:
systemctl cat fstrim.timer
sudo journalctl -u fstrim.service
The timer definition should include an OnCalendar entry and Persistent=true, which lets a missed run occur after the machine has been off. Ubuntu uses the system's local time zone, so a 03:00 schedule follows settings such as Australia/Sydney, where daylight saving changes the clock, or Australia/Brisbane, where it does not. The service's journal entry gives the date and trimmed amount, which is more useful than assuming a job ran because a timer appeared in the calendar.
You do not need a custom timer for most desktops or laptops. If you prefer another day, the built-in weekly run is enough to keep routine housekeeping separate from your workday. For a deliberate weekend window, edit the timer:
sudo systemctl edit fstrim.timer
Add:
[Timer]
OnCalendar=Sun *-*-* 03:00:00
RandomizedDelaySec=2h
Persistent=true
Then reload and restart the timer:
sudo systemctl daemon-reload
sudo systemctl restart fstrim.timer
Use systemctl list-timers fstrim.timer again to confirm the new schedule. Avoid disabling the built-in service simply to reduce wear; weekly trimming is light routine I/O, and duplicate maintenance jobs add little value.
Keeping performance and data safe
TRIM is not a backup and does not protect files from a failing drive, accidental deletion or a stolen laptop. On a dual-boot laptop in Sydney, a disk labelled C: in Windows may appear as /dev/nvme0n1p2 in Ubuntu. Trim the Ubuntu filesystem, not the Windows hibernation partition. If you share an NTFS data partition, keep Windows Fast Startup disabled so Linux does not mount a hibernated volume read-write.
Australian shops such as JB Hi-Fi, Officeworks and Centre Com carry mainstream 500GB and 1TB SSDs. Consumer prices normally include GST, so comparing the full purchase cost is straightforward. Compare capacity, endurance and warranty rather than a headline sequential-read number alone. For a home backup, an external drive can hold a second copy of important files; encrypt it when it contains sensitive material. An Australian household on an NBN plan can make the first backup over fixed broadband, avoiding a large upload against a mobile data allowance.
Performance also depends on heat and enclosure design. Brisbane summers can make a compact laptop or mini PC warm enough to slow its SSD, so check airflow and use a heatsink where the manufacturer recommends one. For an NVMe drive, install nvme-cli and inspect its reported temperature with:
sudo apt install nvme-cli
sudo nvme smart-log /dev/nvme0
Replace /dev/nvme0 with the drive's actual name. SMART wear figures are controller-specific and are not pass/fail scores; a high percentage used indicates accumulated workload, not that the drive will fail on a particular date. SATA drives can be checked with smartctl -a /dev/sda after installing smartmontools. Traditional periodic defragmentation is unnecessary for SSDs on Linux; modern tools usually detect them and leave them alone. TRIM helps the controller manage space, but backups, cooling and sensible capacity remain separate safeguards.
On a typical Ubuntu desktop, the useful combination is simple: the kernel supports discard, fstrim can reach the mounted filesystem, and the weekly systemd timer runs without a second maintenance tool taking over. Most apparent SSD slowdowns come from full disks, poor thermal conditions, background updates or an application bottleneck rather than missing TRIM.
Keeping a healthy free-space margin and checking storage health remain useful alongside trimming, but neither can replace a separate copy of important data. The concrete next step is to run sudo fstrim -av once and save its output as the first maintenance baseline.