External storage no permissions to create folders or uplouad files

Nextcloud version (eg, 20.0.5): 23.0.2.1
Operating system and version (eg, Ubuntu 20.04): Debian GNU/Linux 10. 5.10.103-v8+ (aarch64)
Apache or nginx version (eg, Apache 2.4.25): don't know
PHP version (eg, 7.4): 7.3.31-1~deb10u1

The issue you are facing:
I connected a HDD drive to my nextcloudpi and tried to use it as external storage. (The drive was formatted in Windows using a program to format in ext4) Everything showed up in the settings panel and i set the path as an local storage, which was confirmed with a green checkmark. After that the folder “HDD” shows up as one of my data folders, as expected and i can open the folder and see a folder called “lost+found”. But i can’t create any folders or upload files.

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Format HDD to ext4 with an windows program
  2. Connect HDD to nextcloudpi
  3. Configure drive as external storage

I have nearly no experience with linux, which is why i used a windows program (EaseUS Partition Master) to format the drive. Could the program be the problem? What is this lost+found folder for?

Thanks for your help.

Hello,

The lost+found is incase your harddrive is not properly removed and your disk may get damaged. This folder is always there and should always be there.

The reason that you cannot create files or folders is probably because you have not yet set the right permissions for the webserver to write to it.

I must make a assumption here that your using Apache as webserver you should check if this is true by the command:

Apache2 -v

it should show you something like

Server version: Apache/2.4.46 (Ubuntu)
Server built:   2021-03-13T15:08:26

if this is the case then your webserver user is probably ‘www-data’ and you should give this user access to your harddisk.

you need to atleast have shell access to your RPI to continue.

When logged in your RPI you can find your disk with the command

df -h

It should output something like

udev                              16G        0   16G   0% /dev
tmpfs                            3,2G     1,8M  3,2G   1% /run
/dev/mapper/vgmint-root          227G     125G   90G  59% /
tmpfs                             16G        0   16G   0% /dev/shm
tmpfs                            5,0M     8,0K  5,0M   1% /run/lock
tmpfs                             16G        0   16G   0% /sys/fs/cgroup
/dev/nvme1n1p2                   705M     520M  134M  80% /boot
/dev/nvme0n1p2                    96M      31M   66M  32% /boot/efi
/dev/sda1                        458G     404G   31G  93% /media/data
10.8.0.20:/cloud/Films           7,2T     5,0T  1,9T  73% /media/cloud/Films
10.8.0.20:/cloud/muziek/Mvids    7,2T     5,0T  1,9T  73% /media/cloud/Mvids
tmpfs                            3,2G      64K  3,2G   1% /run/user/1000
/dev/sdb1                        1,9G     1,9G     0 100% /media/vincent/Linux Mint 20 Xfce 64-bit

What your looking for is /dev/sdX1 where X is a letter eigther a or b maybe c depending on how many disk are connected every disk gets a letter starting from a and further.

now for example your disk is like above /dev/sda1 Then I would go to

cd /media
type
ls -la

and I get

drwxr-xr-x   5 root root 4096 dec 15 06:12 .
drwxr-xr-x  23 root root 4096 dec 14 18:31 ..
drwxr-xr-x   4 root root 4096 dec 15 06:13 cloud
drwxr-xr-x   4 root root 4096 apr 15  2020 data
drwxr-x---+  3 root root 4096 mrt 11 08:41 vincent

as you can see this folder ‘data’ is owned by user root and group root but notice that ’ drwxr-xr-x’ only the root user can write to it.

let change this user root to www-data by typing

sudo chown www-data:www-data data

now it we look with ls -la again we see

drwxr-xr-x   5 root     root     4096 dec 15 06:12 .
drwxr-xr-x  23 root     root     4096 dec 14 18:31 ..
drwxr-xr-x   4 root     root     4096 dec 15 06:13 cloud
drwxr-xr-x   4 www-data www-data 4096 apr 15  2020 data
drwxr-x---+  3 root     root     4096 mrt 11 08:41 vincent

now the webserver has access to it and this is what you should want. now if we look inside this data folder and do ls -la we see

drwxr-xr-x  4 www-data www-data  4096 apr 15  2020 .
drwxr-xr-x  5 root     root      4096 dec 15 06:12 ..
drwx------  2 vincent  vincent  16384 nov 30  2019 lost+found

we find the lost+found that this folder is not owned by www-data does not matter as it is used by the system and not the webserver.

you could further secure the disk by changing the chmod to 750 but first sort it out that you can create files and folders on in in the NC interface.

Let us know if you need any more help or something is not clearly explained.

1 Like

Hello,

