Snap install and external storage permission

Hello,

I have been fighting this problem for more than a week and have read a lot of topics, but my problem remains unsolved.

The problem is that the NC does not have the proper permission to acces the external storage added as local.
I get the Failed to open directory: Permission denied at /snap/nextcloud/35878/htdocs/lib/private/Files/Storage/Local.php#154

The HDD is mounted to /mnt/razmena folder and is not owned by root. It has 771 permission.
I could do the 777 and the NC would finaly see the files, but I am not about to give everyone access to it. Even then, the problem is back in the first subdirectory owned by anyone other than root.

The obvious beginner next step is to enable removable media with
sudo snap connect nextcloud:removable-media

Done with no luck. Restarted service, rebooted… No luck.

Little background on what I am using.
VM with ubuntu server installed on proxmox.
I had the exact same problem on debian VM

NC is version 26 installed via snap.

I would be able to accept defeat and admit I am doing something wrong if i didn’t have the exact same configuration on RPI raspbian. Using the very same HDD. I can swap the USB cable from server to RPI and the NC on RPI would see the files from /mnt/razmena. So obviously, the ownership and permissions are not the problem, it is the settings, but other than connecting removable media.
root does have access to the files and folders. I can access everything from webmin interface which is accessing everything as root. So seing files, rename, delete… can be done by root.
I have now just tried to add another drive, but this time, it was formated and file system was created on this machine. Just in case some permission is carried from the other system. Still no luck :frowning:

Edit:
I have just installed the fresh copy of rpi os to the new memory card. Got all the same apps that I have on ubuntu vm and configured it the same way with same users. External storage works.
So it is not my configuration since that is very basic, but somewhere deeper.

1 Like

Hello,

I am not sure, but I have seen during my experience of running Snap Nextcloud, may be due to it’s confinement limitations, external storage must be mounted to either /mnt or /media location. It wont access anything outside those two locations as external storage…

Check if your external mount is within those two locations.

Thanks.

It is mounted to /mnt.
Just for fun, I have tried moving it to /media as well, but it stays the same

I’m guessing it’s because you’re using a mix of supported and unsupported distros. Snaps are not actually cross-distro in that confinement doesn’t work the same everywhere.

1 Like

Ok, thanks for that reply, that is definately news to me.
Lets forget about the rpi os for a moment, can you tell me the point of connect removable media and its use in the ubuntu as the supported distro?

Focusing on ubuntu: yes. You should be able to connect the removable-media interface and you will gain access to the /media and /mnt directories on the host. Each directory that makes up the path you’re wanting to use as the data directory (i.e. /, /mnt, /mnt/razmena and so on) will need to be owned by root.

Being owned by root really makes no sense to me. It is quite limiting. It works only in the case of the whole drive being used by nextcloud only and not being accessed by or from anywhere else.

I would asume that external storage is not exclusive to root, otherwise it would be either internal or useless as external.
I am trully sorry this may sound rude, but i simply cannot accept that as the designed feature.
That means that no matter the location, nextcloud wil not see any file not owned by root.

Fair enough.

I have managed to get a workaround for this. Quite a fun and silly thing, but it works.
I have added the external storage as SFTP. host is “localhost”, root (directory) is /mnt/whatever.

Because my main ubuntu user has a lot of privileges, I have created a new dummy user and used that for auth. Not only that it can see the /ext but it can see everything that the users member can if i need it.
The only thing is that I am not sure if SFTP is maybe a little slower and if it is heavy on the resources.
Not that the speed matters much as the main intention of NC is access from outside the local network over internet and the main limit will be my home internet upload speed.

I will have to check if switching to FTP is ok, since it is not being accessed over network, only localy within that one VM.

In any case, one way or another, this is solved.

This sounds like a recursion problem. You can fix that by adding the -R parameter to your commands. E.g. chown -R root.

It would be impossible to keep that up in my case as the external device is part of the SMB share.

  1. As soon as files are owned by root, no other SMB user has access to it.
  2. SMB is used by torrent client, backup client and users, each of which creates files with their ownership so the initial setup would be shortlived
1 Like

Another update. After using SFTP as external storage, as I suspected, it destroys the performance. Upload and download are somewhat OK, but videos are impossible to play. Downloading larger files is insanely slow.
I have been tinkering again with many settings and found a compromise in giving permission to others. For folders it is r-x and for files it is r–. My samba dir mask is 775 and create mask 754.
In this case, ownership has no effect. Neither folders nor files have to be owned by root.
Actually, changing ownership to root does not help at all in my case. Also, putting root to users group does nothing.

A solution that works well for me, is using bindfs. I have local folders (not owned by root) mounted to /mnt on startup by adding following lines to /etc/fstab

/drv/video /mnt/video fuse.bindfs mirror=root,create-for-user=media_owner,create-for-group=media_owner 0 0
/drv/docs/documents /mnt/docs fuse.bindfs mirror=root,create-for-user=doc_owner,create-for-group=doc_owner 0 0

the option mirror=root maps the ownership of the mounted location too root, while keeping the original ownership of the source location.
with the create-for- options new files will automatically chown’ed to the owners of the source location.

After adding the /mnt/ location as external storage, i have full read/write access.

1 Like

Sorry for taking so long to reply, I was on vacation when you posted.
First of all, thanks for contributing even though the thread is a bit old. I appreciate the time and your answer helps a lot.
The main thing is that it WORKS. I can finally use the same folders in separate use cases like samba, torrent, and nextcloud.

