Installing a NAS Server
There are usually 3-4 major parts.
- Setting up the Raspberry Pi - Getting Started
- Configuring the USB Drive
- Setting up the NAS Settings using NSF
- Configuring NextCloud or other additional software
We're just going to cover the first three. However, we will not setup mirroring or RAID. For a RAID setup the data would be stored on 2-5 USB hard drives (RAID 1 uses 2 disks, one is used for the everyday traffic, the other is used to store backups). However, the active USB hard drives should have it's own power supply because the RPi cannot power two USB drives. I'll be adding information on NextCloud vs OwnCloud. They both could be used but there are differences. NextCloud appears to have more current support.
Setup the Basic Storage
Step 1. Format the hard drive
While you can format the drive at the command line, it's easier on your laptop or desktop computer.
Windows:
- Plug in the hard drive and open Windows Explorer.
- Right-click on the drive icon and choose Format from the drop-down menu.
- Select the file system you want (ext4), give your drive a name under Volume label. ____rose1____. Name yours what you want!
- Make sure the Quick Format box is checked.
- Click Start, and the computer will reformat your drive.
Mac:
- Go to the Utilities folder and select Disk Utility.
- Select your drive, right click and select Erase.
- Give the disk a name. __rose1_____ Choose the format (extf).
- The partition scheme should be GUID (NOt MBR!). Click Erase.
Hard disks are organized using sectors, cyllinders are used to identify information location on the hard disks. Changes the partition tables can break your machine. So be careful! You will use fdisk to verify your settints.
Step 2. Physically connect your hard drive to the Pi
Step 3. Connect to your Pi using SSH
1. Choose the program you will use to connect using SSH.
- You can alternatively use VNC (ie. Real VNC works well) if you enabled it and used the GUI version of Raspbian.
- If you are using Windows you will likely use Putty to connect. You'll need to download Putty and install it.
- If you are in a Mac, you don't have to install anything. Just open the Terminal program located in your Utilities folder.
2. Type in the ssh command and your user name and password.
- Make sure to use your PIs IP address! If you don't have access to your PIs address there are programs like Pi Finder and you can look up the IP if you have access to the router.
- ssh pi@192.168.1.163
- Enter your password you typed in earlier. ___________________
- You will see a message:
The authenticity of host '192.168.1.163 (192.168.1.163)' can't be established. ECDSA key fingerprint is SHA256:YJA0w78MM1pZn3G+mbJVNVJK3nsPL0pq+WwdMYmWlts. Are you sure you want to continue connecting (yes/no/[fingerprint])?
3. Type Yes.
Configuration TIP: What can go wrong?
Some computers like Macs, keep the certificate information. It will permanently added '192.168.1.163' (ECDSA) to the list of known hosts. So if you are using the same device and switch out SD Cards, you might have issues. It won't happen the first time but will on other times. If that happens, on a Mac, you have to run this code to reset the keys.
- cd /Users/katie/.ssh
- ls
- ssh-keygen -R 192.168.1.12
Setup the NAS Share
Step 1. Configure and Mount the Drive
1. Sudo fdisk help provides options and usage examples for the command. The option L will display partitions and exit.
sudo fdisk -l
2. You'll get something that looks like this (sda/sdb/sdd may vary) Because we formatted the disk already you do not need to use fdisk to reformat the drive.
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 98765433w3 1565677888 199.5G 83 Linux
3. Install all the HFS packages we need by running the following command.
sudo apt-get install hfsplus hfsutils hfsprogs gdisk
4. Add a label for the new partition on the hard drive. Make sure the values match up!
sudo e2label /dev/sda1 rose1
5. Find out what is your current working directory too! It should return /home/pi.
- pwd
- ls
6. You need to install autofs and create the mount point for the storage. After a power outage when Pi boots up, the USB drives are not always available to get mounted. Use autofs to mount them when needed.
sudo apt install autofs
sudo mkdir /nas
7. Mount the devices by adding the following line to /etc/auto.master:
sudo nano /etc/auto.master
/nas /etc/auto.usb (add this line - we don't have the file yet!)
8. Create the file you just mentioned, auto.usb.
sudo nano /etc/auto.usb
rose1 -fstype=ext4,rw :/dev/disk/by-label/rose1 (add this line)
9. Restart the autofs service
sudo service autofs restart
10. Verify the files are mounted. The mount command shows the hard drive was mounted where it should be!
cd /nas/rose2 (this is really just a visual inspection)
mount
Step 2. Configure the NFS Share
1. Install the network file system (NFS) on the Pi.
sudo apt install nfs-kernel-server
2. Configure the NFS server to expose the /nas/rose1 directory. (again security issue, it's the only one accessible) We have to export the directory. Edit the exports file.
sudo nano /etc/exports
/nas/data *(rw,sync,no_subtree_check)
Security TIP: Remember that if you have access to the NFS ports 111 and 2049 they can mount the drice. You can modify the router's firewall to allow ports 22 and 443 access or, only allow devices in the home network to reach the NFS server. (sudo mount -t nfs <raspberry-pi-hostname-or-ip>:/nas/data /nas/rose1)
3. To mount the drive on a Linux computer:
sudo mkdir /nas/rose1
sudo mount -t nfs 192.168.1.92:/nas/rose1 /nas/rose1
4. The method to access files stored on the Pi-powered NAS from remote devices using the NFS mount will depend on your device. This is on my MacBook Pro not on the Pi!
cd /Users/[username]
cd Desktop
sudo mkdir nas
sudo mkdir /nas/rose1
5. Now mount the drive to the /Users/katie/Desktop/nas/rose1 folder.
sudo mount -t nfs pi1-nextcloud:/nas/rose1 /Users/katie/Desktop/nas/rose1
6. Now go to your server information and mount the drive to that folder.
nfs://192.168.1.92/nas/rose1
7. Write a file using Nano on the Pi. Verify that the file is showing up on the MacBook or PC!
You are done!
Resource:
- GRASPINGTECH. (8 Dec 2016). How to Mount an NFS Share on a Windows Computer
Next Steps
NextCloud or OwnCloud.
References
Manuel Dewald (Red Hat) . (24 Jul 2018 ). Building a network attached storage device with a Raspberry Pi. Follow these step-by-step instructions to build your own Raspberry Pi-based network attached storage system.
Manuel Dewald (Red Hat). (19 Sep 2018) Host your own cloud with Raspberry Pi NAS Protect and secure your data with a self-hosted cloud powered by your Raspberry Pi.
Alan Formy-Duval (05 Jun 2018). How to use autofs to mount NFS shares Configure a basic automount function on your network file system.
Raspberry Pi Basics: Installing Raspbian and getting it up and running.
Chinmay. (May 13, 2019). How to SSH into a Raspberry Pi [Beginner’s Tip]