rclone: Mounting using AutoFS doesn't work

Output of rclone version

rclone v1.47.0

  • os/arch: linux/amd64
  • go version: go1.12.3

Describe the issue

I have been trying to add a few rclone-mounts to my autofs configuration without success

Mounting the drive using the exact commandline that autofs uses works though, so something is weird…

handle_packet_missing_indirect: token 20, name TeamDrive-Archive, request pid 3291
attempting to mount entry /media/GoogleTest/TeamDrive-Archive
lookup_mount: lookup(file): looking up TeamDrive-Archive
lookup_mount: lookup(file): TeamDrive-Archive -> -fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf	:rclonefs\#dom-td01\:
parse_mount: parse(sun): expanded entry: -fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf	:rclonefs\#dom-td01\:
parse_mount: parse(sun): gathered options: fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf
parse_mount: parse(sun): dequote(":rclonefs\#dom-td01\:") -> :rclonefs#dom-td01:
parse_mount: parse(sun): core of entry: options=fstype=fuse,config=/home/scuttle/.config/rclone/rclone.conf, loc=:rclonefs#dom-td01:
sun_mount: parse(sun): mounting root /media/GoogleTest, mountpoint TeamDrive-Archive, what rclonefs#dom-td01:, fstype fuse, options config=/home/scuttle/.config/rclone/rclone.conf
do_mount: rclonefs#dom-td01: /media/GoogleTest/TeamDrive-Archive type fuse options config=/home/scuttle/.config/rclone/rclone.conf using module generic
mount_mount: mount(generic): calling mkdir_path /media/GoogleTest/TeamDrive-Archive
mount_mount: mount(generic): calling mount -t fuse -o config=/home/scuttle/.config/rclone/rclone.conf rclonefs#dom-td01: /media/GoogleTest/TeamDrive-Archive

Just running “mount -t fuse -o config=/home/scuttle/.config/rclone/rclone.conf rclonefs#dom-td01: /media/GoogleTest/TeamDrive-Archive” mounts the folder just fine, but when automount tries it, it just hangs on that last line

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 58 (30 by maintainers)

Commits related to this issue

Most upvoted comments

Hm, just wanted to add… none of my idle autofs-mounts shows up in /proc/mounts, they only show up there when they are actually mounted. No matter if it’s a rclone-mount or a regular filesystem mount

Thank you. It explains why you don’t hit the unmount bug. Looks like the pseudo-mount abstraction is used only by systemd automounter while the Autofs daemon uses an alternative kernel mechanism for that. I will mention it when I submit final patch for rclone.

@ncw

Let’s close this ticket.

I will open another PR with ultimate goal to get rid of shell wrappers so rclone like sshfs can work natively with mount and autofs!

ln -s /usr/bin/rclone /sbin/mount.rclone
mount -t rclone remote:path /mnt/remote -o vfs-mode=full ...

My last open task is to teach cobra translate -o xxx into rclone flags…

ok done 😃

Well, back when the bug was originally opened, there were some minor adjustments, but right now it looks like this:

Autofs: Music -fstype=fuse.rclonefs,config=/home/scuttle/.config/rclone/rclone.conf,allow-other,default-permissions,allow-non-empty,max-read-ahead=16M,uid=1000,gid=1000

Rclonefs:

#!/bin/bash
remote=$1
mountpoint=$2
shift 2

# Process -o parameters
while getopts :o: opts; do
    case $opts in
        o)
            params=${OPTARG//,/ }
            for param in $params; do
                if [ "$param" == "rw"   ]; then continue; fi
                if [ "$param" == "ro"   ]; then continue; fi
                if [ "$param" == "dev"  ]; then continue; fi
                if [ "$param" == "suid" ]; then continue; fi
                if [ "$param" == "exec" ]; then continue; fi
                if [ "$param" == "auto" ]; then continue; fi
                if [ "$param" == "nodev" ]; then continue; fi
                if [ "$param" == "nosuid" ]; then continue; fi
                if [ "$param" == "noexec" ]; then continue; fi
                if [ "$param" == "noauto" ]; then continue; fi
                if [[ $param == x-systemd.* ]]; then continue; fi
                trans="$trans --$param"
            done
            ;;
        \?)
            echo "Invalid option: -$OPTARG"
            ;;
    esac
done

# exec rclone
trans="$trans $remote $mountpoint"
# NOTE: do not try "mount --daemon" here, it does not play well with systemd automount, use '&'!
# NOTE: mount is suid and ignores pre-set PATHs -> specify explicitely
PATH=$PATH rclone mount $trans </dev/null >/dev/null 2>/dev/null &

# WARNING: this will loop forever if remote is actually empty!
until [ "`ls -l $mountpoint`" != 'total 0' ]; do
    sleep 1
done

The mount:

[music]
type = drive
scope = drive
service_account_file = /home/scuttle/.config/rclone/serviceaccounts01/009.json
team_drive = XXXXXXXXXXXXXXX

Tried the new binary, and works fine that one too

scuttle@ranma ~ (master)> rclone version
rclone v1.56.0
- os/version: arch rolling (64 bit)
- os/kernel: 5.13.5-arch1-1 (x86_64)
- os/type: linux
- os/arch: amd64
- go/version: go1.16.6
- go/linking: dynamic
- go/tags: none

I can make rclone mount work with systemd.mount and systemd.automount on Linux using a wrapping shell script.

My dev branch rclone-for-autofs has two patches against latest rclone 1.56 (of course it can fork using --daemon):

  1. the parent process can wait for forked child to finish mounts, using the --daemon-timeout=30s flag.
  2. neither parent nor child try to list files in the mountpoint, they just parse the Linux API file /proc/mounts.

I use systemd files from https://gist.github.com/ivandeex/038ac805293f44e6859c3c876f586c46:

  • /etc/systemd/system/mnt-mysftp.mount
  • /etc/systemd/system/mnt-mysftp.automount
  • /sbin/mount.rclone

The former file is a shell wrapper invoked by systemd when it establishes a type=rclone mount. Systemd passes mount options as -o option=value to the wrapper, and expects it to do the mount and exit with zero status.

The path must be fully mounted when the wrapper exits, so the default way rclone mount --daemon works (parent exits immediately without waiting for mount) is not enough. The wrapper must ensure that mount is completely established by the time it exits, or systemd will detect failure. I tried three methods to ensure this.

  1. I don’t use the --daemon flag. The wrapper runs rclone mount ... & i.e. backrounds it, then polls /proc/mounts until the mount establishes. This method works fine both with systemd mount and automount.

  2. The wrapper just translates -o opt=val into rclone flags like --opt=val and invokes rclone mount --daemon --daemon-timeout=30s ..... This way rclone does all: it forks, the child mounts, the parent waits for the child and then exits.

  3. Combination of 1 and 2. Wrapper translates args and invokes rclone mount --daemon ..., then polls /proc/mounts.

All methods work fine with systemd mount. After systemctl start mnt-mysftp.mount I can access /mnt/mysftp without problems. But if I stop mount, start automount and try to access ls /mnt/myfork, methods 2 and 3 fail with error rclone: fusermount: /mnt/myfork: ENODEV. This means for sure that https://github.com/sevlyar/go-daemon (rclone calls it for --daemon) is incompatible with autofs/automount.

I am investigaing this, trying kludges on the above branch, etc etc…

Sorry we don’t use systemd so I can’t test it with it… Let me know if I can help