Skip to content

Both.org

News, Opinion, Tutorials, and Community for Linux Users and SysAdmins

Primary Menu
  • About Us
  • Computers 101
    • Hardware 101
    • Operating Systems 101
  • End of 10 Events
    • Wake Forest, NC, — 2025-09-20
  • Linux
    • Why I use Linux
    • The real reason we use Linux
  • My Linux Books
    • systemd for Linux SysAdmins
    • Using and Administering Linux – Zero to SysAdmin: 2nd Edition
    • The Linux Philosophy for SysAdmins
    • Linux for Small Business Owners
    • Errata
      • Errata for The Linux Philosophy for SysAdmins
      • Errata for Using and Administering Linux — 1st Edition
      • Errata for Using and Administering Linux — 2nd Edition
  • Open Source Resources
    • What is Open Source?
    • What is Linux?
    • What is Open Source Software?
    • The Open Source Way
  • Write for us
    • Submission and Style guide
    • Advertising statement
  • Downloads
  • Home
  • Extend the life of your Linux SSD drive with fstrim
  • Hardware
  • Linux

Extend the life of your Linux SSD drive with fstrim

SSDs have benefits like silent and cooler operation and a faster interface spec, compared to their elder spinning ancestors. Of course, new technology brings with it new methods of maintenance and management. SSDs have a feature to reclaim unused blocks on the device.
Alan Formy-Duval April 27, 2024 4 minutes read
SSDs-Cropped
1

Over the past several years, solid-state drives (SSD) have become the standard form of data storage. Mechanical drives can still be purchased if very large capacities are your need. SSDs have benefits over their mechanical spinning ancestors like silent and cooler operation and a faster interface spec. Of course, new technology brings with it new methods of maintenance and management. SSDs have a feature called TRIM. This is essentially a method for reclaiming unused blocks on the device, which may have been previously written, but no longer contain valid data and therefore, can be returned to the general storage pool for reuse.

The TRIM service

Fedora introduced the trim service into their Linux distribution in release 32, and it is enabled in all current releases. This service is not unique to Fedora. The existence and status will depend on an individual distribution basis.

Test

The service can be tested to better understand what is happening behind the scenes. I do this by opening a terminal and issuing the command to show the help on my Fedora 39 Linux system. The –help argument to fstrim will describe these and other arguments.

$ sudo /usr/sbin/fstrim --help

Usage:
 fstrim [options] <mount point>

Discard unused blocks on a mounted filesystem.

Options:
 -a, --all                trim mounted filesystems
 -A, --fstab              trim filesystems from /etc/fstab
 -I, --listed-in <list>   trim filesystems listed in specified files
 -o, --offset <num>       the offset in bytes to start discarding from
 -l, --length <num>       the number of bytes to discard
 -m, --minimum <num>      the minimum extent length to discard
 -t, --types <list>       limit the set of filesystem types
 -v, --verbose            print number of discarded bytes
     --quiet-unsupported  suppress error messages if trim unsupported
 -n, --dry-run            does everything, but trim

 -h, --help          display this help
 -V, --version       display version
Arguments:
  arguments may be followed by the suffixes for
   GiB, TiB, PiB, EiB, ZiB, and YiB (the "iB" is optional)

For more details see fstrim(8).

Let’s look at the service itself.

$ cat /usr/lib/systemd/system/fstrim.service
[Unit]
Description=Discard unused blocks on filesystems from /etc/fstab
Documentation=man:fstrim(8)
ConditionVirtualization=!container

[Service]
Type=oneshot
ExecStart=/usr/sbin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose --quiet-unsupported
PrivateDevices=no
PrivateNetwork=yes
PrivateUsers=no
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
MemoryDenyWriteExecute=yes
SystemCallFilter=@default @file-system @basic-io @system-service

Now I can see that the systemd service is configured to run the trim on all supported mounted filesystems in my /etc/fstab and /proc/self/mountinfo files –listed-in and print the number of discarded bytes –verbose but suppress any error messages if trim is unsupported –quiet-unsupported. Knowing these options is helpful for testing. For instance, I can start with the safest one, which is the dry run. I’ll leave off the quiet-unsupported argument so I can determine if any errors will occur with my drive setup.

$ sudo /usr/sbin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose --dry-run

This will show what the fstrim command will do based on the file systems that it finds.

$ sudo /usr/sbin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose

This will now send the TRIM operation to the drive and report on the number of discarded bytes from each file system. Below is an example on a NVME SSD.

/home: 54.3 GiB (58316726272 bytes) trimmed on /dev/mapper/home
/boot/efi: 579.8 MiB (607936512 bytes) trimmed on /dev/nvme0n1p1
/boot: 0 B (0 bytes) trimmed on /dev/nvme0n1p2
/: 4.1 GiB (4352933888 bytes) trimmed on /dev/mapper/root

The fstrim timer service

Fedora Linux implements a systemd timer service, scheduled to run on a weekly basis. To check the existence and current status, run systemctl status.

$ sudo systemctl status fstrim.timer
[sudo] password for alan: 
● fstrim.timer - Discard unused filesystem blocks once a week
     Loaded: loaded (/usr/lib/systemd/system/fstrim.timer; enabled; preset: enabled)
     Active: active (waiting) since Sun 2024-04-14 21:06:49 EDT; 1 week 0 days ago
    Trigger: Mon 2024-04-22 01:02:17 EDT; 3h 37min left
   Triggers: ● fstrim.service
       Docs: man:fstrim

Apr 14 21:06:49 myhost systemd[1]: Started fstrim.timer - Discard unused filesystem blocks once a week.

Verify

You can verify that the timer is enabled by listing all of the timers.

$ sudo systemctl list-timers --all

The following line referring to the fstrim.timer will appear. Notice that the timer actually activates fstrim.service. This is from where the actual fstrim is called.


NEXT                            LEFT LAST                             PASSED UNIT           ACTIVATES
Mon 2024-04-22 01:02:17 EDT 3h 37min Mon 2024-04-15 00:36:40 EDT  6 days ago fstrim.timer   fstrim.service

This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

Tags: Hardware Linux SSD

Post navigation

Previous: NetworkManager on Linux: #3 — How I migrated to NetworkManager Connection Files for configuration
Next: Seven Linux commands just for fun

Related Stories

f44-01-day-cropped
  • Fedora
  • Linux
  • Upgrades

Fedora 44 Released

David Both April 28, 2026
command_line_prompt
  • Command Line
  • Linux
  • Programming

Writing a replacement seq command

Jim Hall April 27, 2026
dark-web
  • Linux
  • News
  • Security
  • Vulnerability

High-severity Vulnerability in PackageKit

David Both April 25, 2026

Random Quote

Computers are unreliable; humans are even more unreliable.

— Gilb’s laws of unreliability

Why I’ve Never Used Windows

On February 12 I gave a presentation at the Triangle Linux Users Group (TriLUG) about why I use Linux and why I’ve never used Windows.

Here’s the link to the video: https://www.youtube.com/live/uCK_haOXPFM 

Why there’s no such thing as AI

Last October at All Things Open (ATO) I was interviewed by Jason Hibbits of We Love Open Source. It’s posted in the article “Why today’s AI isn’t intelligent (yet)“.

Technically We Write — Our Partner Site

Our partner site, Technically We Write, has published a number of articles from several contributors to Both.org. Check them out.

Technically We Write is a community of technical writers, technical editors, copyeditors, web content writers, and all other roles in technical communication.

Subscribe to Both.org

To comment on articles, you must have an account.

Send your desired user ID, first and last name, and an email address for login (this must be the same email address used to register) to subscribe@both.org with “Subscribe” as the subject line.

You’ll receive a confirmation of your subscription with your initial password as soon as we are able to process it.

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

License and AI Statements

Both.org aims to publish everything under a Creative Commons Attribution ShareAlike license. Some items may be published under a different license. You are responsible to verify permissions before reusing content from this website.

The opinions expressed are those of the individual authors, not Both.org.

You may not use this content to train AI.

 

Advertising Statement

Both.org does not sell advertising on this website.


Advertising may keep most websites running—but at Both.org, we’re committed to keeping our corner of the web ad-free. Both.org does not sell advertising on the website. Nor do we offer sponsored articles at this time. We’ll update this page if our position on sponsorships changes.

We want to be open about how the website is funded. Both.org is supported entirely by David Both and a few other dedicated individuals.

 

 

Copyright © All rights reserved. | MoreNews by AF themes.