How come everything is written when I decide to unmount a usbdrive?

This kind of topic is usually created by users who have not yet developed an understanding of their linux system and the inner workings.

The topic has been frequently discussed on Manjaro forum - with various sysctl tweaks as a result.

SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem", ENV{UDISKS_MOUNT_OPTIONS_DEFAULTS}+="sync", ENV{UDISKS_MOUNT_OPTIONS_ALLOW}+="sync"

https://forum.manjaro.org/t/decrease-dirty-bytes-for-more-reliable-usb-transfer/120798/4

In the beginning of EndeavourOS as it was with Manjaro - it was Linux superusers and experts - and when the distribution gets traction - and news attention - it attracts all kinds of users including users who knows next to nothing of Linux, users who makes the common mistake to substitute Linux for Windows.

Linux != Windows

The writing starts immediately but as USB device storage is slower than memory - data is cached to memory using write cache.

All kinds of USB devices exist - devices slow as snail and others like a cheetah.

The suggestion to use an udev rule to disable write cache drew my attention.

To me the idea is a :bulb: moment and I know how to improve this rule to only target USB devices

ACTION=="add|change", KERNEL=="sd[a-z]", RUN+="/usr/bin/hdparm -W 0 /dev/%k"

One should realize that not all USB devices support write-caching and in such case - the result of disabling write-caching will likely affect system especially when it comes to large transfers from one usb to another.

So - this will never be a one size fits all - but when you know what you are doing - the input you gave me here is noteworthy.

To come up with this I had to get an idea of what happened and udevadm is a great tool

To watch what happens when a device is inserted

udevadm monitor

To get info on the device - where y is the device just added

udevadm info /dev/sdy

Testing a handful usb devices I realized the ID_USB_TYPE=disk would be an ideal pointer to ensure only usb devices was targeted.

ACTION=="add|change", KERNEL=="sd[a-z]", ENV{ID_USB_TYPE}=="disk", RUN+="/usr/bin/hdparm -W 0 /dev/%k"

This addition will likely affect sdcards as well - suffice they support write-caching - as card readers - including internal - is usually attached to the usb bus.

There is a couple of usable E:

E: ID_USB_TYPE=disk
E: ID_USB_DRIVER=usb-storage

SDcard

 $ udevadm info /dev/sdf
P: /devices/pci0000:00/0000:00:03.1/0000:02:00.0/0000:03:08.0/0000:04:00.3/usb8/8-4/8-4:1.0/host11/target11:0:0/11:0:0:1/block/sdf
M: sdf
U: block
T: disk
D: b 8:80
N: sdf
L: 0
S: disk/by-id/usb-Generic-_USB3.0_CRW-SD_201412031053-0:1
S: disk/by-path/pci-0000:04:00.3-usb-0:4:1.0-scsi-0:0:0:1
S: disk/by-diskseq/13
Q: 13
E: DEVPATH=/devices/pci0000:00/0000:00:03.1/0000:02:00.0/0000:03:08.0/0000:04:00.3/usb8/8-4/8-4:1.0/host11/target11:0:0/11:0:0:1/block/sdf
E: DEVNAME=/dev/sdf
E: DEVTYPE=disk
E: DISKSEQ=13
E: MAJOR=8
E: MINOR=80
E: SUBSYSTEM=block
E: USEC_INITIALIZED=4122115
E: ID_BUS=usb
E: ID_MODEL=USB3.0_CRW-SD
E: ID_MODEL_ENC=USB3.0\x20CRW-SD\x20\x20\x20
E: ID_MODEL_ID=0321
E: ID_SERIAL=Generic-_USB3.0_CRW-SD_201412031053-0:1
E: ID_SERIAL_SHORT=201412031053
E: ID_VENDOR=Generic-
E: ID_VENDOR_ENC=Generic-
E: ID_VENDOR_ID=0bda
E: ID_REVISION=1.00
E: ID_TYPE=disk
E: ID_INSTANCE=0:1
E: ID_USB_MODEL=USB3.0_CRW-SD
E: ID_USB_MODEL_ENC=USB3.0\x20CRW-SD\x20\x20\x20
E: ID_USB_MODEL_ID=0321
E: ID_USB_SERIAL=Generic-_USB3.0_CRW-SD_201412031053-0:1
E: ID_USB_SERIAL_SHORT=201412031053
E: ID_USB_VENDOR=Generic-
E: ID_USB_VENDOR_ENC=Generic-
E: ID_USB_VENDOR_ID=0bda
E: ID_USB_REVISION=1.00
E: ID_USB_TYPE=disk
E: ID_USB_INSTANCE=0:1
E: ID_USB_INTERFACES=:080650:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=usb-storage
E: ID_PATH=pci-0000:04:00.3-usb-0:4:1.0-scsi-0:0:0:1
E: ID_PATH_TAG=pci-0000_04_00_3-usb-0_4_1_0-scsi-0_0_0_1
E: ID_PART_TABLE_UUID=dc14d963
E: ID_PART_TABLE_TYPE=dos
E: DEVLINKS=/dev/disk/by-id/usb-Generic-_USB3.0_CRW-SD_201412031053-0:1 /dev/disk/by-path/pci-0000:04:00.3-usb-0:4:1.0-scsi-0:0:0:1 /dev/dis>
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd: