Can't add local external storage to fresh Nextcloud install- error: External storage not available: stat() failed

Nextcloud version: 19.01

Operating system and version:

Ubuntu 20.04

Apache or nginx version:

nginx 1.18.0

PHP version:

7.4.9

The issue you are facing:

I am unable to add local external storage

Is this the first time you’ve seen this error?

yes

Steps to replicate it:

  1. fresh install using this ansible playbook: https://github.com/ReinerNippes/nextcloud/tree/nextcloud-reloaded
  2. attempt to add external storage
  3. error

The output of your Nextcloud log in Admin > Logging:

[no app in context] Info: External storage not available: stat() failed

PUT /apps/files_external/globalstorages/2
from 192.168.1.1 by admin at 2020-08-18T15:11:23+00:00

{"reqId":"oDE2tn6eR9GT1Gdus5oI","level":1,"time":"2020-08-18T15:11:23+00:00","remoteAddr":"192.168.1.1","user":"admin","app":"no app in context","method":"PUT","url":"/apps/files_external/globalstorages/2","message":"External storage not available: stat() failed","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":"19.0.1.1","id":"5f3bef9e6a78d"}
[PHP] Error: stat(): stat failed for /media/aslan/work/ at /var/www/nextcloud/lib/private/Files/Storage/Local.php#145

PUT /apps/files_external/globalstorages/2
from 192.168.1.1 by admin at 2020-08-18T15:11:23+00:00

{"reqId":"oDE2tn6eR9GT1Gdus5oI","level":1,"time":"2020-08-18T15:11:23+00:00","remoteAddr":"192.168.1.1","user":"admin","app":"no app in context","method":"PUT","url":"/apps/files_external/globalstorages/2","message":"External storage not available: stat() failed","userAgent":"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0","version":"19.0.1.1","id":"5f3bef9e6a78d"}

These two logs basically repeat about 7 times. I’ve included both the formatted and raw versions.

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'passwordsalt' => '{REDACTED}',
  'secret' => '{REDACTED}',
  'trusted_domains' => 
  array (
    0 => 'cloud.aslanfrench.work',
  ),
  'datadirectory' => '/var/nc-data',
  'dbtype' => 'pgsql',
  'version' => '19.0.1.1',
  'overwrite.cli.url' => 'https://cloud.aslanfrench.work',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'dbuser' => 'nextcloud',
  'dbpassword' => '{REDACTED}',
  'installed' => true,
  'instanceid' => 'occ902x1gtuw',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0,
    'password' => '{REDACTED}',
  ),
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'filelocking.enabled' => true,
  'enable_previews' => true,
  'enabledPreviewProviders' => 
  array (
    0 => 'OC\\Preview\\PNG',
    1 => 'OC\\Preview\\JPEG',
    2 => 'OC\\Preview\\GIF',
    3 => 'OC\\Preview\\BMP',
    4 => 'OC\\Preview\\XBitmap',
    5 => 'OC\\Preview\\MarkDown',
    6 => 'OC\\Preview\\MP3',
    7 => 'OC\\Preview\\TXT',
    8 => 'OC\\Preview\\Illustrator',
    9 => 'OC\\Preview\\Movie',
    10 => 'OC\\Preview\\MSOffice2003',
    11 => 'OC\\Preview\\MSOffice2007',
    12 => 'OC\\Preview\\MSOfficeDoc',
    13 => 'OC\\Preview\\OpenDocument',
    14 => 'OC\\Preview\\PDF',
    15 => 'OC\\Preview\\Photoshop',
    16 => 'OC\\Preview\\Postscript',
    17 => 'OC\\Preview\\StarOffice',
    18 => 'OC\\Preview\\SVG',
    19 => 'OC\\Preview\\TIFF',
    20 => 'OC\\Preview\\Font',
  ),
  'preview_max_x' => 1024,
  'preview_max_y' => 768,
  'preview_max_scale_facto' => 1,
  'auth.bruteforce.protection.enabled' => true,
  'trashbin_retention_obligation' => 'auto,7',
  'skeletondirectory' => '',
  'defaultapp' => 'file',
  'activity_expire_days' => 14,
  'integrity.check.disabled' => false,
  'updater.release.channel' => 'stable',
  'loglevel' => 1,
  'maintenance' => false,
  'theme' => '',
);

The output of your Apache/nginx/system log in /var/log/____:

Nextcloud error log:

