Score:3

System hangs/breaks when fstrim runs (dual boot on SSD setup)

sl flag

I have a Windows 10 / Kubuntu 22.04 dual boot setup with both OS partitions on the same SSD drive.

Every week fstrim.timer triggers fstrim.service to run in background and as a result my system "breaks" in interesting ways and becomes unusable until I do an emergency reboot.

Symptoms

  • Trying to start any new GUI application silently fails.
  • Some applications such as Firefox freeze completely.
  • I'm able keep using command line if there is an already open Konsole.
  • Trying to reboot the system takes forever while showing the following mesage in text mode (after pressing Esc to show logs instead plymouth screen):
    A stop job is running for Discard unused blocks on filesystems from /etc/fstab
    I usually do an emergency reboot after losing patience.

I'm able to reproduce the situation above by running sudo fstrim --fstab. Pressing Ctrl+C while running fstrim or executing killall -KILL fstrim does nothing.

Prior Research

Diagnostics

$ systemctl status fstrim.service fstrim.timer
○ fstrim.service - Discard unused blocks on filesystems from /etc/fstab
     Loaded: loaded (/lib/systemd/system/fstrim.service; static)
     Active: inactive (dead)
TriggeredBy: ● fstrim.timer
       Docs: man:fstrim(8)

● fstrim.timer - Discard unused blocks once a week
     Loaded: loaded (/lib/systemd/system/fstrim.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Fri 2022-11-25 19:42:10 +03; 13min ago
    Trigger: Mon 2022-11-28 00:17:05 +03; 2 days left
   Triggers: ● fstrim.service
       Docs: man:fstrim
$ journalctl -u fstrim
Sep 11 10:35:23 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
-- Boot 07b77c86b89d45bd82fbb37b31a8d63f --
Sep 12 08:01:24 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Sep 12 08:03:55 ABRA-Linux systemd[1]: fstrim.service: Main process exited, code=killed, status=15/TERM
Sep 12 08:03:55 ABRA-Linux systemd[1]: fstrim.service: Failed with result 'signal'.
Sep 12 08:03:55 ABRA-Linux systemd[1]: Stopped Discard unused blocks on filesystems from /etc/fstab.
-- Boot b4acfa99e85148c3a9f173cdd1fb13fc --
Oct 04 17:59:05 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Oct 04 18:03:49 ABRA-Linux systemd[1]: fstrim.service: State 'stop-sigterm' timed out. Killing.
Oct 04 18:03:49 ABRA-Linux systemd[1]: fstrim.service: Killing process 24334 (fstrim) with signal SIGKILL.
-- Boot 553a345dfd7e41429eb0719320254cee --
Oct 10 08:31:04 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
-- Boot 71d860d3c7654cf88d564ae9072918da --
Oct 17 00:17:47 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Oct 17 00:32:56 ABRA-Linux fstrim[117561]: /mnt/C: 31,2 GiB (33495588864 bytes) trimmed on /dev/sda3
Oct 17 00:32:56 ABRA-Linux fstrim[117561]: /boot/efi: 60,8 MiB (63755264 bytes) trimmed on /dev/sda1
Oct 17 00:32:56 ABRA-Linux fstrim[117561]: /: 9,8 GiB (10574045184 bytes) trimmed on /dev/sda5
Oct 17 00:32:56 ABRA-Linux systemd[1]: fstrim.service: Deactivated successfully.
Oct 17 00:32:56 ABRA-Linux systemd[1]: Finished Discard unused blocks on filesystems from /etc/fstab.
Oct 17 00:32:56 ABRA-Linux systemd[1]: fstrim.service: Consumed 5.636s CPU time.
-- Boot c3a58c73fbb1402d862520a0c5b1faf1 --
Oct 27 13:09:32 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
-- Boot 5be05c0fa9b34f9493fe830675f4d3b2 --
Nov 08 21:15:36 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Nov 08 21:38:58 ABRA-Linux systemd[1]: fstrim.service: Main process exited, code=killed, status=15/TERM
Nov 08 21:38:58 ABRA-Linux systemd[1]: fstrim.service: Failed with result 'signal'.
Nov 08 21:38:58 ABRA-Linux systemd[1]: Stopped Discard unused blocks on filesystems from /etc/fstab.
-- Boot 69549e12288c4ca2a022c8e4f6cea7cf --
Nov 14 21:06:02 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Nov 14 21:18:36 ABRA-Linux fstrim[46092]: /mnt/C: 26,4 GiB (28312604672 bytes) trimmed on /dev/sda3
Nov 14 21:18:36 ABRA-Linux fstrim[46092]: /boot/efi: 60,8 MiB (63706112 bytes) trimmed on /dev/sda1
Nov 14 21:18:36 ABRA-Linux fstrim[46092]: /: 9,1 GiB (9798144000 bytes) trimmed on /dev/sda5
Nov 14 21:18:36 ABRA-Linux systemd[1]: fstrim.service: Deactivated successfully.
Nov 14 21:18:36 ABRA-Linux systemd[1]: Finished Discard unused blocks on filesystems from /etc/fstab.
Nov 14 21:18:36 ABRA-Linux systemd[1]: fstrim.service: Consumed 5.480s CPU time.
-- Boot 51a404cad72449fb84c8464cdc522c1a --
Nov 25 17:31:53 ABRA-Linux systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
Nov 25 17:42:42 ABRA-Linux systemd[1]: fstrim.service: State 'stop-sigterm' timed out. Killing.
Nov 25 17:42:42 ABRA-Linux systemd[1]: fstrim.service: Killing process 16417 (fstrim) with signal SIGKILL.
Nov 25 17:44:12 ABRA-Linux systemd[1]: fstrim.service: Processes still around after SIGKILL. Ignoring.
Nov 25 17:45:42 ABRA-Linux systemd[1]: fstrim.service: State 'final-sigterm' timed out. Killing.
Nov 25 17:45:42 ABRA-Linux systemd[1]: fstrim.service: Killing process 16417 (fstrim) with signal SIGKILL.
Nov 25 17:47:13 ABRA-Linux systemd[1]: fstrim.service: Processes still around after final SIGKILL. Entering failed mode.
Nov 25 17:47:13 ABRA-Linux systemd[1]: fstrim.service: Failed with result 'timeout'.
Nov 25 17:47:13 ABRA-Linux systemd[1]: fstrim.service: Unit process 16417 (fstrim) remains running after unit stopped.
Nov 25 17:47:13 ABRA-Linux systemd[1]: Stopped Discard unused blocks on filesystems from /etc/fstab.
$ cat /etc/fstab
# <file system>                            <mount point>  <type>  <options>                  <dump>  <pass>
UUID=e6c60824-c508-4136-b085-46e9f9e18012  /              ext4    defaults                   0       1
UUID=5C82-5FBB                             /boot/efi      vfat    umask=007                  0       1
UUID=2fe26c1f-25ae-44c5-91d6-c90971846815  /data          ext4    defaults                   0       2
UUID=3CB2C0EBB2C0AAAA                      /mnt/C         ntfs    windows_names,umask=000    0       0
UUID=D0AE869EAE867D2A                      /mnt/D         ntfs    windows_names,umask=000    0       0
/swapfile                                  none           swap    sw                         0       0
$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 223.6G  0 disk 
├─sda1   8:1    0   100M  0 part /boot/efi
├─sda2   8:2    0    16M  0 part 
├─sda3   8:3    0 176.4G  0 part /mnt/C
├─sda4   8:4    0   509M  0 part 
└─sda5   8:5    0  46.6G  0 part /
sdb      8:16   0 931.5G  0 disk 
├─sdb1   8:17   0   500G  0 part /mnt/D
└─sdb2   8:18   0 431.5G  0 part /data
sr0     11:0    1  1024M  0 rom  
$ sudo blkid
/dev/sda5: LABEL="Linux" UUID="e6c60824-c508-4136-b085-46e9f9e18012" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux" PARTUUID="409a24dc-414c-49d7-b7e2-c353610e4b6f"
/dev/sdb2: UUID="2fe26c1f-25ae-44c5-91d6-c90971846815" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="Linux Data" PARTUUID="91cbfe6d-67a3-a145-bb9b-8b95756dd01e"
/dev/sdb1: BLOCK_SIZE="512" UUID="D0AE869EAE867D2A" TYPE="ntfs" PARTLABEL="Windows Data" PARTUUID="1a7ad633-565e-4721-a395-6d90149eb24f"
/dev/sda4: BLOCK_SIZE="512" UUID="CEF6C4DDF6C4C745" TYPE="ntfs" PARTUUID="19412a16-7e1d-4c09-9baa-7e8d36e12512"
/dev/sda2: PARTLABEL="Microsoft reserved partition" PARTUUID="604485ef-4246-4773-a653-7f01e14a7db4"
/dev/sda3: LABEL="Windows" BLOCK_SIZE="512" UUID="3CB2C0EBB2C0AAAA" TYPE="ntfs" PARTLABEL="Windows" PARTUUID="fcd81266-ef0c-46a6-8f0c-a3c0ea7c736f"
/dev/sda1: UUID="5C82-5FBB" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="78c8d426-646d-4ba8-bf0a-3d8c52118f1f"
$ sudo fdisk -l
Disk /dev/sda: 223.57 GiB, 240057409536 bytes, 468862128 sectors
Disk model: INTEL SSDSCKHW24
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 20985C80-B8A7-4B70-A20E-869F288EFD10

Device         Start       End   Sectors   Size Type
/dev/sda1       2048    206847    204800   100M EFI System
/dev/sda2     206848    239615     32768    16M Microsoft reserved
/dev/sda3     239616 370159537 369919922 176.4G Microsoft basic data
/dev/sda4  467816448 468858879   1042432   509M Windows recovery environment
/dev/sda5  370159616 467816447  97656832  46.6G Linux filesystem

Partition table entries are not in disk order.


Disk /dev/sdb: 931.51 GiB, 1000204886016 bytes, 1953525168 sectors
Disk model: HGST HTS721010A9
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 88536680-938F-44E7-B75A-6BF2EC90977E

Device          Start        End    Sectors   Size Type
/dev/sdb1        2048 1048578047 1048576000   500G Microsoft basic data
/dev/sdb2  1048578048 1953523711  904945664 431.5G Linux filesystem
$ cat /mnt/C/.NTFS-3G/UserMapping
# Generated by ntfsusermap for Linux, v 1.2.0
:1000:S-1-5-21-76983165-3329468604-3967637644-513
1000:1000:S-1-5-21-76983165-3329468604-3967637644-1001
Score:0
iq flag

Sorry, this is not an answer, but I have the same issue. Only in my case it takes whopping 30 minutes. And it also happens on arch. I ended up not mounting the disks via fstab and instead mounting them through udisks

○ fstrim.service - Discard unused blocks on filesystems from /etc/fstab
     Loaded: loaded (/usr/lib/systemd/system/fstrim.service; static)
     Active: inactive (dead) since Mon 2023-06-12 17:51:14 EEST; 3min 32s ago
TriggeredBy: ● fstrim.timer
       Docs: man:fstrim(8)
    Process: 4848 ExecStart=/usr/bin/fstrim --listed-in /etc/fstab:/proc/self/mountinfo --verbose --quiet-unsupported (code=exited, status=0/SUCCESS)
   Main PID: 4848 (code=exited, status=0/SUCCESS)
        CPU: 819ms

jun 12 17:27:56 sauron systemd[1]: Starting Discard unused blocks on filesystems from /etc/fstab...
jun 12 17:51:14 sauron fstrim[4848]: /mnt/windows10: 221.9 GiB (238276542464 bytes) trimmed on /dev/nvme0n1p3
jun 12 17:51:14 sauron fstrim[4848]: /mnt/personal_misc: 1.6 TiB (1797919481856 bytes) trimmed on /dev/sda3
jun 12 17:51:14 sauron fstrim[4848]: /mnt/tools_misc: 1.7 TiB (1882781216768 bytes) trimmed on /dev/sda2
jun 12 17:51:14 sauron fstrim[4848]: /: 156.3 GiB (167851999232 bytes) trimmed on /dev/sdb1
jun 12 17:51:14 sauron fstrim[4848]: /boot/efi: 70.6 MiB (74066944 bytes) trimmed on /dev/nvme0n1p1
jun 12 17:51:14 sauron systemd[1]: fstrim.service: Deactivated successfully.
jun 12 17:51:14 sauron systemd[1]: Finished Discard unused blocks on filesystems from /etc/fstab.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.