2

I have an ARM-based ODROID XU4 running Ubuntu 16.04. I want to automatically mount USB sticks on /media/usbdisk when they are inserted. Now I'm facing the problem that the devices don't seem to be correctly mounted.

I can mount and access the stick manually using

sudo mount -t ntfs /dev/sda1 usbdisk/

Then I added the following rule as /etc/udev/rules.d/11-media-by-label-auto-mount.rules

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"  
# Filesystem-specific mount options  
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"  
# Mount the device  
ACTION=="add", RUN+="/bin/mkdir -p /media/usbdisk", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/usbdisk"  
# Clean up after removal  
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/usbdisk", RUN+="/bin/rmdir /media/usbdisk"  
# Exit  
LABEL="media_by_label_auto_mount_end"

When I add a USB stick the folder /media/usbdisk gets created, however the file system is not mounted correctly. ls on /media says:

/media$ ls -la
ls: cannot access 'usbdisk': Transport endpoint is not connected
total 24
drwxr-xr-x  4 root root  4096 Feb 11 16:51 .
drwxr-xr-x 22 root root  4096 Feb 11 17:03 ..
drwxr-xr-x  3 root root 16384 Jan  1  1970 boot
d?????????  ? ?    ?        ?            ? usbdisk

and I cannot cd into it

cd usbdisk 
-bash: cd: usbdisk: Transport endpoint is not connected

dmesg output is:

[  221.871579] [c2] usb 4-1.2: new SuperSpeed USB device number 3 using xhci-hcd
[  221.885847] [c2] usb 4-1.2: Parent hub missing LPM exit latency info.  Power management will be impacted.
[  221.887582] [c2] usb-storage 4-1.2:1.0: USB Mass Storage device detected
[  221.888007] [c2] scsi2 : usb-storage 4-1.2:1.0
[  222.886208] [c2] scsi 2:0:0:0: Direct-Access     SanDisk  Extreme          0001 PQ: 0 ANSI: 6
[  222.887373] [c2] sd 2:0:0:0: Attached scsi generic sg0 type 0
[  222.887626] [c2] sd 2:0:0:0: [sda] 250085376 512-byte logical blocks: (128 GB/119 GiB)
[  222.888235] [c2] sd 2:0:0:0: [sda] Write Protect is off
[  222.888257] [c2] sd 2:0:0:0: [sda] Mode Sense: 53 00 00 08
[  222.888830] [c2] sd 2:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[  222.893348] [c2]  sda: sda1
[  222.897331] [c2] sd 2:0:0:0: [sda] Attached SCSI removable disk

Edit - found out some more details:

I minimized the udev rule to basically just the mount and unmount commands. The problem persisted. Using journalctl -f I could see a message from udev, the mount command exits with an error, return code is 21.

Even more surprising - I have a script running on startup of the device through systemd that is supposed to log to the usb disk. This script succeeds and writes something to the stick. So obviously the device is mounted but I don't have the rights to access it. Any idea in what mode / for which user udev runs?

Thanks for your help!

0

udev run scripts as root. So change the permissions of the created folder /media/usbdisk before mounting the block device.

| improve this answer | |

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.