how to mount NAS storage in owncloud to keep all users data

In this post I am sharing about how I mounted the NAS storage in owncloud to keep all users data in it.
I checked the External Storage application of owncloud but here our requirement is we want to keep all data in NAS storage and user should not save anything in Owncloud Server’s disk.
The main trick is mounting part.

Scenario: Keep all user’s data in NAS storage and user should not save anything in Server hard disk.

Solution: For this trick,the owncloud should be installed in your server and working.In ownloud DocumentRoot there is one directory called data. We will mount NAS storage to data directory.

Step 1: Login into your NAS server and create a shared folder with username and password.I have use IOmega NAS server. The shared directory in NAS server should be accessed via Windows sharing (aka CIFS filesystem)

Step 2: Now login into Linux server in which you have installed owncloud.
In my server(Ubuntu) the DocumentRoot is /var/www/owncloud.
Hence the path of data directory is /var/www/owncloud/data

First of all check .are you able to mount NAS storage temporarily

Syntax:
mount -t cifs \NAS-Server-IP-addressSharedFolder-Name mounting-Directory -o username=give_username,password=give_password

eg.

mount -t cifs \192.168.1.10owncloud mnt -o username=owncloud-nas,password=owncloud_password

If you are able to mount successfully now unmount the partition

eg.

umount /mnt 

Step 3: Now we will permanently mount the NAS storage.But before this we have to do some changes

Copy the data directory of owncloud

 

cp -prvf /var/www/owncloud/data /var/www/owncloud/data.backup

Now rename original owncloud’s data directory ,create new data folder,copy the contents from original data directory and change ownership and permission

mv /var/www/owncloud/data /var/www/owncloud/data.orig

mkdir -p /var/www/owncloud/data

