Page 1 of 1

How to mount an NTFS partition for TRIM.

Posted: Tue Feb 05, 2019 5:05 pm
by BretAB
Hi Linux Mint Forums,

In a Mint (via Grub) "Dual Boot" environment, I see that Linux Mint v19.1 Mate is able to TRIM a NTFS partrtiton, if ... it is mounted. Here's a fstrim for ntfs example:
sudo fstrim /media/<username>/WinXP - v

What I'm trying to do is add a couple lines of code to the cron job that runs the normal Linux weekly TRIM. I didn't find a fstrim line in any of the cron.weekly files (or are they all just symbolic links to one cron.weekly file?). So I tried a brute force approach (and waited):
sudo grep -rnw '/' -e "fstrim"
(btw, you'll need to Ctrl_C to stop the search after several minutes)

One of the lines returned was:
/lib/systemd/system/fstrim.service:6:ExecStart=sbin/fstrim -av

So "/lib/systemd/system/fstrim.service" looks like a winner. But keep in mind that as far as Linux goes, I'm at the "Conscious incompetence" stage as seen here:

In fstrim.service I see:
Description=Discard unused blocks
ExecStart=/sbin/fstrim -av

I see that file is Read Only, and I could edit it via "<sudo EditorOfChoice path/filename">. So the newbie questions are:
1) Is this the correct file to add my unknown code to?
2) What code do I need to add to mount before fstrim, and what code to add after fstrim to dismount?

Sorry for the elongated post. I tired to ad enough explanation to possibly help other newbies. I appreciate your help.

Regards . . .

Re: How to mount an NTFS partition for TRIM.

Posted: Wed Feb 06, 2019 4:58 pm
by BretAB
Ok, I had no takers on my OP, so I'm going to do some live research/training here. Hopefully this will help other Newbies. If someone doesn't think this thread is in the correct forum, please let me know. Imho, the concept of "Newbie" is relative, based on experience in various related fields. So for me this is newbie level. That said . . .

One of my quandaries was why I couldn't find a cron.weekly file. Now I hopefully understand correctly that cron.weekly is not a single file, but rather a folder (aka "a unit file"). in that folder, 0anacron is always executed first, then the other files in that folder are executed. The execution of all the files in the folder collectively are the "job". Anacron (not a daemon like cron btw) allows jobs to run when your PC wakes up or otherwise becomes active. Whereas a "cron" is a daemon and executes a job at a specific date and time. 0anacron updates the time stamp found in \var\spool\anacron. For example, notice the presence of "\var\spool\anacron\cron.weekly". You can see the date stamp contents of that file via "sudo ls -l /var/spool/anacron".

These articles helped me understand some of the folder locations and their precedence: ... unit-files
Note the "Where are Systemd Unit Files Found?" section, and in there, "... /lib/systemd/system ... You should not edit files in this directory. Instead you should override the file, if necessary, using another unit file location which will supersede the file in this location." And further note, "If you wish to modify the way that a unit functions, the best location to do so is within the /etc/systemd/system directory. Unit files found in this directory location take precedence over any of the other locations on the filesystem. If you need to modify the system's copy of a unit file, putting a replacement in this directory is the safest and most flexible way to do this." I suggest reading the entire article.

This article help me understand the difference between the /etc/systemd/system, /run/systemd/system, and the /usr/lib/systemd/system "unit" folders: ... emd-system

This article mentions, "You can see that anacron is set to run some of the same scripts that are run by cron. Distributions handle this clash differently, by creating a preference for either cron or anacron and making the other program not execute the rule. For instance, on Ubuntu, the "/etc/crontab" tests if anacron is available on the system, and only executes the scripts in the cron.* directories with cron if anacron is not found. Other distributions have cron update the anacron's time-stamps every time it runs the contents of these directories, so that anacron does not execute when it is called." : ... n-on-a-vps

I still haven't figured out exactly how/where to schedule the mount of the ntfs partition before and after a fstrim line, but I think I'm getting closer.

For what that's worth . . .

Re: How to mount an NTFS partition for TRIM.

Posted: Wed Feb 06, 2019 5:25 pm
by BretAB
And closer, "TRIM is enabled to run weekly by default in 18.04. It is a systemd service managed via systemctl, not CRON."
(from ... stallation)

And closer (from same article), "For reference, the when is controlled by /lib/systemd/system/fstrim.timer (OnCalendar=weekly) and the what by /lib/systemd/system/fstrim.service (ExecStart=/sbin/fstrim -av). – Moilleadóir Jul 5 '18 at 8:46".

Re: How to mount an NTFS partition for TRIM.

Posted: Wed Feb 06, 2019 5:43 pm
by BretAB
Attn Moderator:

Perhaps this thread should be moved to the Hardware forum?

Please advise.

Re: How to mount an NTFS partition for TRIM.

Posted: Fri Feb 08, 2019 12:35 pm
by hcentaur13
fstrim IS running vby systemd weekly for all mounted partitions.. No need for an own cron job.

Re: How to mount an NTFS partition for TRIM.

Posted: Thu Feb 14, 2019 5:11 pm
by BretAB
Hi. Thanks for your post and I'm sorry for the late reply.

I'm not quite sure what you mean by "vby". Maybe just a typo of "by"? Anyway . . .

I saw the -av switch (a for "all" and v for "verbose). I can see the NTFS partition in MATE's file manager "Caja". The problem is that I don't believe the NTFS partition is already mounted by default (I could be wrong of course). I noticed that if I right click on it in Caja, the available option is to Mount it (not dismount it). If I mount it, only then then do I get code to appear in root\run\mount\utab , and a utab.lock file also is created and remains present until dismounted. Hum . . .

Thanks if you care to comment further : )