How to use Block Storage to Increase Space on Your Nextcloud Instance
In a previous article, I showed you how to build your very own Nextcloud server. In this article, we're going to extend the storage for our Nextcloud instance by utilizing block storage. To follow along, you'll either need your own Nextcloud server to extend, or perhaps you can add block storage to a different type of server you may control, which would mean you'd need to update the paths accordingly as we go along. Block storage is incredibly useful, so we'll definitely want to take advantage of this.
Setting up the block storage volume
First, use SSH to log in to your Nextcloud instance:
ssh <IP or domain name>
If we execute
df -h, we can see the current list of attached storage volumes:
One of the benefits of block storage, is that you can have a smaller instance (but still have a bigger disk). Right now, unless you're working ahead, we won't have a block storage volume attached yet, so create one within the Linode dashboard.
You can do this by clicking on "Volumes" within the dashboard, and then you can get started with the process. Fill out each of the fields while creating the block storage device. But pay special attention to the region - you want to set this to be the same region that your Linode instance is in.
After creating the volume, you should see some example commands that give you everything you need to set up the volume. The first command, the one we will use to format the volume, we can copy and paste that command directly into a command shell. For example, it might look similar to this:
sudo mkfs.ext4 "/dev/disk/by-id/scsi-0Linode_Volume_nextcloud-data"
Of course, that's just an example command, it's best to use the command provided from the Linode dashboard, so if you'd like to copy and paste - use the command that you're provided within the dashboard.
At this point, the volume will be formatted, but we'll need to mount it in order to start using it. The second command presented in the dashboard will end up creating a directory into which to mount the volume:
sudo mkdir "/mnt/nextcloud-data"
The third command will actually mount the new volume to your filesystem. Be sure to use the command from the dashboard, the one below is presented only as an example of what that generally looks like:
sudo mount "/dev/disk/by-id/scsi-0Linode_Volume_nextcloud-data"
Next, check the output of the
df command and ensure the new volume is listed within the output:
Next, let's make sure we update
/etc/fstab for the new volume, to ensure that it's automatically mounted every time the server starts up:
sudo nano /etc/fstab
Within the dashboard, the correct line to add for the new volume will be presented there, so you can simply copy and paste that line into the
Setting up block storage with Nextcloud
Now that we have a new block storage volume, Nextcloud isn't going to be using it yet. So what we'll do, is set up the new volume to become the storage volume for Nextcloud's data.
cd into Nextcloud's application directory on your server. This path will vary from installation to installation, but in the previous article/video, we used the following directory (in my case at least):
Notice that within that directory, there's a sub-directory named
data. You'll likely have some files/directories within that
data directory. Continue by using
cd to change into the
data directory, and then move its contents into the block storage device:
mv * /mnt/nextcloud-data/
Now that we've moved the contents of the current data directory to the new block storage volume, we can tell Nextcloud to use that volume for its data. Inside the config directory, you should have a config line that corresponds to the data directory:
'datadirectory' => '/var/www/nextcloud.learnlinux.cloud',
Update the path section, within the single quotes, to the path to the newly mounted data volume that we've set up:
'datadirectory' => '/mnt/nextcloud-data',
Double-check the previous data directory, and see if there are any hidden files there. If there are, be sure to move those as well if the previous command didn't do that:
mv .htaccess .ocdata /mnt/nextcloud-data
To be on the safe side, be sure the permissions on the
data folder (in terms of ownership) are applied to the new storage volume:
sudo chown www-data:www-data -R /mnt/nextcloud-data
Although this isn't required, it's a good idea to reboot the server - especially to ensure that all open links to the old path have been disconnected. Once the server comes back up, you should be able to verify that Nextcloud is using the new block storage device. If so, then you're all set!
You can watch the tutorial here: