A Detective Story - blinking lights and no sleep

Post image

The night was dark as Sherlock sat in front of his Ubuntu system, fingers flying across the keyboard. Suddenly, just a moment after midnight, a nervously blinking LED caught his eye.

The disk access light was frantic. The system slowed to a crawl.

Sherlock froze. Was it a virus? Ransomware? A hacker? Hardware failure? He had to find out.

The Mystery of the Insomniac PC

“Calm down,” he muttered to himself. It was late; a fresh mind would serve the investigation better tomorrow. But as he tried to send the computer to sleep, the system refused. It was gripped by some invisible task, stubbornly preventing hibernation.

He couldn’t force a shutdown. He had 67 open browser tabs—each one a vital thread in his current project. With a weary sigh, he stayed up to dive into the digital abyss.

The Missing Cron Job

His first thought: a cronjob. He checked the crontab for scheduled housekeeping, but found nothing. No ghosts in the machine there.

Puzzled, he delved deeper into the system logs until he found the culprit: a program called fstrim.

He soon discovered that fstrim is the unsung hero of the modern age. It maintains the health of SSDs by trimming unused blocks, increasing the drive’s lifespan and keeping performance snappy. He had recently upgraded to an SSD but hadn’t realized that since Ubuntu 18.04 , the system uses systemd timers instead of old-fashioned cron jobs.

Puh. That explained why his search for cron jobs had come up empty.

The Resolution

Feeling a wave of relief, Sherlock watched as the blinking LED finally went dark. The system smoothed out. The “threat” was nothing more than a diligent digital janitor.

However, Sherlock was a man of logic, and having his work interrupted at midnight was a crime in itself. He realized that scheduling the task for 4:00 AM—as most tutorials suggested—was a rookie mistake. If his PC was off, the systemd timer would simply wait for him to boot up and then “catch up” by slowing down his morning coffee-and-coding session.

The Clever Fix

Sherlock opened his terminal one last time. He wouldn’t schedule the maintenance for the dead of night, nor the start of his day.

Instead, he rescheduled fstrim for Tuesday at 12 o’clock. “Even a detective must eat,” he mused. “While I’m off hunting down a sandwich, the computer can hunt down its own fragmented blocks. By the time I’m back with a full stomach, the SSD will be refreshed, and my 67 tabs will be ready for action.”


In conclusion: If you’re an Ubuntu user with an SSD, don’t let your system maintenance keep you up at night. Check your timers, understand your hardware, and schedule your “housekeeping” for a time when you’re actually away from the desk.


🛠️ Technical Appendix: Mastering the fstrim Timer

If you want to investigate or reschedule your own SSD maintenance, here are the commands Sherlock used to solve the mystery.

1. Check if the Timer is Active

Ubuntu enables fstrim by default on systems with SSDs. To see if it’s currently scheduled, run:

systemctl status fstrim.timer

2. View the Last Run Time

To see exactly when the trim last occurred and how much data was reclaimed, check the logs:

journalctl -u fstrim.service

3. Rescheduling the “Sleep Stealer”

By default, the timer triggers at 00:00 on Mondays. Because the setting Persistent=true is enabled by default, if your PC is off at midnight, Ubuntu will “catch up” and run the trim the very next time you boot up.

If you want to move the schedule or prevent it from slowing down your morning start-up, follow these steps:

  1. Open the edit buffer:
sudo systemctl edit fstrim.timer
  1. Paste the following configuration:
[Timer]
# Clear the default schedule
OnCalendar=

# Set new schedule: Tuesday at 12:00 PM (Sherlock's Lunch Break)
OnCalendar=Tue *-*-* 12:00:00

# Wait up to 30 mins after boot before catching up on a missed run
# This ensures that if the PC was off at noon, it doesn't slow down 
# the system the moment it is powered back on.
RandomizedDelaySec=30min
  1. Save and exit.
    Detective’s Note: The RandomizedDelaySec is the real secret weapon here. It ensures that if you missed your 12 o’clock window, the system won’t start the heavy lifting until you’ve had a chance to get your 67 tabs open and settled.

4. Manual Intervention

If you’ve just deleted a massive project and want to reclaim that space immediately without waiting for the timer, you can run a manual trim:

sudo fstrim -av

The -v (verbose) flag will tell you exactly how many bytes were trimmed.

You May Also Like