Hello @everybody,
As I have two NAS devices, I’ve always wanted to be able to connect to them from anywhere, as quickly and easily as possible.
There was just one thing missing: for my two NAS devices to mount automatically when I start up my computer.
I tried using the SMB protocol, which was the one I’d always used to connect, but to no avail.
I then turned to the WebDAV protocol, which I use to synchronise my calendars.
I’d managed to do this quite easily, but suddenly it was no longer possible from Budgie 24.04 onwards.
I then turned to @jlb, who is well known on this forum for his tips and tricks, as well as for his invaluable help in all circumstances.
Thanks to his boundless patience, I managed to sort out my problem.
The sources he suggested I use are:
- Setting up WebDAV – why is it so difficult??
Reddit - ArclLinux : Davfs2 using systemd
davfs2 - ArchWiki - Achlinux : Mount a WebDAV resource as davfs2 file system
mount.davfs(8) — Arch manual pages
I’m going to summarise the approach taken here, trying to be as clear as possible; if it isn’t clear enough, please do let me know, and I’ll try to amend it to make it clearer.
Both of my NAS devices are Synology models, so I’ve started setting them up to work via WebDAV:
- How to access files on a Synology NAS using WebDAV
Comment accéder aux fichiers du Synology NAS avec WebDAV? - Synology Centre de connaissances
For NAS devices from other brands, please refer to their support pages.
- Install the necessary packages :
Open a terminal and run the following command to install the davfs2 package, which allows you to mount WebDAV file systems:
sudo apt install davfs2
I have chosen to allow any non-privileged user to mount WebDAV resources.
I am creating a directory /home/my_username/.davfs2 containing the same files as those in the /etc/davfs2 directory
- Create an mount point :
Create a directory where you want to mount your NAS drive. For example:
sudo mkdir /media/my_NAS
- Using systemd :
To set up the service, as I have two NAS devices, I had to carry out this procedure twice, once for each NAS.
3.1 Setting up the service
Create a file called /etc/systemd/system/mnt-webdav-service.mount to mount the service:
[Unit]
Description=Mount WebDAV Service
After=network-online.target
Wants=network-online.target
[Mount]
What=https://my_NAS_address:port_used
Where=/media/my_NAS
Options=uid=1000,file_mode=0664,dir_mode=2775,grpid
Type=davfs
TimeoutSec=15
[Install]
WantedBy=multi-user.target
3.2 Automatic service setup
Create a file called /etc/systemd/system/mnt-webdav-service.automount to enable the service to mount automatically:
[Unit]
Description=Mount WebDAV Service
[Automount]
Where=/media/my_NAS
TimeoutIdleSec=300
[Install]
WantedBy=remote-fs.target
3.3 Creating the service
Creating a file called ~/.local/share/systemd/user/mountdav.service
[Unit]
Description=Mount WebDAV Service
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=bash -c 'for i in {1..15}; do if ping -c 1 myserver; then mount /media/my_NASs; break; else sleep 1; fi; done'
ExecStop=umount /media/my_NAS
RemainAfterExit=true
[Install]
WantedBy=default.target%
- Set up user id :
If your NAS requires a username and password, edit the configuration file called ‘secrets’ in /etc/davfs2/secrets for the administrator, and in /home/my_username/.davfs2/secrets for the user
In the ‘Credential line my_username’ section, add:
https://url_du_nas username password,
Note: put the ‘password’ in single quotes
Attention : Handling special characters.
If a password or username in the ~/.davfs2/secrets or /etc/davfs2/secrets file contains special characters, these must be preceded by a backslash ().
Special characters include the space, tab, #, \ and ".
To escape them:
Use \ for a space.
Use # for the # character.
Use \ for the backslash itself.
Use " for double quotation marks.
It is also possible to enclose values containing spaces, tabs or the # character within double quotation marks (“”), but the characters \ and » must always be escaped within the quotation marks.
Personally, I have changed my passwords so as to avoid any problems with these special characters.
- Edit the fstab file
Add or edit this line in fstab:
http://myserver`` /media/my_nas davfs user,rw,noauto,_netdev 0 0
To use with a specific user, add uid= or .
This is often uid=1000.
http://myserver`` /media/my_nas davfs user,uid= or ,rw,noauto,_netdev 0 0
Note :
Ports used: please specify the ports that have been selected for WebDAV; in my case, these are port 7006 (instead of 7001) for the first NAS and port 7008 (instead of 7003) for the second.
- Change permissions :
For security reasons, ensure that the secrets file has the correct permissions; the davfs2 ‘secrets’ file must belong to the user mounting the WebDAV share and have strict permissions of 600 (read and write access for the owner only).
sudo chmod 600 /etc/davfs2/secrets
chown root:root /etc/davfs2/secrets
Note :
6.1.1 Owner
The required owner depends on how the share is set up:
System-wide mounts (e.g. via /etc/fstab and mounted as root): the /etc/davfs2/secrets file must be owned by root:root.
User-level mounts (mounted by a non-privileged user): the file ~/.davfs2/secrets must be owned by the specific user and group (e.g. john:john) performing the mount operation.
6.1.2 Authorisations (mode)
Permissions must be set to 600, which means:
Owner: read and write (rw-)
Group: no access (—)
Others: no access (—)
This is a security measure designed to prevent other local users from reading the plaintext credentials stored in the file.
How to set the correct permissions:
To set this up system-wide (as root):
sudo chown root:root /etc/davfs2/secrets
sudo chmod 600 /etc/davfs2/secrets
To mount on a per-user basis (as a standard user):
chown : ~/.davfs2/secrets
chmod 600 ~/.davfs2/secrets
(Replace and with the actual username and their primary group).
- Mount the disk : to mount the disk immediately withot restarting, run the following command :
sudo mount /media/my_NAS
- Automate the mounting at start-up :
To ensure that the drive mounts automatically at boot, you must add the ‘auto’ option to the /etc/fstab file as described above.
http://myserver`` /media/my_NAS davfs user,rw,auto,_netdev 0 0
- Restart :
Restart your computer to check that the automatic mounting is working correctly.
And it must work ![]()