Technical Anshu
Tutorials Blog
Nextcloud Storage

Move Nextcloud Data Directory to a Bigger Disk After Install

The install put every file on the Ubuntu disk. Here is the careful sequence that moves the data directory onto the big disk - and why week one, while it holds almost nothing, is the time to do it.

By Technical AnshuUbuntu ServerSelf Hosted9 minute read
Watch the full video - the one-step Nextcloud install on Ubuntu, step by step

By default the snap keeps user data in /var/snap/nextcloud/common/nextcloud/data - on the system disk. That disk is usually the small fast one. The good news: the move is a documented, well-trodden path. The honest warnings first: on the snap the new home must live under /media or /mnt because the package runs confined, and the move is a copy-while-stopped job, so do it early, before the data is measured in hours of copying.

Terminal - the move, in order
$ sudo snap connect nextcloud:removable-media $ sudo snap stop nextcloud $ sudo cp -a /var/snap/nextcloud/common/nextcloud/data/. /media/datadisk/data/ $ sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php 'datadirectory' => '/media/datadisk/data', $ sudo snap start nextcloud
The essence of the sequence - the sections below add the mounting and permission steps that make it survive a reboot
1

Before You Touch Anything

Three preparations decide whether this is a calm job or a rescue:

  1. Attach and mount the new disk permanently. Add it in /etc/fstab mounted under /media/datadisk or /mnt/datadisk, then reboot once and confirm it is there. A disk that only appears when someone clicks it in a file manager will vanish at the worst moment
  2. Take the fresh backup. You almost certainly do not need it - and this is still the wrong job to skip it on. The backup guide in this series is fifteen minutes
  3. Tell the users. The cloud is down for the length of the copy. In week one that is minutes
2

The Move, Step by Step

  1. Give the confined snap permission to see outside itself: sudo snap connect nextcloud:removable-media
  2. Create the target folder: sudo mkdir -p /media/datadisk/data
  3. Stop Nextcloud so nothing writes mid-copy: sudo snap stop nextcloud
  4. Copy everything, preserving ownership and the hidden marker file: sudo cp -a /var/snap/nextcloud/common/nextcloud/data/. /media/datadisk/data/
  5. Set ownership and permissions on the new home: sudo chown -R root:root /media/datadisk/data and sudo chmod 0770 /media/datadisk/data
  6. Point Nextcloud at it. Edit /var/snap/nextcloud/current/nextcloud/config/config.php and change the datadirectory line to 'datadirectory' => '/media/datadisk/data',
  7. Start it up: sudo snap start nextcloud
3

Prove the Move Worked

Do not delete anything yet. Prove the new home in this order:

  1. Log in - your existing files and folders are all visible
  2. Upload one new photo and open it back
  3. Check the file really landed on the new disk: ls /media/datadisk/data shows your user folders
  4. Reboot the server and log in again - this is the test that catches a bad fstab entry while the old copy still exists

Keep the old data folder untouched for a few days of normal use. Only when the reboot test and a few days of uploads have passed is it safe to reclaim the space on the system disk.

4

The Other Option - Add Space Without Moving

Moving the data directory is not the only shape of growth. Nextcloud's built-in External Storage app can mount an extra disk or folder as additional space inside Nextcloud, leaving the main data directory where it is. That suits an archive disk - big, rarely changing files - very well. It is a weaker answer for the main home: quotas, trash and versions behave most simply when the real data directory itself has room. Rule of thumb: main disk filling = move the data directory; adding an archive = external storage.

🔴 The snap-specific trap: pointing datadirectory at a folder outside /media or /mnt, or forgetting the removable-media connection, ends with a data directory is invalid error. The path rule is not Nextcloud being difficult - it is the snap's confinement doing its job.

Watch the Install This Disk Belongs To

The one-step install, and the fresh server this move completes.

Watch Full Video
Frequently Asked Questions

Can the data directory live on a USB drive?

Yes, if the drive is mounted permanently under /media or /mnt through fstab and the removable-media connection is made. Keep it attached forever after - if the drive is missing at boot, Nextcloud starts to an empty or invalid data directory.

Will I lose file versions and the trash bin in the move?

No. The copy command preserves the complete data folder including versions, trash and the hidden .ncdata marker file Nextcloud checks for. Verify by logging in and opening an older file before you delete the old copy.

Nextcloud says Your data directory is invalid after the move - what now?

In almost every case it is one of three things: the .ncdata file did not arrive (re-copy with the archive flag), the folder ownership or permissions are wrong (root ownership, 0770), or the path is outside /media or /mnt without the removable-media connection. Check them in that order.

This guide is based on the Technical Anshu Nextcloud install video - stuck on a step? Ask in the video comments and you will get a reply.