Wednesday, May 8, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 12581  / 1 Year ago, fri, march 17, 2023, 8:56:12

If I edit the files on my pendrive, and then just remove it physically, the data will not be recorded. I have to click "eject", and so the led starts to blink, and the data starts to be recorded.



How can I change this, so that the data is recorded instantly when changed?



update: Ubuntu 11.10



In Ubuntu 11.10 I wrote the rules file (from @enzotib answer), and works, but gives the following message when I try to eject/unmount:



enter image description here



(should I start another question for Ubuntu 11.10?)


More From » 10.10

 Answers
3

Following the question (and answer) that @arrange shows in his comment, let's create a new file



/etc/udev/rules.d/11-media-by-label-auto-mount.rules


and write into it the following content (see udev::Mount under /media; use partition label if present)



KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# Global mount options
ACTION=="add", ENV{mount_options}="relatime,sync"
# Filesystem-specific mount options
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,uid=1000,gid=1000,umask=002"

# Mount the device
ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"

# Clean up after removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"

# Exit
LABEL="media_by_label_auto_mount_end"


I have done some little modifications with respect to that reported on the website




  • added the sync option to ENV{mount_options}

  • modified the gid=100 option to uid=1000,gid=1000, where the number are relative to your used-id and group-id, as returned by id -u and id -g



The second one make you the owner of all files on the mounted partition, so no permission problem can arise. Obviously this is not the case if more than a single user should access the files, but this can be handled in other ways.



For non-windows filesystems, owner and group are metadata on the filesystem, and cannot be changed by a mount option.



The new rule is immediately active (udev uses inotify to detect new and modified rule files).



The mounted drive is not automatically opened in a file manager window, as you can see, and this is difficult to achieve, given that the mounting process is owned by root, and do not have access to your graphical login session. But the drive is on your desktop, so a simple double-click will open it.



Unfortunately I cannot get the desktop right-click unmount to work, but this is not a big problem: having the sync option in place, you can simply unplug the device, and the udev rule take care of removing the entry from /proc/mounts and removing the mount-point.


[#43492] Saturday, March 18, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
zebrla

Total Points: 356
Total Questions: 110
Total Answers: 120

Location: Sudan
Member since Tue, Aug 3, 2021
3 Years ago
;