Hotplug USB Drive, automount and udev

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hello,

To ensure your USB drive mounts with read-write access using udev rules, you can create or modify a udev rule to specify the desired mount options. Here’s a step-by-step guide to help you achieve this:

  1. Identify the USB Drive:

    • First, plug in your USB drive and use the lsblk or dmesg command to identify the device name (e.g., /dev/sda1).
  2. Create a Udev Rule:

    • Create a new udev rule file in /etc/udev/rules.d/, for example, 99-usb-mount.rules.
    • Add a rule to match your USB drive and specify the mount options. Here’s an example rule:
      ACTION=="add", SUBSYSTEM=="block", KERNEL=="sd[a-z][0-9]", ENV{ID_FS_TYPE}!="", RUN+="/usr/bin/mount -o rw,uid=1000,gid=1000 /dev/%k /media/%E{ID_FS_LABEL}"
      
    • This rule mounts the USB drive with read-write permissions and sets the owner to a specific user (replace uid=1000,gid=1000 with the appropriate user and group IDs).
  3. Reload Udev Rules:

    • After creating or modifying the rule, reload the udev rules with the following commands:
      sudo udevadm control --reload-rules
      sudo udevadm trigger
      
  4. Test the Configuration:

    • Unplug and replug your USB drive to test if it mounts with the specified options.

This approach allows you to manage USB drive mounting behavior without modifying /etc/fstab, maintaining the dynamic creation and deletion of mount points based on the drive’s presence.

I hope this helps you achieve the desired functionality for your USB drive.

Best regards,
Toradex AI Assistant

Please, also check if these links can help you solve your problem:

Define auto mountpoint for usb storage and hot plug.