Raspberry Pi External Storage Part 1 – Step by Step Permanent External Hard Drive (plus OwnCloud Adjustments)

October 29, 2013 11:02 pm Leave your thoughts


In my previous article I described how to get OwnCloud up and running on the Raspberry Pi. I have trialled this for about a month now and it’s been working very well, syncing files between 2 other machines and mobile devices. So far I’ve been using the internal SDCard for this as most of the time I only use my Raspberry Pi’s OwnCloud instance to transfer photos between the devices especially those that I took using my mobile phone.

I want to start using the Raspberry Pi to share and sync bigger files though, so I decided to salvage an older HDD from my older PC and put it in an external enclosure. To be honest the only reason I haven’t been doing this is because I haven’t had the chance to decommission one of my desktops and turn its HDD into an external drive. In any case, the HDD is 320GB so it’s still pretty decent for casual file sharing locally. Plus, this saves me from running an entire desktop machine 24/7 which would have used a lot of energy.

Also, when I was doing this for my Raspberry Pi, I kinda wished I have a step by step list to follow. It might be easy for some people but having a guide like this would hopefully help those in need.

Preparing the Hard Drive

If you bought a new hard disk chances are that it’ll come either unformatted or  formatted in one of the Windows compatible partitions. We need to repartition the hard drive to be able to use it properly with the Raspberry Pi, especially if you start using it for OwnCloud or other services that requires full Linux directory and file permissions. If you noticed in the previous article I mentioned that I couldn’t use the USB drive because it was formatted with FAT file system.

The easiest way to do this is using the graphical tool called gparted. There if of course command line way to do this, but I like graphical stuff in general.

So start the desktop if you haven’t using startx. Then open a terminal instance. Once open, use apt-get to install gparted.

The above command will install the full tool for you.

Eject the Hard Drive

photo-21-10-13-23-23-22-2_0When the tool installation has been completed, connect your external hard drive. Then make sure that the hard drive is ejected from the system. You can do this by simply opening the file browser and ejecting the hard drive.

Doing this will ensure that the partitioning software will be able to access the hard drive and format properly.

Partition the Hard Drive

The next step would be partitioning. Open a terminal window and run gparted. This needs to be run as root.

Within gparted, make sure you choose the correct device to re-format. Do this with caution please.


Once you have selected the drive, delete any existing partition then create a new one with ext type. We need to use ext2 or ext4 if we want to be able to use this drive with proper file and directory permissions, which would be required by applications such as OwnCloud.


After this just wait until the hard drive is fully formatted. We will then continue to setup mounting permanently.

Mounting the Hard Drive Permanently

First create the directory where the hard drive will be mounted. In this example I’m calling the directory extstorage.


Next, we will identify the correct device id for the external hard drive. We do this by cross-checking the information returned from lsblk and listing the device by uuid. So run these two commands one after another.


As you can see from the screenshot above you’ll be able to find out the correct hard drive from the size of the sda1 and then get the correct UUID of sda1. In our example above it’s 340b922b-e….d115. Copy and paste this UUID to a text file as we will use this in the next step.

We will now update the fstab file so that this device can be mounted automatically every time we restart the Raspberry Pi. So open the fstab file as a root using your favourite text editor, I’m using leafpad for this example.


Add the mount settings to the next line of the other mounts. That previous line before the highlighted line is the dduckusb from my previous article, that one cannot be used with OwnCloud as it’s formatted in FAT32 and mounted with vfat partition.

The mount type that we want for this external hard drive is ext4 just like what we format this hard drive as, in addition we set it up to be mounted at /media/extstorage. As for the rest of the options, we just left it as defaults as this will suit our needs for file storage drive. If you are interested to find out more about fstab settings, there is a good article here from the Ubuntu Community.

Now save the settings and test it by running the mount -a command as root.

The command above will re-run all the entry in the fstab file, if any of them is already mounted then the entry will be ignored. When this works you’ll be able to see the drive in the file manager. That’s it, you’re done setting up the drive.


Now we’ll adjust our previous OwnCloud installation.

Adjusting OwnCloud Configuration to Use the New Disk

This should be the easiest part.

Firstly, create the directory where the OwnCloud files will be stored. In this example I used /owncloud/. This directory must be owned by www-data user.

We then copy any existing OwnCloud data from our previous installation (if you tried the last article) to the newly created OwnCloud directory.

When all the existing files have been copied over, we open the OwnCloud configuration files for editing.

Then change the datadirectory settings into the new OwnCloud directory path, which was /media/extstorage/owncloud

Lastly, restart the apache server check you OwnCloud installation and sync from your devices. In my case it was relatively smooth, all of my devices are able to retrieve the shared files and upload new files.  In fact all of the photographs in this article was shot using and iPhone and then uploaded to my Raspberry Pi’s OwnCloud. When my laptop finished sync, I can straight away used all the images with this article.

This conclude the part 1 of this guide. On the next part I will talk about setting up Samba share using this external hard drive. Just like this article, I decided to write one because Samba can be tricky. Until next article.

UPDATE: Step right up to Part 2 here!

Tags: , ,

Categorised in: ,