Before, I got used to making new folders and then fiddling around with copying files to go around this, but this will unify all the locations.

Just to make a little update on my use case, I have a server with proxmox and ZFS on it. To use those pools, they are mounted to an ubuntu container (same as a virtual machine). Samba is then installed on the ubuntu and shares the mounted folders (/mnt/proxmox/Files) to the network.
With your help, I have now added another mount to /mnt/nextcloud/Files which is added to nextcloud as an external storage.
Permissions are back to restrictive mode which was loosened up just to get some use out of nextcloud.

BTW, for anyone that stumbles on this post, fuse or bindfs might not be installed by default which could result in errors or machine not booting. Check before using it in /etc/fstab.

Once again, thanks so much for your help.

Hy,
I have the same problem, and i resolve it, with this command line :
snap connect nextcloud-desktop-client:removable-media

Morning, I’ve really struggle with docker and aio. So I’d like to try snap. I want to connect an external usb drive for Nextcloud backup and also file backup . Is this easy to do? I’ve spent weeks with docker and I’ve given up. I’m hoping your code may work.

snap connect nextcloud-desktop-client:removable-media

this is well documented with an extensive wiki Nextcloud snap wiki and support and FAQ’s

feel free to ask the community, but do read the docs :grinning:

1 Like

Hi all
It is easy to read the documents, but what to do if nothing works after following the docs?

to set the /media/xxx ownership to root:root does nothing. I have worked long hours to config the external storage to no avail. some one had mention that his worked with
adm group but it did not work for me.

Error message always is

local storage path does not exist.

I think it might be more basic.
Maybe the ubuntu version, snap version… matters. not sure what it is causing this prermission problem

here is my drive permissions

sudo ls -la /media/www/data
total 24
drwxrwxrwx 4 root adm 4096 Feb 15 19:23 .
drwxrwxrwx 4 root adm 4096 Feb 19 17:08 …
drwxrwxrwx 7 root adm 4096 Feb 15 19:31 appdata_ocjat877dr84
-rwxrwxrwx 1 root adm 542 Feb 15 19:18 .htaccess
-rwxrwxrwx 1 root adm 0 Feb 15 19:18 index.html
-rwxrwxrwx 1 root adm 52 Feb 15 19:18 .ncdata
drwxrwxrwx 4 root adm 4096 Feb 15 19:31 wanj
wanj@wanj5:~$ sudo ls -la /media/www
total 16
drwxrwxrwx 4 root adm 4096 Feb 19 17:08 .
drwxrwx— 8 wanj wanj 4096 Feb 19 17:06 …
drwxrwxrwx 4 root adm 4096 Feb 15 19:23 data
drwxrwxrwx 3 root adm 4096 Feb 19 17:11 files
wanj@wanj5:~$ groups
wanj adm cdrom sudo dip plugdev lpadmin lxd sambashare

I also installed the nextcloud-desktop-client and enabled it with snap

sudo snap list
Name Version Rev Tracking Publisher Notes
bare 1.0 5 latest/stable canonicalâś“ base
core18 20240920 2846 latest/stable canonicalâś“ base
core20 20241206 2496 latest/stable canonicalâś“ base
core22 20250110 1748 latest/stable canonicalâś“ base
core24 20241119 716 latest/stable canonicalâś“ base
curl 8.12.1 2283 latest/stable aoilinux -
firefox 135.0.1-1 5783 latest/stable mozillaâś“ -
firmware-updater 0+git.22198be 167 1/stable/… canonical✓ -
gnome-3-28-1804 3.28.0-19-g98f9e67.98f9e67 198 latest/stable canonicalâś“ -
gnome-3-38-2004 0+git.efb213a 143 latest/stable canonicalâś“ -
gnome-42-2204 0+git.38ea591 202 latest/stable canonicalâś“ -
gtk-common-themes 0.1-81-g442e511 1535 latest/stable/… canonical✓ -
imagick 3.7.0 32 latest/edge kz6fittycent -
nextcloud 30.0.5snap1 46218 latest/stable nextcloudâś“ -
nextcloud-desktop-client 3.13.4 214 latest/stable glasen -
samba4-manager 0+git.eab1e95 3 latest/stable stgraber -
snap-store 0+git.7a3a49a6 1248 2/stable/… canonical✓ -
snapd 2.67 23545 latest/stable canonicalâś“ snapd
snapd-desktop-integration 0.9 253 latest/stable/… canonical✓ -
termius-app 9.14.0 214 latest/stable termiusâś“ -
thunderbird 128.7.1esr-1 663 latest/stable canonicalâś“ -

I am not sure if nextcloud can use external storage outside of /mnt/ location.
Even if you did, you might get to the same problem I had with the write permissions.

The good thing is that you can use the solution from the few posts above using bindfs. You can even keep the original HDD mount/location you have in /media.
Use fstab to add the mount to the original location to the /mnt/ and with root, but keep the original ownership and permissions.

in fstab add

/path/to/source /mnt/target/path fuse.bindfs mirror=root,create-for-user=OWNER,create-for-group=GROUP 0 0

just change the owner and group to the actual ownership you want. Obviously, choose the paths you need/want.

In nextcloud GUI, when you are logged in as admin, you have to install or enable the external storage plugin and then add the new /mnt location.

have you done this:

sudo snap connect nextcloud:removable-media

1 Like