Owncloud and an external hard drive

When installing OwnCloud, you will probably have an external hard drive that you will want to have as your data directory. You can place the entire owncloud directory on your hard drive but this will result in slower performance when really all the large data files will be in /data. By moving /data, you have gigabytes or terabytes of extra storage that your desktop machine cannot run. Getting OwnCloud to recognize that external hard drive is tougher that you think. Here is my solution following the different threads I found online:

You could change /var/www/owncloud/config/config.php ‘s datadirectory to look at the new location, but that never worked for me. Rather, we are going to create a mount point and not a symbolic link. The symbolic links have a permission issues that “mackey” discovered and they will cause you a huge headache.

  • Notes before reading:
    • Some of these may need a sudo in front to execute.
    • You can apply stricter permissions in the chmod step.
    • If you mess up the mount step, you can edit /etc/mtab to remove your mounts or you can use umount folder_you_mounted to clean up your mounts.
  1. So, create your folder on your hard drive, let’s call it
    mkdir /media/user/your_hard_drive/owncloud_data (Updated on 3/12/2015)
  2. Stop your webserver service (updated on March 4, 2017)
    apache2: sudo service apache2 stop
    nignx: sudo service nginx stop
  3. Copy your data directory to the new location
    cp -rT /var/www/owncloud/data/ /media/user/your_hard_drive/owncloud_data/
  4. Rename your data directory to avoid confusion
    mv /var/www/owncloud/data /var/www/owncloud/data_original
  5. Apply the proper group and read permissions onto the hard drive’s data directory
    chown -R www-data:www-data /media/user/your_hard_drive/owncloud_data/
    chmod -R 755 /media/user/your_hard_drive/owncloud_data/
  6. Make the folder that will be mounted
    mkdir /var/www/owncloud/data
  7. Apply the proper permissions onto this soon-to-be-mounted folder
    chown -R www-data:www-data /var/www/owncloud/data
    chmod -R 755 /var/www/owncloud/data
  8. Make the mount
    mount --bind /media/user/your_hard_drive/owncloud_data/ /var/www/owncloud/data/
  9. Verify your server is up and running. (added on Jan 9, 2016) (updated on March 4, 2017)
    apache2: sudo service apache2 restart
    nginx: sudo service nginx restart
  10. Verify you can access your owncloud server (typically localhost/owncloud)
  11. Verify in top right Username>Personal that you have a large amount of storage space left.

Sources:

  1. http://forum.owncloud.org/viewtopic.php?f=17&t=7118
  2. http://www.dslreports.com/forum/r29286602-open-basedir-prohibits-opening-var-www-owncloud-data-owncloud.db
  3. http://backdrift.org/how-to-use-bind-mounts-in-linux
  4. http://www.linuxquestions.org/questions/linux-software-2/can-i-cp-hidden-files-627605/
This entry was posted in How-To, Linux, Nextcloud/OwnCloud and tagged , , , , . Bookmark the permalink.

