This page looks best with JavaScript enabled

Mount a WebDav resource inside a Linux container

 ·   ·  ☕ 3 min read

Backstory

For the past few years I’ve been using NextCloud as my file hosting software suite of choice. It has clients for Android, Windows, Linux, Web… you name it. But, what happens when you want to browse your files from within a linux terminal?

There are a lot of ways to go about this, for example you can get a text based browser like lynx. Or mess around with curl. If you follow this guide, you will be able to mount it in your filesystem and browse as if it was a local directory.

NextCloud supports WebDAV. We’ll take advantage of that and a tool called davfs2.

Step 1: Installing davfs2

Update your system
apt update && apt upgrade

Install davfs2
apt install davfs2

Step 2: Configuring davfs2

Stock configuration works out of the box. You’ll have to save your username and password in a plain text file though. Make sure its file access permissions are restricted to root user only.

Store username and password

Add /webdav your-username your-password to /etc/davfs2/secrets.
Then chmod 600 /etc/davfs2/secrets.

Disable file locks

NextCloud seems like it doesn’t support file locks, so we’ll disable them (otherwise we get warnings).

Open /etc/davfs2/davfs2.conf and add

[/webdav]
use_locks 0

Step 4: Mounting

Update fstab (optional)

Open /etc/fstab in your favourite editor and add
https://example.com/remote.php/webdav/ /webdav davfs defaults,uid=[a userid],_netdev,noauto 0 0
to the end.

Mount at boot

If you would like to mount your resource at boot, change the noauto parameter to auto in /etc/fstab.

Troubleshooting

Can’t open fuse device

If your container is unprivileged, add features: fuse=1 to its config file, otherwise you’ll get errors like these:

/sbin/mount.davfs: loading kernel module fuse
/sbin/mount.davfs: loading kernel module fuse failed
/sbin/mount.davfs: waiting for /dev/fuse to be created
/sbin/mount.davfs: can't open fuse device
/sbin/mount.davfs: trying coda kernel file system
/sbin/mount.davfs: no free coda device to mount

Other

If you are having troubles, a good place to start is to make sure selinux, apparmor or cgroup are not blocking root access to the mount point.

Sources

davfs2

  1. Davfs2 on ArchWiki
  2. Comments inside /etc/davfs2/davfs2.conf
  3. Comments inside /etc/davfs2/secrets

automount

  1. Fstab on ArchWiki
  2. Systemd automount unit configuration
  3. Systemd mount unit configuration
Share on
Support the author with