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?)

  • 2
    Performance will be less as the write cache is not used anymore. Properly unmount partitions using the eject / unmount options or you'll lose data.
    – Lekensteyn
    Sep 14, 2011 at 19:33
  • 4
    You can use the sync option when mounting the partition. This is not recommended though as it dramatically increases the number of writes to the thumbdrive.
    – arrange
    Sep 14, 2011 at 20:04
  • 2
    @arrange as ubuntu do the automount, is there a way to put this sync as default, so I don't need to do this in a terminal every time? And I'm aware that it'll dramatically increase the number of writes, still is what I want. Thanks! Sep 15, 2011 at 12:15
  • 1
    See askubuntu.com/questions/30762/…
    – arrange
    Sep 15, 2011 at 19:35
  • @arrange saw it, but it's still not a complete answer... Sep 21, 2011 at 12:25

1 Answer 1


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


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

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.

  • I couldn't get round to writing this how-to, thanks for doing it ;) And I also couldn't get the user unmount to work, it seems like the users option is only valid in the fstab file... This isn't a problem here ("sync"), but for a general how-to it would be.
    – arrange
    Sep 22, 2011 at 9:24
  • Thanks for answering. Unfortunately, after doing the described, I couldn't create, edit or delete any files on the pendrive. Also, it's no more automatically opening the window when I plug it. Any idea? Sep 22, 2011 at 16:14
  • By the way, I considered that the extension you typed ".rule" is wrong, and I used the same of the other files on that folder: ".rules". Sep 22, 2011 at 16:14
  • The documentation do not talk about specific extensions to use. By the way I copied wrong from the site, so it is better to use .rules to be safe. For the rest, see the edited answer.
    – enzotib
    Sep 22, 2011 at 16:41
  • Hey, I'm on Ubuntu 11.10 now, and there's a different behavior. Please, see my update. Mar 23, 2012 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.