Building Your Own NAS with FreeNAS

It’s the 9th week I’m working in isolation, and I needed a new project. So I look into my old PC and thought that I’m going to make a server out of this.

In this era of big data, we have tons of data, and we should be careful of what we put on the cloud. Chances are we may lose all of our data, or got it hacked, stolen, or ransomed. Building your own NAS allows you to have a complete ownership of your data. It is after all sitting in your own property. While ready made NAS may have been an option, I prefer to build my own NAS, because it’s cheap, and it’s just much more fun.

Before I jumped in, I would like to address a few things:
First of all, FreeNAS is very stable. It is enterprise-grade and the company that support this sells TrueNAS, which is FreeNAS with their certified hardware-build.
Second, FreeNAS uses ZFS file system. This is the best ever file system. Unfortunately this is not available from Synology or QNAP.
Finally, FreeNAS is literally free. For the same specification I have, you will be spending thousands of dollars from Synology or QNAP.
And personally I feel having the full control of my OS is the biggest benefit.

By the end of this tutorial, you may decided that this is way too much work. And to be honest, it is. But I dare you try. You can use your existing laptop, and an external USB drive, or even use a Raspberry Pi. Or simple set it up in a VM. Just try. Message me if you encounter a problem.

FreeNAS, however is not for everyone. It isn’t like Synology where you can simply extend your drive pool and it will automatically resilver. It also doesn’t have Synology SHR which allows you to have different drive sizes. It also likely to use more power than ready made NAS. It is also does not have warranty or support, so you are on your own. I think the last part is a good thing however.

Here are my NAS requirements:
1. RAID Redundancy
2. File Server with Samba and NFS Support
3. Media/DLNA server via Plex
4. Runs Virtual Machines
5. Sync files to my cloud providers
6. Surveillance Camera Server
7. Backup Server
8. Local Web Server – would like to run a few homemade web apps

Here is my hardware spec, bare in mind that this is a 6 years old PC:
Motherboard: Gigabyte Z97N-WIFI mini-ITX (6 SATA3 ports)
Processors: Intel Core i5-4690
RAM: 16GB DDR3
Hard drive: 3x4TB WD RED, 3x 4TB Seagate Ironwolf.
Case: Fractal Design Node 304

INSTALLATION
To install, download the iso file from FreeNAS. Also download Rufus if you are using Windows.

Then using Rufus, build the installation USB. You will also need to clean the boot drive(s) to ensure no partition remaining. In Windows this is done with diskpart. Note that Disk Management is not good enough.

To use diskpart, simple open Command Prompt, or PowerShell, and type diskpart.
Then type: list disk
Take a note of the disk number of your USB.
Then type: select disk 3
Then type: clean

In my installation, I use two USB drives for redundancy. You may choose to use SSD instead, but it is not required, and performance gain from SSD in FreeNAS is minimal.

Insert all your USBs and turn on your system. Make sure to setup your BIOS to boot from the installation USB.

Press 1 to install. Select all the USB drives that you wish to boot from, and FreeNAS will automatically mirror them. This means if one of the USB drive dies, the system will not be impacted. Choose Boot via UEFI because your motherboard is likely made in this century.

After installation, remove your installation USB and let the system boot into your brand new FreeNAS. This will take up to 1 hour.

When it finishes, it will show the FreeNAS IP address. Then with your laptop or PC, open a browser and go to the IP address that is shown on your FreeNAS.

First thing we need to do is setup the storage pool.
A pool is basically a collection of drive that is accessed as one. Storage pool can consist multiple VDEV, and a VDEV can consist multiple drives.
For more information read here.

I set up all my drives as 1 pool with RAIDZ, which will allow me to have 1 drive faulty before I lose all my data. If you have spare SATA port, you can use it for Log (which will speed up writing), Cache (or L2ARC, which will speed up reading), or Spare (which is a spare, literally). If you are a common home user like me, it is unlikely you can realise the benefit of using any of those.

Dataset is basically a partition. You should plan ahead how you would like to partition your pool. It is best to setup a separate pool for each purpose. For example my setup is:

  1. BigDataGuy – this is where all my personal files stored.
  2. Media – all my Movies, Music, Photos, etc.
  3. VM – all my VMs.
  4. Backups – Any backup files, OS, etc.
  5. Surveilance.
  6. Web – any web hosting files.

USER ACCOUNTS

Now that we have the drive set up, we need to setup the user and group accounts. Again it is also best to create a user for each applications. For example my setup is:
1. root – this is created by default.
2. bigdataguy – that’s me. I will use this to access the files.
3. www – created by default, this is for web hostings permissions.

To set up, simply go to Users and add user. You can assign the user to a new group, or existing group.

Now that we have the storage and user set up, we can set up the file sharing server. As I have Windows and will have Ubuntu, I will need to set up Samba and NFS share.

SETTINGS
Before we continue further, it is best to setup some of the storage settings.
Go to System > Advanced and tick the “Enable Autotune” option.

Go to Tasks > S.M.A.R.T Tests and add these two tasks:
– A weekly Long Self-Test on Sundays
– A daily Short Self-Test

Go to Tasks > Scrub Tasks, and set up a task. I setup mine weekly.

SMB SETUP
Go to Services> SMB, then select tick “Start Automatically”. While you are here, why not tick a few others as well?

