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.