To use USB hard disks in your NAS setup, we need to make sure they auto-mount at boot. We also need to make sure that if the use the NTFS file system, we are allowed to write to them - this is what ntfs-3g
is for. Install ntfs-3g from the terminal:
sudo apt-get install ntfs-3gCreate mount point directory
First, we need to make some folders for the disks to be mounted to. As an example, we'll assume there is a USB hard disk with a single partition, formatted with a NTFS file system. It contains all of your legally owned videos and music, so we will call it 'Media'. Make a folder for the drive to be mounted to, and change the permissions so everyone on the network can read and write to and from it:
sudo mkdir /media/Media
sudo chmod 777 /media/Media Setup auto-mount
Now, let's set the disk to auto-mount to that folder at boot. We will edit a file called fstab
, which deals with all the file systems that are mounted at boot on your Pi. We need to gather some information about the drives first, so in a terminal type:
sudo blkid blkid
is a tool we can use to a drives metadata - specifically the UUID
. This is what we are going to make fstab use to identify the drives. Drives are automatically assigned to files in the /dev folder, but these assignments are not guaranteed to be the same every time your Pi boots, so we will use the UUID.
We are interested in the UUID of each drive/partition you wish to mount on your NAS. My drives were formatted and partitioned on a Windows client some time ago, and are easily identifiable by their labels. Copy the full output of blkid, then type:
sudo nano /etc/fstab
This will open the fstab file for editing. Bellow the text that is already there, leave a bit of space then paste the output form blkid. We will be deleting this later, but I think it's easier to have all the info infront of you - this won't be an issue on a Pi setup with a monitor, but I was doing this headless so it worked better in that situation.
Entries in fstab are in this format:
Device Name | Mount Point | File System | Options | Dump Options | FS Check Options
One of my entries as an example:
Device Name Mount Point FS Options DO | FSC O
/dev/sda /media/Ipod vfat auto,user,rw,exec 0 0
In the device name column, UUID= and Label can also be used. All entries are seperated by a single tab. Your entry should be structured like this:
Device Name: Use the UUID identified in the blkid output, without the quotes.
Mount Point: In the Mount Point column, enter the location of the mount point we created earlier.
File System: The information for the File System column can be found in the blkid output, after the word TYPE. The file system for FAT32 drives is vfat, and for NTFS drives you should use 3g-ntfs.
After these three columns, paste auto,user,rw,exec 0 0
So the entry for the fictional 'Media' drive would be (I'm just gonna make up a UUID):
UUID=5d2047b5-6eaf-46de-9a52-a3a19dfc3706 /media/Media ntfs-3g auto,user,rw,exec 0 0
Repeat this process (including creating a mount folder) for each drive or partition you want to share. Be sure to delete the output from blkid that you pasted in before you save and exit.
To test your new entries in fstab, in the terminal type:
sudo mount -a
This will attempt to mount all entries in fstab, unless they are already mounted. The second command will output information about currently mounted drives, which will indicate wether or not the entries in fstab are valid. If you see the mount folders you created listed in the output of df
, navigate to them and list their contents to confirm all is well.
Make sure you have nailed this part before carrying on - your Pi will have problems booting if there are faulty entries in fstab. If this occurs, you should be given the option of a terminal prompt, at which point you can open fstab in nano like before and remove the bad entry.