2020/08/17 00:06:24 [error] 1958#1958: *36818 access forbidden by rule, client: 202.142.81.87, server: cloud.aslanfrench.work, request: "GET /.env HTTP/1.1", host: "136.49.174.165", referrer: "https://136.49.174.165/"
2020/08/17 02:59:16 [error] 1958#1958: *37188 access forbidden by rule, client: 13.125.118.177, server: cloud.aslanfrench.work, request: "GET /.git/HEAD HTTP/1.1", host: "wiki.jackalope.tech"
2020/08/17 03:34:50 [error] 1958#1958: *37202 access forbidden by rule, client: 202.142.81.87, server: cloud.aslanfrench.work, request: "GET /.git/config HTTP/1.1", host: "136.49.174.165", referrer: "https://136.49.174.165/"
2020/08/17 03:34:52 [error] 1958#1958: *37204 access forbidden by rule, client: 202.142.81.87, server: cloud.aslanfrench.work, request: "GET /.git/HEAD HTTP/1.1", host: "136.49.174.165", referrer: "https://136.49.174.165/"
2020/08/17 04:08:01 [error] 1958#1958: *37227 access forbidden by rule, client: 202.142.81.87, server: cloud.aslanfrench.work, request: "GET /.env HTTP/1.1", host: "136.49.174.165", referrer: "https://136.49.174.165/"
2020/08/17 10:41:16 [error] 1958#1958: *39031 access forbidden by rule, client: 13.52.97.239, server: cloud.aslanfrench.work, request: "GET /.git/HEAD HTTP/1.1", host: "wiki.jackalope.tech"
2020/08/17 16:00:24 [warn] 1958#1958: *47492 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/7/01/0000000017 while reading upstream, client: 192.168.1.1, server: cloud.aslanfrench.work, request: "GET /remote.php/dav/files/aslan/InstantUpload/Slack/IMG_20200817_155920.jpg HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "cloud.aslanfrench.work"
2020/08/17 17:14:41 [crit] 1958#1958: *51253 SSL_do_handshake() failed (SSL: error:1408F0C6:SSL routines:ssl3_get_record:packet length too long) while SSL handshaking, client: 68.183.188.21, server: 0.0.0.0:443
2020/08/17 18:11:14 [warn] 1958#1958: *52602 an upstream response is buffered to a temporary file /var/cache/nginx/fastcgi_temp/8/01/0000000018 while reading upstream, client: 192.168.1.1, server: cloud.aslanfrench.work, request: "GET /remote.php/webdav/InstantUpload/Slack/IMG_20200817_155920.jpg HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "cloud.aslanfrench.work"

nginx error log sample:

2020/07/29 04:55:42 [error] 100872#100872: *415 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost"
2020/07/29 05:02:57 [error] 100872#100872: *426 open() "/usr/share/nginx/html/nextcloud" failed (2: No such file or directory), client: 127.0.0.1, server: localhost, request: "GET /nextcloud HTTP/1.1", host: "localhost"

Further Info

When I first tried to add local external storage I received an error in the web ui that said:

smbclient" is not installed. Mounting of "SMB / CIFS", "SMB / CIFS using OC login" is not possible. Please ask your system administrator to install it. nextcloud

I googled this and people were saying this was because smbclient needed to be installed. I installed it and restarted the server. This did not fix the issue. Other people in that thread also said that php-smbclient needed to be installed too so I tried installing that and restarting the server. The problem persisted after restarting the server.

The external storage that I am trying to mount is an HDD that automatically mounted under /media/{username}.

The server I’m installing on is a desktop computer that I’ve been running Nextcloud off for the past 2 years. I was running 18.04 but after running into some clunky system issues I decided to do a fresh reinstall of the system. I did a fresh install of Ubuntu 20 and ran the latest version of the Reiner Nippes ansible playbook (branch nextcloud-reloaded). Everything went fairly smoothly until I recently decided to hook back up the external storage and ran into this problem.

Hi,
to me it sounds like the webserveruser that nextcloud is running with has no access to the external HDD. So if you try to mount the local external storage, Nextcloud reports that you don’t have the rights to access the storage.

can you post the output of the following commands:
ls -l /var/www/nextcloud/occ
and
ls -l /media/aslan | grep work

I thought that might be the issue so I added the www-data user to the “aslan” user group, which should have full permissions to the work hdd.

But let’s see:

ls -l /var/www/nextcloud/occ
-rw-r----- 1 nginx nginx 283 Jul 15 15:22 /var/www/nextcloud/occ
ls -l /media/aslan | grep work
drwxrwxrwx 1 aslan aslan   8192 Aug 17 19:46 work

Hmmm… that seems weird… maybe the ansible script I used made the nextcloud folder under the nginx user instead of the www-data user?

Do I just need to add the nginx user to the aslan user group to fix this?

Yes, it sounds like this should work :+1:
Please report back if that works for you.

Thanks!

It didn’t work though :frowning:

But I think I might know why?

I double checked. Both www-data and nginx are in the aslan user group. And the work folder has 777 permissions.

BUT! the full address is /media/aslan/work and both media and aslan are both root user and group. So I think that’s probably the problem. I don’t think I should expose /media to non root users (since that’s what USB drives mount to automatically) so I think I just need to remount the work drive to a dedicated location in /. I’ll try that and get back to ya’ll.

EDIT: BINGO! That worked :slight_smile:

Great, congrats! :tada:

new but related problem logged here: External storage reading "0 kb" despite probably showing up in filesystem

hello, I would like to ask you what exactly you modified to make it work if you don’t mind.
I have mounted the storage in the folder nextcloud. This folder is in the root partition.
I have used chown to make www-data user and owner for all the folders that below to the folder nextcloud, they have 777 permission.
Question, if I have the user admin created at the beginning in nextcloud, how do I find this user in the file passwd. I don’t see it, neither in the file group.
What do you mean you mounted to a dedicated location in /.?

my mount is /dev/sda1 /nextcloud
side note: I have samba working. I can share files between windows and the raspberry linux but I want to use the external storage of nextcloud and it gave me the error for samba client.
I will appreciate any help

hello, how do I know which user is used in nextcloud?
for insrtance, iof I create the user pete, how can I find it in linux to add in certainm group?
I will appreciate any help