Then open the SMB Configuration and made the following changes:
Set the “NetBIOS Name” to: bigdataguynas
Set the “Workgroup” to: bjgdataguynaslan
Set the “Description” to: Big Data Guy NAS http://www.bigdataguy.blog

Then go to Sharing – SMB, and add the folder you would like to share. Leave other settings as default.

SMB requires sharing to be setup in the Pool. So go to the Storage and select your dataset that you shared. Set Permissions on the “share” dataset to the selected user and apply the permission recursively.

NFS Setup
Go to Services then NFS. Select start automatically.

Go to Sharing-NFS, and add the folder you would like to share.
SET Maproot user to the user that you would like to have write permission, otherwise set it to nobody.

EMAIL SETUP
Before setting up email, you need to have email entered in your root account. So go to Users, and check if you have email on your root account.
Then go to System > Email then fill out the details.
If you have set up 2-factor authentication on you Mail Provider, then you need to get app password, instead of using your normal password.

The email is useful to send you notification if anything gone wrong.

UPDATING FREENAS
The good thing about FreeNAS is that it has frequent update.
However you should still update when you want to, when there is a good reason to do so. The last thing you want is having your server or plugin unavailable due to incompatible update.

You should make a good habit to save config and encryption keys regularly.
If anything is wrong, simply reinstall FreeNAS, restore the config and keys! FreeNAS also create a snapshot in the boot drive prior to every update.

PLEX SETUP
Now we got storage and sharing done, we are getting to the fun stuff.

Go to Plugins and choose Plex, and click Install.
This will automatically create a jail and install all the files.
In my installation somehow it failed when I choose DHCP, so I chose NAT instead. After the installation, I switched it back to DHCP and all runs well.
When the installation finished, click on Manage.

There are reported issues with Plex web server can’t be reached. If you are experiencing this problem, try go to Jails and then expand Plex and click Shell and type:
– service plexmediaserver stop
– service plexmediaserver onestart
That should do the trick.

Before you can manage your Plex Server, you need to mount the storage, which in this case the Media pool.
Go to the Jails > Stop Plex > Mount Point > Add mount points

That’s it! Your Plex media server now should be setup.

SYNCTHING
Syncthing is a peer-to-peer sync service. Unlike cloud, it doesn’t store the file in one location, instead it sync the files in all location.

Installing Syncthing is easier than Plex. Go to Plugins > Install > Set the mount points, and it just works.

To Sync, install Syncthing in the other device, and share the Device ID.

Syncthing is available in Windows and Android, but not on iOS……

CLOUD SYNC
Chances are you have a Cloud Provider and you would like to sync your server to the it. Most Cloud providers are supported, except Apple iCloud (do you read this Apple?).

To Set Up Cloud Sync, you need to set up Cloud Credentials.
Go to System and setup Cloud Credentials.
The example below is to set up OneDrive.

If you haven’t done this before, you need to get access token.
To get access token, you need to:
1. Download and install rclone.
2. Go to Windows Powershell and go to the rclone folder.
3. Type the following command:
– start rclone config
– n (new remote)
– remote
– type the number for the one drive as listed (eg. 23)
– leave client ID and client secret blank (press enter)
– press n for advanced config
– y for auto config, this will open a browser windows
– Press Yes to enable the app for access.
– Choose 1 for onedrive personal.
– choose 0
– choose Y for is that OK
– copy the access token and drive ID
– be sure to copy up to the quotes (“) mark

Now that you got the credentials set up, go to Tasks > Cloud Sync Task, and setup OneDrive.
To test, just press start and verify the data is pulled to your NAS.

NEXTCLOUD
At this point, I’m pretty happy with my setup.
I got Syncthing happily synchronising my files with my PC and Ubuntu, backing up photos on my phones, and I got the CloudSync automatically download anything in OneDrive.

However, just for fun, I would like to try NextCloud. NextCloud is one of the best, if not the best open source Cloud Provider. It is very difficult to setup that you can access from the Internet, but it is very simple if you just would like to access in your LAN Network.

Installing this is again very simple:
Go to Plugins and Install NextCloud.
Choose DHCP.
After installation, open post install notes, and take note of the ncadmin user name and password.
Then click Manage and login using ncadmin and the password.
Go to Settings and setup users for myself, and setup email (if you have two-factor authentication setup, then you would need to get app password).

Next Cloud is available on iOS and Android, you can set it up to Auto Upload your photos and videos.

Back to the NAS. Stop NextCloud, and mount the folders. This will be where Next Cloud store your files. You should mount the folder to this location: /mnt/<your Nas name>/iocage/jails/nextcloud/root/usr/local/www/nextcloud/data/

After mounting the folders, you need to set the permission owner to NextCloud so that it can read and write your files. The owner of NextCloud is www.
To do this SSH to the FreeNAS with Putty, and go to the Next Cloud data folder.
Enter the following command:
Chown www <your mounted dataset>

ANTIVIRUS
It is always good to have a secondary antivirus on top of the one you already have on your client machine.

For the antivirus, I use the recommended plugin ClamAV.
Then follow this instruction: https://github.com/jaburt/FreeNAS-Server-ClamAV-Scan

FINAL WORD
Chances are your server isn’t working straight away. If it doesn’t, you can read the documentation here, or just contact me and I will try to help you.

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 )

Facebook photo

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

Connecting to %s