At begining, I wanted to move nextcloud Data directory to an USB HDD.
I always got problem with .ocadata or permission then I followed what you said for external storage.

And it worked fine I been able to run nextcloud even after move the data directory.

But I noticed some feature not working such as Welcome Widget that could not connect anymore.

Then I moved data directory to original directory with base installation.

Following your says, I also been able to make external storage works on my USB HDD.

However after rebooted my laptop the USB HDD is not available.

It seems it is because when i reboot the device as long as I did not loggin to open ubuntu that the USB HDD isn’t mounted.

Then I auto mounted at boot the USB Drive and now it is working fine.
Thank you.

1 Like

Hello. I did everything exactly as you described:

ast@dol:/mnt/nextcloud$ ls -la
total 16
drwxr-xr-x 4 root     root     4096 May 10 18:44 .
drwxr-xr-x 6 root     root     4096 May 10 18:44 ..
drwxr-x--- 4 www-data www-data 4096 Jul 22 18:28 data
drwxr-x--- 3 www-data www-data 4096 Jul 20 19:12 data2

but when creating a folder in local external storage, it still gives out Unable to create folder “New folder”

Good morning,
this question is older, but maybe I have the solution.
Did you distribute the permissions correctly?
You have to do following command:

chown -R www-data:www-data /home/data/

home/data is your data Directory.

Does it work now?

Best regards and good luck!

From:

https://technik.schächner.de/blog/2023/03/29/nextcloud-26-hub-4-installieren-2023/

1 Like

I saw, you made sudo chown www-data:www-data data, but I think, for folders you need „chown -r“, not only „chown“.

I did
sudo chown -R www-data:www-data /mnt/nextcloud/data

I’m sorry. Could it be an error with the Mount?
Did you add an entry to /etc/fstab?

/dev/sdb1 /mnt/nextcloud/data ext4 defaults 0 2
/dev/sdc1 /mnt/nextcloud/data2 ext4 defaults 0 2

Yep

Tut mir leid, dann weiß ich es nicht. Was du höchstens noch probieren könntest,
ist die 0 2 auf 0 0 zu ändern.

In the example above your problem, the directory rights are set to 755 while you used 750.


Just for the record:

That has nothing to do with the issue here.
The sixth field is the so called “fs_passno”, to indicate fsck if-, and if yes ( != 0 ) in what order to check the drive. Read → man fstab:

   The sixth field (fs_passno).
       This field is used by fsck(8) to determine the order in which
       filesystem checks are done at boot time. The root filesystem should be
       specified with a fs_passno of 1. Other filesystems should have a
       fs_passno of 2. Filesystems within a drive will be checked
       sequentially, but filesystems on different drives will be checked at
       the same time to utilize parallelism available in the hardware.
       Defaults to zero (don’t check the filesystem) if not present.

sudo chmod -R 755 /mnt/nextcloud/data
didn’t help either
sudo chmod -R 777 /mnt/nextcloud/data
didn’t help either

All extremely strange.
Since you started somewhere in the middle: What is your setup exactly? Debian/Ubuntu?
How exactly is the folder integrated into the server? As external storage?

What is the output of

mount | grep "dev/sd[bc]1"

  • Does/did everything work on your normal data directory?
  • Did you change anything else? Did you apply updates recently?
  • No Docker/Snap/AIO?

I’m just guessing.

Updates installed 2 days ago.
I connected 2 hard drives internal to a pc that already has ubuntu installed.
Created partitions on each.
Formatted.
Mounted partitions sdb1 and sdc1 into folders /mnt/nextcloud/data /mnt/nextcloud/data2 respectively.
Added:

/dev/sdb1 /mnt/nextcloud/data ext4 defaults 0 2
/dev/sdc1 /mnt/nextcloud/data2 ext4 defaults 0 2

in /etc/fstab.
On nextcloud added option “external storage”.
Added 2 local external storages.
Did this from https://docs.nextcloud.com/:

sudo chown -R www-data:www-data /path/to/localdir
sudo chmod -R 0750 /path/to/localdir

I guess a didn’t do anything else.
Nextcloud Installed by snap

This did interest me most:

 mount | grep "dev/sdb1"
/dev/sdb1 on /mnt/nextcloud/data type ext4 (rw,relatime)
mount | grep "dev/sdc1"
/dev/sdc1 on /mnt/nextcloud/data2 type ext4 (rw,relatime)

I am running out of ideas. The last thing I could imagine is, that you eventually made mistakes in the permissions in the external storage settings.:
image

Read only = unchecked?

Much luck!

It was uncheked by default so i didn’t touch it(

You are right, sorry. Then unfortunately I can’t help you.
You’ll already know, but I suspect it’s only a #ncp problem.