mirror of
https://codeberg.org/wonky/udev-usb-sync.git
synced 2024-09-19 23:30:37 +02:00
initial commit
This commit is contained in:
parent
ea7f43726a
commit
9e017c0465
3 changed files with 61 additions and 0 deletions
3
99-usb-sync.rules
Normal file
3
99-usb-sync.rules
Normal file
|
@ -0,0 +1,3 @@
|
|||
# rule to disable write cache for usb storage
|
||||
# requires hdparm to be installed
|
||||
ACTION=="add|change", KERNEL=="sd[a-z]", ENV{ID_USB_TYPE}=="disk", RUN+="/usr/bin/hdparm -W 0 /dev/%k"
|
17
PKGBUILD
Normal file
17
PKGBUILD
Normal file
|
@ -0,0 +1,17 @@
|
|||
# Maintainer:
|
||||
pkgname='udev-usb-sync'
|
||||
pkgver=0.1
|
||||
pkgrel=1
|
||||
pkgdesc='Disable writecache when USB storage device is plugged'
|
||||
arch=('any')
|
||||
url='https://codeberg.org/wonky/udev-usb-sync'
|
||||
license=('MIT')
|
||||
depends=('hdparm')
|
||||
provides=("${pkgname}")
|
||||
source=('99-usb-sync.rules')
|
||||
sha256sums=('ed0253bbbd5b64529efd752978ba17176e3ff23d3f7f220bbacd3fa3a3691df9')
|
||||
|
||||
package() {
|
||||
install -d -m755 $pkgdir/etc/udev/rules.d
|
||||
cp ${startdir}/99-usb-sync.rules "${pkgdir}/etc/udev/rules.d"
|
||||
}
|
41
README.md
41
README.md
|
@ -1,2 +1,43 @@
|
|||
# udev-usb-sync
|
||||
|
||||
Linux filesystem cache
|
||||
|
||||
Linux agressively caches files in order to improve overall performance.
|
||||
|
||||
When copying large amount of files to an USB storage this often results in some wait time until the device can be safely removed.
|
||||
|
||||
How long you have to wait depends on your system and the quality of the USB storage device.
|
||||
|
||||
Numerous issues regarding this has resulted in various suggestions involving sysctl tweaks and trim.
|
||||
udev rule to disable write-cache
|
||||
|
||||
In another place one user threw in an udev rule which would disable write-cache for devices when they were added and while it was just an idea - it triggered my curiosity.
|
||||
|
||||
I dug into the intricacies of udev and found a method to only target USB storage devices.
|
||||
|
||||
The final rule
|
||||
|
||||
```
|
||||
# rule to disable write cache for usb storage
|
||||
# requires hdparm to be installed
|
||||
ACTION=="add|change", KERNEL=="sd[a-z]", ENV{ID_USB_TYPE}=="disk", RUN+="/usr/bin/hdparm -W 0 /dev/%k"
|
||||
```
|
||||
|
||||
The rule activates on
|
||||
|
||||
* add or change
|
||||
* kernel event involvinig disk devices sd[a-z]
|
||||
* only if the device environment ID_USB_TYPE==‘disk’
|
||||
* run hdparm -W 0 /dev/%K
|
||||
|
||||
Create a file in /etc/udev/rules.d/99-usb-sync.rules and paste above content into the file and save it.
|
||||
|
||||
Install hdparm package.
|
||||
|
||||
sudo pacman -Syu hdparm
|
||||
|
||||
Then plug an usb device - open in your file manager - copy a huge amout of files to the device - when the copy is done - click eject in the file manager - and the device ejects immediately.
|
||||
|
||||
For those preferring that I have created a PKGBUILD 2 for it which will pull the hdparm dependency upon installation.
|
||||
|
||||
pamac build udev-usb-sync
|
||||
|
|
Loading…
Reference in a new issue