D
D
Dmitry Plotnikov2017-06-06 04:22:19
linux
Dmitry Plotnikov, 2017-06-06 04:22:19

Automount a USB drive via udev. Why does it turn off after 1-2 seconds?

There is RASPBERRY PI 3 with Raspbian Wheezy, purely console mode, X is not and is not needed.
The task is to automatically mount the USB drive, and regardless of the user's login, the drive is used by background processes.
Devices sda1, sdb1 are assigned to fstab - periodically the system defines them differently.

/dev/sda1 /media/exfat exfat defaults,noauto 0 0
/dev/sdb1 /media/exfat exfat defaults,noauto 0 0

FS type - exfat. Noauto - on purpose, otherwise, in the absence of a USB drive during boot, we get a transition to emergency mode. There is a root user in the plugdev group.
Automount rules are written - so far the simplest:
/etc/udev/rules.d/10-automount.rules
ACTION=="add", KERNEL=="sd[ab][0-2]", RUN+="/bin/mount /dev/%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL= ="sd[ab][0-2]", RUN+="/bin/umount /media/exfat"

With pmount the situation is exactly the same.
As a result, the situation is:
1. We connect the USB drive
2. The UDEV-event "add" arrives
3. The drive is mounted and available
4. After 1-2 seconds, the UDEV-event "change" arrives
5. The drive is unavailable, the mount point looks like this:
[email protected]:/media# ls -la
ls: cannot access exfat: Transport endpoint is not connected
total 8
drwxr-xr-x  3 root root 4096 Jun  5 23:19 .
drwxr-xr-x 21 root root 4096 Apr 10 09:58 ..
d?????????  ? ?    ?       ?            ? exfat

Output from udevadm monitor here

KERNEL[4204.018204] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3 (usb)
KERNEL[4204.018489] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0 (usb)
KERNEL[4204.019167] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14 (scsi)
KERNEL[4204.019406] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/scsi_host/host14 (scsi_host)
UDEV [4204.026059] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3 (usb)
UDEV [4204.030635] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0 (usb)
UDEV [4204.031852] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14 (scsi)
UDEV [4204.033554] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/scsi_host/host14 (scsi_host)
KERNEL[4205.012443] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0 (scsi)
KERNEL[4205.012980] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0 (scsi)
KERNEL[4205.013305] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/scsi_disk/14:0:0:0 (scsi_disk)
KERNEL[4205.013380] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/scsi_device/14:0:0:0 (scsi_device)
KERNEL[4205.013649] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/scsi_generic/sg0 (scsi_generic)
KERNEL[4205.014150] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/bsg/14:0:0:0 (bsg)
UDEV [4205.014318] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0 (scsi)
UDEV [4205.018776] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0 (scsi)
UDEV [4205.019058] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/scsi_disk/14:0:0:0 (scsi_disk)
KERNEL[4205.020740] add /devices/virtual/bdi/8:0 (bdi)
UDEV [4205.022555] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/scsi_device/14:0:0:0 (scsi_device)
UDEV [4205.023574] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/scsi_generic/sg0 (scsi_generic)
UDEV [4205.025360] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/bsg/14:0:0:0 (bsg)
UDEV [4205.025886] add /devices/virtual/bdi/8:0 (bdi)
KERNEL[4205.030691] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/block/sda (block)
KERNEL[4205.030885] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/block/sda/sda1 (block)
UDEV [4205.129575] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/block/sda (block)
KERNEL[4205.221355] add /devices/virtual/bdi/8:1-fuseblk (bdi)
UDEV [4205.222509] add /devices/virtual/bdi/8:1-fuseblk (bdi)
UDEV [4205.256254] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/block/sda/sda1 (block)
KERNEL[4208.266520] change /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/block/sda/sda1 (block)
UDEV [4208.327233] change /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.3/1-1.3:1.0/host14/target14:0:0/14:0:0:0/block/sda/sda1 (block)

Manually with the same commands from 10-automount.rules everything is mounted and remains in operation.
PS Maybe, based on the task (to use the drive as background processes without user login), I didn’t go in the wrong direction at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Plotnikov, 2017-06-07
@dimap101

In the process of checking various possible causes, it was possible to establish that such a problem exists only with exFAT and NTFS file systems. Drives with FAT32 are mounted normally. But you need exFAT (or NTFS, although it is undesirable) - 64GB drives.
The only thing left to do is to understand why exFAT automounting works crookedly, but manually works fine.
Checked through udevadm monitor - at FAT32 UDEV-event "change" does not appear.
Also, through "udevadm monitor --property" I checked all the data for "add" and "change" - everything is identical, i.e. in fact, there are no prerequisites for the appearance of "change".
UPDATE: I found a similar problem on several forums and supposedly it is that udev kills all child processes within 30 seconds. But still it is not clear what kind of connection is 30 seconds, and disappears after 1-2 seconds on the UDEV-event "change", and FAT32 works fine.
Nevertheless, I began to look for another solution, I did not use HAL due to obsolescence. Installed devmon from the udevil package, set it to autoload, everything works, there are no problems.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question