3

I'm trying to make udisks-glue work on my Raspbian Raspberry Pi. This works fine if I manually start udisks-glue via ssh. However, I wish to start it automatically on startup.

Hence, a script at /etc/init.d/udisks-glue launches the daemon for me (as per instructions here). This works fine, but disks are mounted with root permissions (drwx------). Is it possible to make this script start the daemon as user pi, not root?

What I've tried

1) Modifying the script above, replacing

DAEMON="/usr/bin/udisks-glue" 

with

DAEMON="exec su - pi -c /usr/bin/udisks-glue"

This failed to execute.

2) Replacing this line with a reference to a custom script, which then calls exec su - pi -c /usr/bin/udisks-glue. When I connect hard drives, they aren't mounted. However, there is the appearance of correctly running processes. Looking at ps aux | grep [u]disks, I can see udisks-glue running as pi (and two udisks-daemons running as root); I get the same ps output if I manually start udisks-glue, as above.

3) I tried editing /etc/rc.local, adding the line

su pi -c "/usr/bin/udisks-glue &"

This had the same result as in (2), with udisks-glue running as pi, but not functional.

4) As per this page, running udisks-glue as root, but giving permissions of mounts to all. This works for FAT filesystems, but fails to even mount ext4. (I'd prefer mounts to be owned by user pi anyway.)

5

I had the same problem a while ago.

Solution:

  1. Fixing your configuration: create file /etc/polkit-1/localauthority/50-local.d/50-mount-as-pi.pkla with the following contents:

    [Media mounting by pi]
    Identity=unix-user:pi
    Action=org.freedesktop.udisks.filesystem-mount
    ResultAny=yes
    
  2. Fixing your init script:

    • add a variable containing the user you would like to run udisks-glue as:

      NAME=udisks-glue
      PIDFILE=/var/run/udisks.pid
      DAEMON="/usr/bin/udisks-glue"
      DAEMONUSER=pi <-- add this line
      
    • modify start-stop-daemon invocations to use the $DAEMONUSER variable:

      start) 
          log_daemon_msg "Starting Automounter" "$NAME"
      --> start-stop-daemon --start --exec $DAEMON --chuid $DAEMONUSER
          log_end_msg $?
          ;;
      stop)  
          log_daemon_msg "Stopping Automounter" "$NAME"
      --> start-stop-daemon --stop --exec $DAEMON --user $DAEMONUSER
          log_end_msg $?
          rm -f $PIDFILE
          ;;
      

      (NOTE: I removed the -- -p $PIDFILE part from the first invocation. Your regular user account probably won't have write permissions for /var/run, so you can either do what I did above or change the $PIDFILE variable to a path writable by your regular user.)

Comments on the steps you've taken:

  1. This couldn't have worked. The $DAEMON variable is used as an argument for --exec in a start-stop-daemon invocation. That argument should be an executable, while exec is a shell builtin.

  2. Doing that broke your init script. While starting udisks-glue that way worked, stopping it wouldn't as start-stop-daemon would try to stop /path/to/your/helper/script.sh instead of the actual daemon (/usr/bin/udisks-glue). Putting that aside, when you start udisks-glue in daemon mode, it doesn't generate debug messages. If you ran the following command in an interactive shell:

    # su pi -c "/usr/bin/udisks-glue -f"
    

    you'd probably see something like:

    Device file /dev/sdb1 inserted
    Trying to automount /dev/sdb1...
    Failed to automount /dev/sdb1: Not Authorized
    Device file /dev/sdb inserted
    

    which would've explained why your drives aren't mounted.

  3. This was effectively the same as 2. One extra remark: the ampersand (&) at the end was redundant as udisks-glue daemonizes by default.

  4. Again, running udisks-glue in foreground would've explained the problem for non-FAT filesystems:

    Device file /dev/sdb1 inserted
    Trying to automount /dev/sdb1...
    Failed to automount /dev/sdb1: Mount option dmask=0 is not allowed
    Device file /dev/sdb inserted
    

    Also note that if you would like to change the owner of an ext4 mountpoint, you need to chown it after mounting.

  • Wow. This is quite simply the best answer I've received. Clear, addressed all the issues, and even explained my errors. I wish I could + more than 1. Thanks. – Sparhawk Jul 12 '14 at 10:15
  • I've reinstalled the system on the Pi, removing a few packages to create a minimal install. These instructions no longer work, and I suspect this is because udisks-glue requires policykit-1. However, I'm having trouble installing it. I'm not sure if you can help, but I thought it useful to link there anyway. – Sparhawk Jul 15 '14 at 10:46

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.