NextcloudPi inaccessible after moving to USB drive

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

Hi. I tried to run the automated data relocation tool to move data from an SD card on a RaspberryPi to a USB drive, and afterwards I’m getting the following error when I try to access NextCloud:

"
Error
Your data directory is invalid.

Ensure there is a file called “.ncdata” in the root of the data directory. It should have the content: “# Nextcloud data directory”
"

It appears that I have a permissions issue. I’d like to undo the move and try again, but I want to make sure I don’t make the problem worse.

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • 31.0.7.1
  • Operating system and version (e.g., Ubuntu 24.04):
    • NextcloudPi
  • Web server and version (e.g, Apache 2.4.25):
    • Not sure
  • Reverse proxy and version _(e.g. nginx 1.27.2)
    • Not sure
  • PHP version (e.g, 8.3):
    • Not sure
  • Is this the first time you’ve seen this error? (Yes / No):
    • Yes
  • When did this problem seem to first start?
    • After an unsuccessful move of my data directory
  • Installation method (e.g. AlO, NCP, Bare Metal/Archive, etc.)
    • Nextcloud Pi setup
  • Are you using CloudfIare, mod_security, or similar? (Yes / No)
    • Dunno

Summary of the issue you are facing:

I tried to run the data move wizard to move my data from /opt/ncdata/data on an SD card to a USB drive.

Steps to replicate it (hint: details matter!):

  1. Plugged in drive
  2. Started NextcloudPi Wizard. Clicked “USB Configuration”
  3. Selected yes, I want to move. Continue. Format. Move data.
  4. Left it overnight

Log entries

[ nc-format-USB ] (Wed Jul 23 05:49:23 UTC 2025)
mmcblk0p2 179:2 0 29.2G 0 part /var/log.hdd\x0a/
/dev/sda: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
NOTE: several default settings have changed in version 5.15, please make sure
this does not affect your deployments:
- DUP for metadata (-m dup)
- enabled no-holes (-O no-holes)
- enabled free-space-tree (-R free-space-tree)

Drive sda formatted successfuly and labeled myCloudDrive

[ nc-datadir ] (Wed Jul 23 05:49:30 UTC 2025)
Maintenance mode enabled
moving data directory from /opt/ncdata/data to /media/myCloudDrive/ncdata/data...
BTRFS filesystem detected
Create subvolume '/media/myCloudDrive/ncdata'
mv: cannot remove '/opt/ncdata/data/.opcache/40b8b70efdcde8a275101195a79f4a37/var/www/nextcloud/core': Directory not empty

[ncp-update-nc]
Running as unit: ncp-update-nc.service
Nextcloud is currently down
Nextcloud update failed (or was installed already).

[ nc-datadir ] (Wed Jul 23 16:29:38 UTC 2025)
INFO: /media/myCloudDrive/ncdata is not empty. Creating backup /media/myCloudDrive/ncdata-07-23-25.1753288179
Your data directory is invalid.
Ensure there is a file called ".ncdata" in the root of the data directory. It should have the content: "# Nextcloud data directory"

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:143
Stack trace:
#0 /var/www/nextcloud/console.php(81): OC\Console\Application->loadCommands()
#1 /var/www/nextcloud/occ(33): require_once('...')
#2 {main}
[ nc-database ] (Wed Jul 23 16:30:10 UTC 2025)
Your data directory is invalid.
Ensure there is a file called ".ncdata" in the root of the data directory. It should have the content: "# Nextcloud data directory"

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:143
Stack trace:
#0 /var/www/nextcloud/console.php(81): OC\Console\Application->loadCommands()
#1 /var/www/nextcloud/occ(33): require_once('...')
#2 {main}moving database to /media/USBdrive/ncdatabase...
Installing template 'mysql/90-ncp.cnf.sh'...
Your data directory is invalid.
Ensure there is a file called ".ncdata" in the root of the data directory. It should have the content: "# Nextcloud data directory"

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:143
Stack trace:
#0 /var/www/nextcloud/console.php(81): OC\Console\Application->loadCommands()
#1 /var/www/nextcloud/occ(33): require_once('...')
#2 {main}
[ nc-automount ] (Wed Jul 23 16:37:16 UTC 2025)
automount enabled

Based on what I’ve read, this looks like a permissions issue. Can anyone suggest the best way to undo this and try again? Or if possible, just complete the move that already started?

I’m a long time Linux user with experience using command line and RaspberryPis, but my knowledge of servers is low, and a lot of my experience overall is shallow and basic so feel free to phrase questions/instructions/explanations like I’m five.

Welcome andrewrgross

you may take a look here:
https://help.nextcloud.com/t/how-to-configure-an-external-usb-drive-with-nextcloudpi/126376

Thank you for this link. I’m trying to go down the list, and I think I may have found part of the problem:

  1. Format USB drive (optional but check note).
    I have confirmed that the drive is formatted as BTRFS
    1. Enable nc-automount.
      Automount is enabled.
  2. Configure Nextcloud data to be on the USB drive.
    This seems to be the current problem.

In the instructions you linked it says to “Change DATADIR to your data location in the mount point.” In the WebUI I tried to do so, but I get the following output:

Data directory: /media/USBdrive/ncdata (I click apply)

[ nc-datadir ] (Wed Jul 23 19:45:34 UTC 2025)
INFO: /media/myCloudDrive/ncdata is not empty. Creating backup /media/myCloudDrive/ncdata-07-23-25.1753299935
Your data directory is invalid.
Ensure there is a file called ".ncdata" in the root of the data directory. It should have the content: "# Nextcloud data directory"

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/nextcloud/lib/private/Console/Application.php:143
Stack trace:
#0 /var/www/nextcloud/console.php(81): OC\Console\Application->loadCommands()
#1 /var/www/nextcloud/occ(33): require_once('...')
#2 {main}

In my NextCloud configuration list, the data directory is /opt/ncdata/data. When I check this folder over SSH, it’s empty. I don’t know why there is a folder called “myCloudDrive” mentioned in the output when I tried to assign “USBdrive” as my data directory, but it exists and appears to have identical contents to USBdrive.

Here’s one question I have: could I copy the contents of USBdrive/ncdata (which is the directory “Data”) back to the original data directory (/opt/ncdata/data). If the system still believes that this is the data directory, would copying the files back into the folder allow it to resume working? This wouldn’t solve my overall problem, in that I’d still need to figure out how to move the files successfully onto the USB drive. But it would be nice to successfully revert back to a functional state.

Second: how do I correct the error that prevents me from reassigning the data directory? What does this error (“Environment not properly prepared. in /var…Application.php:143”) mean?

Even “hidden” files?

I think it comes from labeling the partition when setting up the usb-device.

I would give it a try, you did good back ups beforehand anyway, did you? :grinning_face:

I#m not sure, but check the thing with non empty dataroot - .ncdata file, also check ownership user / group has to be www-data.

I checked, and there were no hidden folders.

I went ahead and moved the data back to its original drive. I no longer get the error I got before, but now it says that it’s in maintenance mode:

Maintenance mode

This NextCloudPi instance is currently in maintenance mode, which may take a while. This page will refresh itself when the instance is available again.

Contact your system administrator if this message persists or appeared unexpectedly.

I searched for instructions, as it has stayed this way for more than 24 hours. I searched and found this guide: How to easily fix “This Nextcloud instance is currently in maintenance mode”

I ran the command, and it seems I now have access again. I need to figure out what I did wrong and how to do this correctly now. Thanks for your help!

So I propose taking ncp-config instead off webui:4443, should be the same, but I think I succeeded more often using the cli.
Good luck.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.