Sounds strange, I have a shell script that it gets trigger by udev rules, to mount attached USB device to the system file tree. The script runs when an usb device attaches to system, so the rules seems to be fine. I monitor how the script progress by syslog, and it also goes fine, and even mount command returns zero, and it says: root[1023]: mount: /dev/sda1 mounted on /media/partitionlabel.But at the end the device is not mounted, it is not listed in /etc/mtab - /proc/mounts - findmnt - mount. and if I run umount on device, it also says, the device is not mounted.However If I run the script manually as a root from terminal, then it works perfect and device gets mount, but not when it runs by udev.I've added 8 second sleep time to the start of the script, to make sure it's not a timing problem and also removed number from rules file name to make sure udevd would put the new rules at the bottom of rules queue, and script would run after other system rules, but no success.The syslog:(right after the device attached)kernel: usb 1-1.2: new high-speed USB device number 12 using dwc_otgkernel: usb 1-1.2: New USB device found, idVendor=058f, idProduct=6387kernel: usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=3kernel: usb 1-1.2: Product: Mass Storagekernel: usb 1-1.2: Manufacturer: Generickernel: usb 1-1.2: SerialNumber: 24DCF568kernel: usb-storage 1-1.2:1.0: USB Mass Storage device detectedkernel: scsi host6: usb-storage 1-1.2:1.0kernel: scsi 6:0:0:0: Direct-Access     Generic  Flash Disk       8.07 PQ: 0 ANSI: 4kernel: sd 6:0:0:0: [sda] 1968128 512-byte logical blocks: (1.00 GB/961 MiB)kernel: sd 6:0:0:0: [sda] Write Protect is offkernel: sd 6:0:0:0: [sda] Mode Sense: 23 00 00 00kernel: sd 6:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn't support DPO or FUAkernel:  sda: sda1kernel: sda: p1 size 1968126 extends beyond EOD, enabling native capacitykernel:  sda: sda1kernel: sda: p1 size 1968126 extends beyond EOD, truncatedkernel: sd 6:0:0:0: [sda] Attached SCSI removable diskroot[1004]: /usr/local/sbin/udev-auto-mount.sh - status: started to automount sda1root[1019]: /usr/local/sbin/udev-auto-mount.sh - status: Device Label is partitionlabel and Filesystem is vfat.root[1021]: /usr/local/sbin/udev-auto-mount.sh - status: mounting the device sda1 by filesystem vfat to /media/partitionlabel.root[1023]: mount: /dev/sda1 mounted on /media/partitionlabel.root[1024]: /usr/local/sbin/udev-auto-mount.sh status: mount command proceed for vfat, retval is 0root[1025]: /usr/local/sbin/udev-auto-mount.sh - status: succeed!Configs:/etc/udev/rules.d/local-rules:The defined rule in udev is:# /etc/udev/rules.d/local-rulesENV{ID_BUS}==usb,     ACTION==add,  ENV{DEVTYPE}==partition,      \          RUN+=/usr/local/sbin/udev-automounter.sh %k $ENV{ID_FS_LABEL_ENC}udev-auto-mount.shThe script starts by another script which defined in the udev rule. It so straight, it makes mount point directory and mounts the usb device to the mount point using its file system type and some regular options. I've added -v option to the mount command to be more verbose and also redirected all outputs to syslog, so I can see how it runs, but it not says too much.#!/bin/sh## /usr/local/sbin/udec-auto-mount.sh##logger -s $0 - status: started to automount ${1}DEVICE=$1sleep 8 #...#...# Checking inputs, getting filesystem type (ID_FS_TYPE), partition label# (ID_FS_LABEL) and ...mkdir /media/${ID_FS_LABEL}logger -s $0 - status: mounting the device ${DEVICE} by filesystem ${ID_FS_TYPE} to /media/${ID_FS_LABEL}.case $ID_FS_TYPE in    vfat)   mount -v -t vfat -o sync,noatime,nosuid,nodev /dev/${DEVICE} /media/${ID_FS_LABEL} 2>&1 | logger        let retVal=$?        logger -s $0 status: mount command proceed for vfat, retval is ${retVal}        ;;    *)  mount -v -t auto -o sync,noatime /dev/${DEVICE} /media/${ID_FS_LABEL}        ;;esacif [ ${retVal} -eq 0 ]; then    logger -s $0 - status: succeed!    exit 0else    logger -s $0 Error: unable to mount the device ${DEVICE}, retval is ${retVal}    rmdir /media/${ID_FS_LABEL}fiexit 0Maybe it helps:Sometimes, after the script fails to mount the USB device, when I detach the device, some error come to syslog like:kernel: usb 1-1.2: USB disconnect, device number 11systemd-udevd[143]: error: /dev/sda: No such file or directorysystemd-udevd[977]: inotify_add_watch(7, /dev/sda, 10) failed: No such file or directoryEdit:This is 'mount' version:$ mount -V:mount from util-linux 2.27.1 (libmount 2.27.0: assert, debug)
Linux - mount command returns zero/0 but not working
linux;arch linux;mount;automounting
Finally found the answer here.Actually the problem were came from systemd-udevd which succeeded original udev. The systemd-udevd creates it's own mirror of root file system, when the 'udev' rule mount the device, it gets mounted and is accessible from:/proc/{PID of systemd-udevd service}/root/{path to mount point}but it is not visible from main root filesystem /.archlinux's wiki (here) suggests:Warning: To mount removable drives, do not call mount from udev rules. In case of FUSE filesystems, you will get Transport endpoint not connected errors. Instead, you could use udisks that handles automount correctly or to make mount work inside udev rules, copy /usr/lib/systemd/system/systemd-udevd.service to /etc/systemd/system/systemd-udevd.service and replace MountFlags=slave to MountFlags=shared.[3] Keep in mind though that udev is not intended to invoke long-running processes.Solution:I copied /usr/lib/systemd/system/systemd-udevd.service to the /etc/systemd/sytem/ directory and replaced MountFlags=slave by MountFlags=shared. then restarted the system, and now everything works fine.