22 Responses to Owncloud and an external hard drive

  1. loscar says:

    hello, thanks for this .

    how can i give plex access to thie new /user/owncloud_data/ folders ?

    • briangoodacre says:

      Access is all about permissions. So either make the /user/owncloud_data/ folders 777 with chmod 777 /user/owncloud_data/ or you can try adding plex to the group that owns owncloud_data.

  2. baumretter says:

    cheer mate, this really helped me! On the first line it should be mkdir instead of mdkir, however. Keep up the good work!

  3. John Peth says:

    Phenomenal thanks!
    You might want to add:
    sudo service apache2 start

    before checking to see if site works.

  4. Luke says:

    Not working on a Raspberry pi 2 running nginx. Any ideas?

    When I tried tried to do step 4 it wouldn’t allow me to. Said it was in use or busy. I did all the other steps, but it’s still showing that I only have 28GB of room and it should be much closer to 1 TB

  5. Pingback: Moving OwnCloud to a new home | Man and Keyboard

  6. Thank’s for the info!
    It’s needed to re-mount the directory when restart the server?

    • Brian_Goodacre says:

      I am not sure exactly what you are asking, but yes. When the server or computer is restarted, you will need to re-mount the directory each time.

      • danvp says:

        Hi Brian,
        I have been struggling a lot for a few days now trying to get Nextcloud working on an external HDD: Indeed, my approach has been to change the datadirectory in /var/www/html/nextcloud/config/config.php, and that just isn’t working.

        Your solution seems great, but I hesitate because of what you say here: having to manually re-mount the directory doesn’t sound like an attractive option.

        Is there a way to automate this?

      • Brian_Goodacre says:

        You can try using the external hard drive plug-in. Your hard drive will appear as a folder in your Nextcloud where you can save files.

  7. Kenny Pyatt says:

    Thanks for the article.

    If you want to avoid the mount issue with restart you can add the mount to /etc/fstab. Below is my entry mounting to a NFS server.
    192.168.1.132:/share/OwnCloud /var/www/owncloud/data nfs defaults

    • Laimis says:

      Is your Owncloud works fine through NFS? What OS version? Did you do any special steps for it except ensuring the right permissions, startup and mounting? Thanks in advance

  8. Andres says:

    Hello man, this is great!

    It worked with nextcloud 10.0 version I guess is the right version. Of course we just have to change the name of “owncloud”

    If you don’t mind I will copy the steps that I did with NextCloud which are pretty much the same, I did a research so deep into the folders but I will copy the steps for everyone to be easy to understand:

    *
    Just remember to replace with your own values the words
    user
    your_hard_drive
    *

    (Updated on 11/19/2016)

    1. Create your folder on your hard drive, let’s call it:
    sudo mkdir /media/user/your_hard_drive/nextcloud_data

    2. Stop your apache2 service
    sudo service apache2 stop

    3. Copy your data directory to the new location
    sudo cp -rT /var/www/html/nextcloud/data /media/user/your_hard_drive/owncloud_data/

    4. Rename your data directory to avoid confusion
    sudo mv /var/www/html/nextcloud/data /var/www/html/nextcloud/data/data_original

    5. Apply the proper group and read permissions onto the hard drive’s data directory
    sudo chown -R www-data:www-data /media/user/your_hard_drive/nextcloud_data/
    sudo chmod -R 777 /media/user/your_hard_drive/nextcloud_data/

    6. Make the folder that will be mounted
    sudo mkdir /var/www/html/nextcloud/data

    7. Apply the proper permissions onto this soon-to-be-mounted folder
    sudo chown -R www-data:www-data /var/www/html/nextcloud/data
    sudo chmod -R 777 /var/www/html/nextcloud/data

    8. Make the mount
    sudo mount –bind /media/user/your_hard_drive/nextcloud_data/ /var/www/html/nextcloud/data

    9. Verify your server is up and running
    sudo service apache2 restart

    10.Verify you can access your owncloud server (typically localhost/owncloud)
    localhost/nextcloud

    11.Verify in top right Username>Personal that you have a large amount of storage space left.

    -Confirmation-
    12. Also I created some random folders on nextcloud and some text files to check if were on the usb hard drive and were created correctly since I plan to have the orange pi server connected and whenever I need to take the drive with me I have everything on it and it worked flawlessly. In addition, I formatted the USB drive as NTFS and worked on Windows as well without additional programs

    Hope this helps for someone else with NextCloud as well 🙂

  9. Pingback: Best Nextcloud 11 Links | Man and Keyboard

  10. CGP says:

    Thanks for the writeup, works like a charm.

  11. Phil says:

    After so many trials, where either setting another data directory failed altogether, or at least somehow was not recognized and the space still limited to the few MB left on my SD, this right here has eventually made it work.
    Great job, and I can’t express my gratitude enough after all these hours!!

  12. room552 says:

    Hi, I am using Nextcloud snap straight on Ubunutu 18.04 (no apache2 or nginx). The only way to be able to read and write files on the Nextcloud browser interface is by setting chmod to 777 for the mount point. Any idea what I can do to avoid this?

    • Brian_Goodacre says:

      You can lower the world permissions to zero, like 770. And I don’t think you need the execute permissions as well.

      • room552 says:

        Hi Brian,
        Setting permissions to 770 didn’t work with the Snap Nextcloud setup; the only parameter that allowed access from Nextcloud to the external drive was 777. I have since started over with a regular LAMP setup and Nextcloud, and I can set user permissions for the external drives to 755 and access the drive.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s