cp -prvf /var/www/owncloud/data.orig/* /var/www/owncloud/data/

cp -prvf /var/www/owncloud/data.orig/*.* /var/www/owncloud/data/

chmod -R 770 /var/www/owncloud/data ; chown -R www-data:www-data /var/www/owncloud/data

Note: www-data is apache user in Debian and Ubuntu,if you are using Red Hat or CentOS replace www-data with apache word.

Get the uid of www-data or apache user by using id command

id www-data 
(For ubuntu and Debian)

OR

id apache  
(For CentOS and Red Hat)

Edit the /etc/fstab for permanently mounting NAS storage

Add the given below line in /etc/fstab ,it is just an exmaple. (As per your information change the ipaddress with your NAS server ip address, id no. of your apache user,NAS username and password)

vi /etc/fstab

\192.168.1.10owncloud /var/www/owncloud/data cifs user,uid=29,rw,suid,username=NAS_user,password=NAS_password,file_mode=0770,dir_mode=0770,noperm 0 0

Now run below command to mount the NFS storage without server restart

mount -a

Step 4: Restart the apache of linux server

/etc/init.d/apache2 restart
(For Ubuntu and Debian)

/etc/init.d/httpd restart
(For CentOS and Red Hat)

Step 5: Now test the owncloud server. Create some user,upload some testing files.
The user;s data directory will be created in /var/www/owncloud/data with their respective username.

If possible login to NAS server dashboard and check the shared folder, you will see uploaded testing files there.

38 thoughts on “how to mount NAS storage in owncloud to keep all users data”

  1. Thanks for an excellent guide for someone who is not so familiar with this. I have to things.
    1. I am running ownCloud on Ubuntu 16.04 and this might depend on that, but a correction or remark:
    cp -prvf /var/www/owncloud/data.orig/*.* /var/www/owncloud/data/ did not work for me. It must be
    cp -prvf /var/www/owncloud/data.orig/. /var/www/owncloud/data/

    2. A lot of people get a message from ownCloud that the data directory on the NAS can be red by others and therefore the chmod must be changed to 0770. Even if we do that nothing happens. My problem was actually that the shared folder on the NAS was shared by owncloud AND admin. Remove the permission for admin and that 0770 message is gone and it works fine..
    Thanks,
    Henrik

    Reply
  2. I cannot seem to mount to my NAS drive no matter what I do.
    Is there per chance changes in this proceedure with the latest version of Ubuntu 14.04 LTS?

    Reply
      • Here’s what I have;
        A folder named owncloud on my NAS server with an address of 192.168.0.10 and I am able to mount it as such;
        sudo mount -t cifs //192.168.0.10/owncloud /var/www/owncloud/test
        I have verified that it mounted.
        Where I run into trouble is when I try to mount this in fstab.
        this is what I enter into my fstab line:
        \192.168.0.10owncloud /var/www/owncloud/data cifs user,uid=33,rw,suid,username=xxxxxxxx,password=zzzzzzzzz,file_mode=0770,dir_mode=0770,noperm 0 0
        then i do this: sudo mount -a and restart apache
        After I do this I can no longer sync on the windows app or connect to the server from the web page.
        I looked in config.php and the data directory is still default but I dont think thats an issue due to mounting the Nas to that data directory.

        Sorry I’m so dense, but I am not sure what the problem is.
        Thanks

        Reply
        • Hi Sam,

          1. First of all I am not sure which Operating System you are using.
          2. Have you checked after mounting do any file or folder exist in /var/www/owncloud/data .

          Mount the NAS first and after this give me command output of –

          ls -ld  /var/www/owncloud/data
          
          ls -l  /var/www/owncloud/data
          
          df -Th
          
          id www-data ; id apache
          

          Regards
          Sharad

          Reply
          • I am running Ubuntu 14.04LTS and owncloud Version 8.2.
            1>
            drwxrwx— 5 www-data www-data 4096 Jan 18 14:33 /var/www/owncloud/data

            2>
            drwxrwx— 2 www-data www-data 4096 Jan 14 16:08 data
            drwxrwx— 6 www-data www-data 4096 Jan 11 15:13 engineer
            -rwxrwx— 1 www-data www-data 0 Jan 7 17:36 index.html
            -rwxrwx— 1 www-data www-data 2370 Jan 11 15:29 mount.json
            -rwxrwx— 1 www-data www-data 149504 Jan 18 14:36 owncloud.db
            -rwxrwx— 1 www-data www-data 12396 Jan 11 15:11 owncloud.log
            drwxrwx— 5 www-data www-data 4096 Jan 11 15:01 sales01

            3>
            Filesystem Type Size Used Avail Use% Mounted on
            udev devtmpfs 994M 4.0K 994M 1% /dev
            tmpfs tmpfs 201M 1.1M 200M 1% /run
            /dev/sda1 ext4 72G 4.8G 63G 8% /
            none tmpfs 4.0K 0 4.0K 0% /sys/fs/cgroup
            none tmpfs 5.0M 0 5.0M 0% /run/lock
            none tmpfs 1004M 144K 1004M 1% /run/shm
            none tmpfs 100M 28K 100M 1% /run/user

            4>
            uid=33(www-data) gid=33(www-data) groups=33(www-data)
            id: apache: no such user

            I really just need to have the documents folder and photo folders reside on NAS and not on the Owncloud drive.

  3. Hi,
    Thanks for your tutorial, i just wanna know if i create a shared folder in windows file server, NTFS & Sharing permission are assigned to that folder and I want to mount that folder in own cloud will it work?

    I want if a user browse the file server through explorer or login own cloud, he should be able to view the folder on which he has assigned permission through active directory.

    any help in this regard would be appreciated.

    Thanks

    Reply
  4. Thank you Sharad! Just what I was trying to accomplish. It worked with a little modification to the mount command line structure on Ubuntu 14.04.

    Reply
  5. Thank you for this guide.

    On my Ubuntu 14.04 I successfully could mount my NAS-share. On the root-dir, and the second one i have write permissions. But if I go to the third dir write premissions are gone. any idea?

    Reply
    • Hello Schickel,

      I did this task long back ago. Send the output of ls -l command. In this way I am not able to understand your question.

      Regards
      Sharad

      Reply
  6. After I copied everything, mounted the NAS storage, and restarted apache I got the following error with owncloud:

    An exception occurred while executing ‘SELECT “configvalue”, “appid” FROM “oc_appconfig” WHERE “configkey” = ?’ with params [“enabled”]: SQLSTATE[HY000]: General error: 1 no such table: oc_appconfig

    Can you help? Thanks!

    Reply
  7. Sharad,

    I am a linux idiot / newbie and had to sort out our owncloud. U’re a life saver, and i could give you a kiss!!

    Thanks for sharing the information and its exactly what we needed.

    Cheers!

    Reply
  8. Followed but getting error Can’t create data directory (/var/www/html/owncloud/data) in webbrowser. Already disables SELinux which was a problem on the internet

    Reply
      • . I am using CentOS 6.4. Owncloud is working correct before I make changes described in your tutotail.

        Only thing whay is different that path for Owncloud is /var/www/html/owncloud. I made a simple text in test.html in /owcloud/data/ and this is displayed correctly in the browser

        This is the error on the page

        Can’t create data directory (/var/www/html/owncloud/data)

        You can usually fix this by giving the webserver user write access to the config directory in owncloud */

        Reply
        • Hello Greg,

          In CentOS, the web server user name is apache.
          Check the permission and owner/group at /var/www/html/owncloud/data
          data directory you have to create and mount NAS partition with it.
          Carefully read Step 3. First I rename the existing data dir. Then I created a directory with name data. Then I mounted the NAS with data dir

          Can you send me the output of
          cat /etc/fstab (Change username and password from output before sharing)
          df -Th
          ls -ld /var/www/html/owncloud/data

          Reply
  9. Hi,

    Thanks for this memo. If you choose SQLITE and owncloud complains about SQLITE :

    Error while trying to create admin user: SQLSTATE[HY000]: General error: 5 database is locked

    then pass “nobrl” to cifs :
    \192.168.1.10owncloud /var/www/owncloud/data cifs user,uid=29,rw,suid,username=NAS_user,password=NAS_password,file_mode=0770,dir_mode=0770,noperm,nobrl 0 0

    Note, SQLITE over CIFS is a *bad* idea.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.