[Guide] Mount Nextcloud (WebDAV) folders locally with davfs

Hello all!

For those interested, the Chum repo now has davfs2 available.

davfs2 is a FUSE (Filesystem in Userspace) driver that allows you to mount remote network filesystems locally.

This is a small example guide how to set it up:

This guide assumes you have a Nextcloud (or other WebDAV server, e.g. SharePoint) and know your account information. We also use nemo as the SFOS user in the examples, adjust for your default user ;).

1. Install the Chum repo:
there are various ways of doing that, in case you haven’t already follow the Guide here.
But basically it’s devel-su pkcon install -y sailfishos-chum && pkcon refresh.

2. Install davfs2:

$ devel-su pkcon install -y davfs2

3. Create a mount point:

$ mkdir ${HOME}/mnt/cloud

4. Create a fstab entry (optional, but makes stuff convenient):

Use devel-su to become root and edit /etc/fstab. Add something like:

 https://cloud.example.org/remote.php/dav/files/myusername/ /home/nemo/mnt/cloud  davfs  _netdev,user,noauto 0 0

Note the options at the end: _netdev,user,noauto, these are important or your device might hang at boot or reboot.

5. Test

Basically you’re ready to mount things now, however at the moment only root may do that. Try it:

$ devel-su
# mount /home/nemo/mnt/cloud

You will be prompted for username and password. If they are correct, you can now browse your files at the mounted location. (Obviously you need to be online for this to work)
Umnount again after testing:

$ devel-su
# umount /home/nemo/mnt/cloud

6. Add the user to the mount group:

For reasons, davfs2 requires users to be in a dedicated group to be able to execute it. I have configured the package to use the mount group for this. So add your user to that group:

 $ devel-su gpasswd -a nemo mount

7. Log in anew:

Open a new Terminal, or ssh connection as user to pick up the group change. Doing id should show that you are now member of the mount group

8. Test again

As user, try the mount now, without devel-su:

$ mount /home/nemo/mnt/cloud

Again, username and password prompt, and you can browse your files.

9. (Optional): Store authentication information:

You should now have a new directory at ${HOME}/davfs2. Inside you have a file called secrets. It allows you to store either username, username and password, or a client certificate for authentication. Follow the comments in that file and add you information.

    /home/nemo/mnt/cloud    myusername  secretapppassword

It should be obvious that storing your password here is not a great idea. At least create an “app password” for your device on the server and use that, or if you can use revokable client certificates.

10. (Optional): Tune some settings:

There is also a file ${HOME}/davfs2/davfs2.conf where you can tune things. Most of the defaults are fine, but I like doing these modifications:

# use a more XDG-compliant cache location:
cache_dir         ~/.cache/davfs2   # per user cache

# tune for slow/bad network conditions
max_upload_attempts 25
dir_refresh     120                # seconds
delay_upload    20
cache_size      128                # MiByte

There is also the equivalent system-wide location at /etc/davfs2/ but you probably do not need to edit anything there.

Hope this is useful, good luck.

Some notes

Be careful when browsing the mounted directory. If your network is flakey or low-bandwidth, or high-latency, this may cause applications to hang while they try to browse stuff.

It may also be a good idea to add the mount to the blacklist of Tracker so it doesn’t try to index the remote files, but that is beyond the scope of this guide.

Oh, and the chum build is relatively new, if you find anything not working please feel free to bug me about it. Note that I have nothing to do with the software itself, I only package it.

References:

14 Likes

I follow your Guide step-by-step but it has some issues and should be reworked:

Point 8. leads to:

[defaultuser@XperiaXCompact Drive]$ mount /home/defaultuser/Drive
/sbin/mount.davfs:/home/defaultuser/.davfs2/davfs2.conf:22: unknown option

Line 22 in /home/defaultuser/.davfs2/davfs2.conf is:

dav_user mount # system wide config file only

When uncomment this line, davfs moan also about line 23:

dav_group mount # system wide config file only

When uncommenting this line too, the defaultuser can mount it but then the copied files are locked on Windows until i set the Execute-Flag for Others on the copied Files/Dir. But this is maybe a Cross-Plattform Problem with Windows?

1 Like

Thanks for the report, I’ll add some notes to the guide (EDIT: I can’t the post is too old), and perhaps change the package too, it probably doesn’t even need those two things set.

About Windows I have no idea, which kind of server software is it? IIS? SharePoint? Something else?

Synology WebDAV Module

If you have lots of problems with this, you can also mount dav sources using rclone.
There’s no package for this tool but you can use the arm binary from the rclone website, it works.

1 Like

Maybe it helps if you use use_locks 0 in the config file?

Maybe it helps if you use use_locks 0 in the config file?

Bingo! Thats fixed it! Thank you!

Its not that fast, but that depends of course from the connection. Maybe rclone is easier here and faster?

I haven’t done any benchmarks between the two - but while rclone is a really cool tool, speed isn’t really one if it’s main features IME :wink:

But it has a large number of tunables and options to play around with. And of course it supports a great many cloudy backends and other features.

I dont need syncing, my NAS has a 2TB HDD and is almost full. My Sony X Compact has 32gb + 64GB MicroSD, so not enough Space for full sync but with davfs2 luckily not necessary. Thankfully most Apps allow save Big Data on MicroSD, for example the Offline Maps of Pure Maps.

I am still surprised how brave the X Compact is in terms of Speed. Its not that slow you would expect from a End 2016 Device. I spend it a new original Battery, now its last 36 - 45 hours. The Sony Batterys have very good Build Quality and last very long in Lifetime. Thats maybe one Reason why Sony Smartphones are a little bit more Expensive like the Competition.

What I meant is that rclone has, in addition to all its syncing features, a mount function which works almost exactly like davfs (but can mount more than just DAV but any backend).

2 Likes

Does rclone mount deal with samba as a backend? I’m reading now, but suspect you will be faster.

Ah, got it: rclone/backend/smb at master · rclone/rclone · GitHub

Yes, or rather

1 Like

Ah, may not work for me: This relies on go-smb2 library for communication with SMB protocol.

Q: Does WebDAV mirror the whole content of the netdrive to the Sailfish phone and use huge memory space on the phone? Or does it only access the netdrive and show it’s content and copies to the phone only on request?

If it’s a mount, it just shows the contents and shouldn’t copy anything. Did you mean a mount or a sync?

1 Like

As I understood @nephros in post # 1, it’s a mount, and that’s what I want.

Yes, the second (plus a bit of caching).

There is no persistent storage.
If you unmount it it’s “gone” :wink:

That is true for both davfs and rclone mount.

1 Like

It’s gone as a mount! But the storage remains persistent, where ever it was. If you write to that mount and unmount it, the data you wrote to it will persist.

1 Like