Welcome
In building my home NAS I have not found any full installation guides, so I shall create one in hope of helping others. I have chosen FreeBSD for its security stability and native ZFS support. FreeBSD is a free Unix-like operating system descended from AT&T UNIX via the Berkeley Software Distribution (BSD). FreeBSD currently has more than 200 active developers and thousands of contributors.
I have tried some really good open source FreeBSD NAS solutions.
Go Beyond “NAS”
TrueNAS is More than a traditional “Network Attached Storage”, TrueNAS is Unified Storage that integrates seamlessly into any environment with a variety of file, block, or object access protocols. You can also expand its functionality with a variety of free plugins, like Plex Media Server, NextCloud, Zoneminder surveillance, and many others.
XigmaNAS is Open Source NAS (Network-Attached Storage) distribution. XigmaNAS is easy to set up in most home and enterprise environments and will allow you to manage and share large amounts of data easily across your network. XigmaNAS also incorporates many different streaming features for sharing your multimedia with other devices on your network.
I was never quite satisfied as they are somewhat restrictive. I decided to build a FreeBSD NAS from scratch. So here we go!
Step One.
Download and install the base FreeBSD OS. For This Guide I will be using the latest FreeBSD 13.2-RELEASE . I will also be using Win32DiskImager to create a bootable USB stick. Feel free to use any method you are comfortable with to create installation media.
- Partition and format USB Device
- How to create bootable USB using Win32 Disk Imager
- How to Boot From a USB Device
- Installing FreeBSD
I use a standard installation set appropriate ip address to match your network. When completing FreeBSD installation make sure to create a non root user added to the ‘wheel’ group to allow root access later.
Step Two.
Once you have done the base OS installation you must decide what services you wish to run. I will install the essential components and try to list some other common NAS services.
Install List:
- iocage – A FreeBSD Jail Manager
- Plex – media server
- emby – media server
- Transmission – A Fast, Easy and Free Bittorrent Client
- Webmin – A web-based system administration tool
- Nut – UPS control
- NGINX – Reverse proxy for added security.
- Samba – file and print services for various Microsoft Windows clients and can integrate with a Microsoft Windows Server domain
Please comment on this post with any suggestions to add to this guide.
Step Three.
Login and update Base OS.
Now we will install any updates and bootstrap the pkg system on our NAS system. Package repositories used by the pkg(8) program consist of one or more collections of “package tarballs” together with package catalogues and optionally various other collected package metadata. This can be done directly on the console or the method I will be using over The Secure Shell Protocol (SSH).
PuTTY is an SSH and telnet client, developed originally by Simon Tatham for the Windows platform. PuTTY is open source software that is available with source code and is developed and supported by a group of volunteers.
There are many other options, so use what you are familiar with. Open your SSH client and connect to your FreeBSD Machine with the ip address you set during installation. Log in with the non root user that you created during installation. Once logged in use the su command and enter the root password to gain root permissions. SSH is enabled on the FreeBSD system by default.
# su
Make sure your installation is up to date.
# freebsd-update fetch install
Hit the ‘q’ key to continue the update. Then reboot and verify your version and patch level with.
# reboot # freebsd-version
Import Storage Data. If not already created your storage devices please see ZFS documentation.
Once created they can be imported and set to mount on boot up.
# zpool import -a # echo 'zfs_enable="YES"' >> /etc/rc.conf # zpool list
We need to create dir to keep our media storage.
# mkdir /mnt/media/media/movies # mkdir /mnt/media/media/tvshows # mkdir /mnt/media/media/downloads
Now we update the pkg system.
# pkg update
Now we will install a couple of useful tools we will use as we go forward. Nano is the text editor I prefer but feel free to use the one of your choice, there are many. GNU Wget is a free utility for non-interactive download of files from the Web.
# pkg install nano wget
Step Four.
Now we will start to install the various software components that make up our NAS system. The first component we will be installing is iocage used to create the Jail system we will use for most of our services.
Find The latest version and install.
# pkg search iocage # pkg install py39-iocage-1.2_10
Message from python39-3.9.18: Note that some standard Python modules are provided as separate ports
as they require additional dependencies. They are available as:
# pkg install py39-gdbm py39-sqlite3 py39-tkinter # echo 'iocage_enable="YES"' >> /etc/rc.conf
Above we set iocage to load at boot. Next we will activate our installation and fetch the FreeBSD tarballs. It will also create the directory structure required.
# iocage activate media # iocage fetch
Media is the name of the ZFS pool that I am using to hold all our jails. Change to whatever you named yours. Select which release you wish to use. This can take a while, go have a coffee. Remember if FreeBSD does not throw an error it is still working.
********************************************************************************
fdescfs(5) is not mounted, performance may suffer. Please run:
mount -t fdescfs null /dev/fd
You can also permanently mount it in /etc/fstab with the following entry:
fdescfs /dev/fd fdescfs rw 0 0
********************************************************************************
Creating media/iocage
Creating media/iocage/download
Creating media/iocage/images
Creating media/iocage/jails
Creating media/iocage/log
Creating media/iocage/releases
Creating media/iocage/templates
Default configuration missing, creating one
[0] 12.4-RELEASE
[1] 13.1-RELEASE
[2] 13.2-RELEASE
Type the number of the desired RELEASE
Press [Enter] to fetch the default selection: (13.2-RELEASE)
Type EXIT to quit: [Enter]
With this done we can create our first Jail. Jails are used to isolate our services from our main OS. The jail mechanism is an implementation of FreeBSD’s OS-level virtualization that allows system administrators to partition a FreeBSD-derived computer system into several independent mini-systems called jails, all sharing the same kernel, with very little overhead.
The file-descriptor file system, or fdescfs, provides access to the per-process file descriptor namespace in the global file system name- space. The conventional mount point is /dev/fd. We follow instructions above and permanently mount it.
# nano /etc/fstab
Add the following.
fdescfs /dev/fd fdescfs rw 0 0
# reboot
I have had some DNS problems within the jails. if this happens to you the way i fixed it is.
Within the jail:
# ee /etc/resolv.conf
make sure your name server is correct ‘nameserver 192.168.0.2′ our whatever you set.
Step Five.
Media Servers
I will be installing both Plex and Emby, I feel they are the two of the best, there are others and can be adapted to this procecs. You can decide if you wish to run one or both. Both have free versions and require a license for full features but are very reasonable priced and offer lifetime licenses.
- Plex vs. Emby: Side-by-Side Comparison
The first Jail we will create will hold our plex media server. Plex is your destination to stream TV shows, movies, and sports. Find great movies to watch and stream all your personal media libraries on every device.
Create a Jail change the ip addresses to match your network
# iocage create -r 13.2-RELEASE -n plex ip4_addr="vnet0|192.168.0.71/24" defaultrouter="192.168.0.2" vnet="on" boot="on" allow_raw_sockets="1" ip6="inherit" allow_mlock="on"
Now we login to our jail using the iocage console to install plex media server. The iocage console will log you in as root user.
# iocage console plex # pkg update # pkg install plexmediaserver-plexpass # sysrc plexmediaserver_plexpass_enable=YES # exit
We need to create links to our media files so that the jail can access our media files. We do this by editing our fstab file. First we create the directory in the jail.
# mkdir /mnt/media/iocage/jails/plex/root/mnt/movies # mkdir /mnt/media/iocage/jails/plex/root/mnt/tvshows
Next add the following to our fstab file in order to link to our media directorys.
# iocage stop plex # setenv EDITOR /usr/local/bin/nano # iocage fstab -e plex
/mnt/media/media/tvshows /mnt/media/iocage/jails/plex/root/mnt/tvshows/ nullfs ro 0 0 /mnt/media/media/movies /mnt/media/iocage/jails/plex/root/mnt/movies/ nullfs ro 0 0
# iocage start plex
Then Open a web browser and go to http://192.168.0.71:32400 or what ever you set it to, then complete setup.
Next We will install Emby. Again we create a jail to house our server.
# iocage create -r 13.2-RELEASE -n emby-server ip4_addr="vnet0|192.168.0.72/24" defaultrouter="192.168.0.2" vnet="on" boot="on" allow_raw_sockets="1" ip6="inherit" allow_mlock="on"
Now we can login and install emby server.
# iocage console emby-server # pkg update # pkg install libass fontconfig freetype2 mbedtls fribidi gnutls iconv opus sqlite3 libtheora libva ocl-icd libvorbis webp libzvbi libraw ImageMagick6 tesseract intel-media-sdk libunwind libinotify openssl icu krb5 libexif libjxl libheif libimagequant openexr openjpeg orc pango tiff # pkg install emby-server # sysrc emby_server_enable="YES" # service emby-server start # exit
Agian We need to create links to our media.
# iocage stop emby-server # mkdir /mnt/media/iocage/jails/emby-server/root/mnt/movies # mkdir /mnt/media/iocage/jails/emby-server/root/mnt/tvshows # setenv EDITOR /usr/local/bin/nano # iocage fstab -e emby-server
/mnt/media/media/tvshows /mnt/media/iocage/jails/emby-server/root/mnt/tvshows/ nullfs ro 0 0 /mnt/media/media/movies /mnt/media/iocage/jails/emby-server/root/mnt/movies/ nullfs ro 0 0
# iocage start emby-server
Then Open a web browser and go to http://192.168.0.72:8096 or what ever you set it to, then complete setup.
Step Six.
Next we will be intalling Transmission – A Fast, Easy and Free Bittorrent Client. Again within a jail.
# iocage create -r 13.2-RELEASE -n trans ip4_addr="vnet0|192.168.0.73/24" defaultrouter="192.168.0.2" vnet="on" boot="on" allow_raw_sockets="1"
Next login and install.
# iocage console trans # pkg install nano # pkg install transmission-daemon transmission-cli transmission-web # echo 'transmission_enable="YES"' >> /etc/rc.conf # service transmission start # service transmission stop # nano /usr/local/etc/transmission/home/settings.json
Modify the following line to allow access from any computer on your LAN to access the transmission WEB UI:
“rpc-whitelist”:”127.0.0.1″, to
“rpc-whitelist”:”127.0.0.1,192.168.0.*”,
# exit
Next Link our data folders.
# iocage stop trans # setenv EDITOR /usr/local/bin/nano # iocage fstab -e trans
/mnt/media/media/downloads /mnt/media/iocage/jails/trans/root/usr/local/etc/transmission/home/downloads/ nullfs rw 0 0
# iocage start trans
Open a web browser and go to http://192.168.0.73:9091/transmission/web/ or what you set.
Step Seven.
The last item that we will be installing in a jail is a reverse proxy for added security. I will be using the Nginx web server that can be used as a reverse proxy, load balancer, mail proxy and HTTP cache. Again we start with the creation of our jail.
# iocage create -r 13.2-RELEASE -n proxy ip4_addr="vnet0|192.168.0.74/24" defaultrouter="192.168.0.2" vnet="on" boot="on" allow_raw_sockets="1"
Login and install.
# iocage console plex # pkg update # pkg install nano nginx # echo 'nginx_enable="YES"' >> /etc/rc.conf # service nginx start # nano /usr/local/etc/nginx/nginx.conf
add the following servers
server { listen 80; listen [::]:80; server_name plex.example.xyz; location / { proxy_pass http://192.168.0.71:32400/; } } server { listen 80; listen [::]:80; server_name emby.example.xyz; location / { proxy_pass http://192.168.0.72:8096/; } }
This will allow us to acess our media over the internet. Now restart nginx for the changes to take affect.
# service nginx restart
Step Eight.
The next service we are going to install is Samba. Samba is a free software re-implementation of the SMB networking protocol, and was originally developed by Andrew Tridgell. Samba provides file and print services for various Microsoft Windows clients and can integrate with a Microsoft Windows Server domain, either as a Domain Controller (DC) or as a domain member. As of version 4, it supports Active Directory and Microsoft Windows NT domains.
Unlike the previous services this will not be installed in a jail but on the host OS. We first make a few settings changes.
# nano /etc/sysctl.conf
kern.maxfiles=25600
kern.maxfilesperproc=16384
net.inet.tcp.sendspace=65536
net.inet.tcp.recvspace=65536
# nano /boot/loader.conf
aio_load=”YES”
# reboot
Now we can install and configure Samba
# pkg search samba # pkg install samba416 # nano /usr/local/etc/smb4.conf
[global]
security = user
passdb backend = tdbsam
workgroup = WORKGROUP
server string = Samba Server Version %v
netbios name = media
wins support = true
server role = standalone
default = global
local master = no
prefered master = no
os level = 0
[downloads]
path = /mnt/media/media/downloads
valid users = myuser
writable = yes
browsable = yes
read only = no
guest ok = no
public = no
create mask = 0666
directory mask = 0755
[Movies]
path = /mnt/media/media/movies
valid users = myuser
writable = yes
browsable = yes
read only = no
guest ok = no
public = no
create mask = 0666
directory mask = 0755
[tvshows]
path = /mnt/media/media/tvshows
valid users = myuser
writable = yes
browsable = yes
read only = no
guest ok = no
public = no
create mask = 0666
directory mask = 0755
# nano /etc/inetd.conf
Uncomment the following.
netbios-ssn stream tcp nowait root /usr/local/sbin/smbd smbd
netbios-ns dgram udp wait root /usr/local/sbin/nmbd nmbd
swat stream tcp nowait/400 root /usr/local/sbin/swat swat
# sysrc samba_server_enable=YES # service samba_server start # pdbedit -a -u myuser # echo 'winbindd_enable="YES"' >> /etc/rc.conf # reboot
Step Nine.
Next We will be installing Nut because all good servers should have a UPS – Uninterruptible Power Supply. This is what will control it.
# pkg install nut # echo "nut_enable="YES"" >> /etc/rc.conf # echo "nut_upslog_enable="YES"" >> /etc/rc.conf # echo "nut_upsmon_enable="YES"" >> /etc/rc.conf # cd /usr/local/etc/nut # cp ups.conf.sample ups.conf # nano ups.conf
Edit this ups.conf and modify it as below:
[ups_one]
driver = usbhid-ups
port = AUTO
Step Ten.
Last we are going to istall Webmin a web-based system administration tool for Unix-like servers.
# pkg install webmin
After installing Webmin for the first time you should perform the following
steps as root: * Configure Webmin by running
# /usr/local/lib/webmin/setup.sh # echo "webmin_enable="YES"" >> /etc/rc.conf
* Start Webmin for the first time by running
# service webmin start
Now it can be accessed at your servers ip address http://192.168.0.70:10000 or what ever you set it as. That I think are the major services required for a home NAS. Any suggestions are welcome.
[robo-gallery id=”1700″]
I was just as enthralled by your work as I was. Your sketch is stylish, and your written content is accurate. Although you are concerned about possibly distributing something illicit soon, I am confident that you will address this problem swiftly and return to your normal high ideals.