You are not logged in.

#1 2021-05-29 16:20:51

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 538

When any USB drive is automounted, always use "sync"

Currently, any storage device I connect through any USB port of my laptop is mounted with writeback cache enabled. This is something I'd like to avoid. Why? Because I find annoying that copying, for example, a big file such a movie to a USB flash stick will show as completed before it actually is, which could lead to data loss as I might think it's done and pull it out.

The best way seems to mount the devices with the "sync" option. I've tried this udev rule:

SUBSYSTEM=="block", ENV{ID_BUS}=="usb", ENV{ID_TYPE}=="disk", ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_MOUNT_OPTIONS}="sync"

With no succes. I am using Gnome, which uses gvfs for automounting. I think that means there is something else to do here, but I don't know what?

Would anyone have any suggestions?

Thanks.

Offline

#2 2021-05-29 16:22:22

Scimmia
Fellow
Registered: 2012-09-01
Posts: 12,837

Re: When any USB drive is automounted, always use "sync"

The best way is to unmount volumes you have mounted instead of just pulling it.

Offline

#3 2021-05-29 16:26:10

icar
Member
From: Catalunya
Registered: 2020-07-31
Posts: 538

Re: When any USB drive is automounted, always use "sync"

Yes, which then throws a notification that "data is still being written", which leads to me waiting for an undefinied amount of time until the cache is actually written.
I'd like to avoid that.

Offline

#4 2021-06-02 18:31:36

teckk
Member
Registered: 2013-02-21
Posts: 529

Re: When any USB drive is automounted, always use "sync"

Open a system monitor while you are writing to a usb device, and watch it. For the last 11 years at least, an arch machine will write everything to the usb drive, pause for 5-10 seconds, then finish writing the last of it. Watch your system monitor for it being done.

If it is a ntfs external device, you definitely want to be sure that it is done before you pull it out. Or you will by looking for a microsoft machine to fix it's corrupt volume.

I think that you can have a look at these too.
/proc/sys/vm/dirty_background_bytes
/proc/sys/vm/dirty_bytes

Offline

Board footer

Powered by FluxBB