0

I have an HDD used for archival purposes. I had to format it with NTFS to keep it accessible from Windows. I need TRIM support (because the HDD is SMR...) and NTFS can't trim without the discard option for some reason.

Can I automatically add the discard option whenever an ntfs partition is mounted?

1 Answer 1

3

NTFS can't trim without the discard option for some reason.

The reason: Because that is the option that enables TRIM support :)

From https://docs.kernel.org/filesystems/ntfs3.html

discard | Enable support of the TRIM command for improved performance on delete operations, which is recommended for use with the solid-state drives (SSD).

Can I automatically add the discard option whenever an ntfs partition is mounted?

Not that I'm aware of.

It's also not what you actually need, you want that specific drive to always be mounted with that, and other NTFS drives possibly not.

So, easiest option here is to just add a line to /etc/fstab that lists your NTFS volume's UUID (you can find that with lsblk -o +uuid), and set the mount options there, and mark it as noauto (if you don't want it to be mounted at boot, which would require it to always be present at boot). Something like:

UUID=1234-5678-ABCD     /mnt/backup   ntfs    defaults,noauto,discard,x-systemd.automount

(don't forget to create the /mnt/backup directory first)

From there on, whenever you try to access the /mnt/backup directory, your system will try to automatically (due to x-systemd.automount) mount the volume with this UUID, using the discard option. The directory will, however, not be automatically mounted at boot (due to the noauto option).

7
  • I got confused because I have seen earlier that discard means that the system will immediately TRIM any deleted file, but not necessary to use fstrim. And exfat filesystems mounted with udisks didn't need it, so I got more confused. I think it may be possible to do it with udev somehow, I just don't know the how :). Thank you for the fstab suggestion, I will likely end up doing this after all. Commented May 2 at 12:13
  • Another suggested parameter for USB drives or any drive not permanently connected is autofs or systemd-automount. Most seem to suggest autofs which needs a Autofs map file in addition to fstab entry. or wiki.archlinux.org/title/Fstab#Automount_with_systemd Note: NTFS not recommended for Linux backup as it does not support ownership & permissions, If just your data files, then you can reset to your ownership & permissions when restoring. But system files vary too much. Commented May 2 at 14:58
  • @oldfred errm, I already recommended systemd automont. Commented May 2 at 15:06
  • 1
    Yes NTFS isn't good for Linux. I backup my home directory to an SSD that has BTRFS. This HDD stores only some large files. I considered exfat but it has no sparse file support so VM disk images would consume space for zeros. @oldfred Commented May 3 at 3:12
  • 1
    @td211 one trick might be, instead of making Linux use an NTFS implementation that was written from scratch, make Windows use an ext4 implementation that's a port of the known-to-be-good Linux ext4 driver (which inherently is open source). github.com/bobranten/Ext4Fsd I haven't used this in a loooong time, so can't tell you how good it really is. But if I had to bet NTFS on Linux vs ext4 on Windows, I'd go with the latter; plus: with the WSL2 subsystem in modern windows, you can also directly mount any file system supported by the Linux kernel. Commented May 3 at 9:49

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.