Making a Home NAS

In my last post I talked about the Odroid-XU4 as my favourite single board computer (SBC). In this post I will will walk you through the steps I performed to create a Home NAS.

Before I set up the NAS, I had to think about how I really wanted to use it. Primarily, it was going to be a location to share files with everyone in the home. In my case it was photos and music. But, I also wanted to have some sort of back up for all the computers in the home. This lead me to have a single sign-on for the NAS. I created a user called ‘odroidnas’ and gave it a secure password. I did not add this user to list of sudo users because I did not want my teenage son to mess around with the Odroid.

sudo adduser odroidnas

I then made sure my version of Samba (our file sharing software) was up to date.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install samba samba-common-bin

Then it was time to add the 4TB external drive that would become our NAS. I picked up a 4TB portable Seagate drive at BestBuy when it was on sale for about C$100. I prefer the portable drives since they do not need to be plugged into a power outlet. They get the power from the USB connection.

I was not sure if the Odroid was going to be able to power multiple drives, that is why I added a 4 port powered USB 3.0 hub to the Odroid. Here is the one I am using from Amazon. In the end, I ended up adding three 4TB drives to my Odroid.

After plugging in the drive, it was time to make sure it mounted and started sharing when the Odroid was started/restarted.

First I wanted to make sure the drive could be read by Windows PC’s attaching to it. I added the ability to read and write Windows formatted (NTFS) drives to the Odroid.

sudo apt-get install ntfs-3g

I then made sure the drive was mounted.

sudo mount -a

Then I create a mount point for the external drive and give it the correct permissions so that the user ‘odroidnas’ can read and write to the disk. Some readers might not like giving a directory full read/write privileges, but this is a NAS inside my home for the whole family to use, so I was comfortable using ‘775’ when setting up the privileges.

sudo mkdir /mnt/nas
sudo chown -R odroidnas:odroidnas /mnt/nas
sudo chmod -R 775 /mnt/nas

Then it was time to find the unique identifier for the portable drive.

ls -l /dev/disk/by-uuid

Then I need to make sure the drive mounts in the same location every time the device reboots. Fstab is used to mount drives in Linux.

sudo nano /etc/fstab

Then add the following line to fstab:

PARTUUID=unique identifier from above /mnt/nas ntfs-3g defaults,nofail 0 0

To test if this works I rebooted the Odroid.

sudo reboot now

After rebooting, I checked to see if the drive mounted.

df -h

In my case, after it rebooted the drive was found at /mnt/nas. However, some drives are slow to mount and may not appear in the list. There is a workaround:

sudo nano /etc/rc.local

Then you can add the following lines before end ‘end 0’:

sleep 20
mount -a

If you are like me and find the flashing blue light of the Odroid annoying, you can also add this line after ‘mount -a‘ to keep it from flashing.

echo none > /sys/class/leds/blue\:heartbeat/trigger

Now it is time to set up the Samba. Open the Samba configuration file:

sudo nano /etc/samba/smb.conf

Then add the following (you can customise the name):

[OdroidNAS]
comment=Home NAS on Odroid
path=/mnt/nas
create mask=0777
directory mask=0777
writeable=yes
public=no
guest ok=no
browseable = yes
force user = odroidnas

Give the user ‘odroidnas’ access to the Samba server by first giving it a password. In my case, I used the same password as when I set up the ‘odroidnas’ user above.

sudo smbpasswd -a odroidnas

Then restart the Samba server.

sudo service smbd restart

We now have a server, but we need to tell our laptop and desktop PC’s how to talk to it. First we need to know the IP address of the server. If you are like me, you want it to be static. I went into my home router and reserved the IP address of the Odroid so that it would have the same IP every time. You can check the IP address by using the command:

ip addr show

Connecting a Mac:

    1. Command + k to bring up the ‘Connect to Server’ dialogue box.
    2. Enter the pathway: smb://192.168.x.x/OdroidNAS
    3. Enter the username (odroidnas) and password
    4. Done!
    5. Bonus: you can also click the ‘+’ button to remember the server.

On a PC, here are the steps:

    1. Open File Explorer from the taskbar or the Start menu
    2. Select This PC from the left pane. Then, on the Computer tab, select Map network drive. Map a network drive in File Explorer
    3. In the Drive list, select a drive letter. (Any available letter will do.)
    4. In the Folder box, type the path of the folder or computer, \\192.168.x.x\OdroidNAS
    5. To connect every time you log on to your PC, select the Reconnect at sign-in check box.
    6. Also check Connect Using Different Credentials, enter the user ‘odroidnas’ and the password.
    7. Select Finish.

You now have a NAS that anyone in the home can use to store and share files. This is really important to me since my laptop has a small solid state drive but I can now access my photo collection easily on my NAS.

Next time I will share my backup strategy for my laptops, desktops, and NAS.

[There a many guides on the Internet. This is my implementation created from information on a variety of sites. A great site to check out is PiMyLifeUp. I would also like to thank Andrew Dobbie for his interest in my experimentation with my Odroid.]

The Odroid-XU4

My newest (and favourite) Single Board Computer (SBC) is the Odroid-XU4. This device is quite beefy when it comes to specs:

    • Samsung Exynos5422 Cortex™-A15 2Ghz and Cortex™-A7 Octa core CPUs
    • Mali-T628 MP6(OpenGL ES 3.1/2.0/1.1 and OpenCL 1.2 Full profile)
    • 2Gbyte LPDDR3 RAM PoP stacked
    • eMMC5.0 HS400 Flash Storage
    • 2 x USB 3.0 Host, 1 x USB 2.0 Host
    • Gigabit Ethernet port
    • HDMI 1.4a for display
    • Size : 83 x 58 x 20 mm approx.(excluding cooler)
    • Power: 5V/4A input
    • Linux Kernel 4.14 LTS

The reason I went with this instead of the Raspberry Pi 3 was because it has 8 cores, Gigabit Ethernet, and USB 3.0. This made it the ideal platform to create a home Network Attached Storage (NAS) Device. Also, being only US$49 it was priced right.

As I mentioned it has 8 cores and it is considerably faster than the Raspberry Pi. Take a look at the Odroid website for comparison charts.

Once I received it in the mail (it was shipped from China), I flashed the the 32GB eMMC drive with Ubuntu 18.04. Hooked up a keyboard, mouse, Ethernet, and monitor and turned it on. It booted right up. Then the first few commands to get it up to date:

sudo apt-get update

sudo apt-get upgrade 

sudo apt-get dist-upgrade

Then I added a new user (newusername), gave it a good password, and then gave it sudo privileges:

adduser newusername
usermod -aG sudo newusername

Then I turned on SSH so I can work with it remotely. In other words, I like to put it someplace out of sight and use my laptop to access the device remotely. You might have to first install the SSH server:

sudo apt-get install openssh-server

Open the SSH config file to prevent root login as a type of basic security:

sudo nano /etc/ssh/sshd_config

Then change the following line from yes to no

PermitRootLogin no

Restart the ssh server

sudo service ssh restart

Get the IP address or assign it an IP address in your router. I chose to assign the device an IP address so it doesn’t change on me. Check the IP address with the command. It will be something like 192.168.x.x :

ip addr show

At this point I normally remove the keyboard, mouse, and monitor. I then move the device to its intended location (a closet or shelf where it will function as a NAS) and reboot it.

You can then use Secure Shell in Chrome to log into the device. Since we are preventing root from login in, we must use our newusername and password to connect to the device.

Now we have a functioning server that we can access from anywhere in the house. Next time I will explain how to set up the NAS.

Plex Media Server on a Raspberry Pi 3

It has been a while since I wrote up a “how-to” for the Raspberry Pi and I thought I would share my latest project with you. I purchased a Raspberry Pi 3B+ to replace my RPi 2 as a media server. In case you are new to the Raspberry Pi. Here are the specs for the 3B+:

  • SOC: Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC
  • CPU: 1.4GHz 64-bit quad-core ARM Cortex-A53 CPU
  • RAM: 1GB LPDDR2 SDRAM
  • WIFI: Dual-band 802.11ac wireless LAN (2.4GHz and 5GHz ) and Bluetooth 4.2
  • Ethernet: Gigabit Ethernet over USB 2.0 (max 300 Mbps). Power-over-
  • Ethernet support (with separate PoE HAT). Improved PXE network and USB mass-storage booting.
  • Thermal management: Yes
  • Video: Yes – VideoCore IV 3D. Full-size HDMI
  • Audio: Yes
  • USB 2.0: 4 ports
  • GPIO: 40-pin
  • Power: 5V/2.5A DC power input
  • Operating system support: Linux and Unix

I have tried and tested many tutorials that I have found online, but this Medium post from Niha M is fantastic, Plex Media Server on Raspberry Pi 3 using Raspbian Lite (Stretch).

I followed all of Niha’s instructions but I had the following modifications:

  1. I am using a wired gigabit network and will not be using Wifi.
  2. I reserved a static IP address through DHCP reservation in my router.
  3. I left the metadata on the SD card.
  4. I attached a 2GB HDD and set up the SAMBA share to make it easier to transfer video, audio, and pictures from my laptop to the server.

I additionally set up a backup script for the SD card since I have had them go bad in the past. I followed the instructions from GrammatonCleric on the Ubuntu Forums.

What I did:
Filled the SD card with zeros because when I compress the image it will shrink down considerably.

dd if=/dev/zero of=/tmp/disk_zero_fill.tmp bs=8M; rm -f/tmp/disk_zero_fill.tmp

I then copied the entire drive to an image and compressed it, by creating an executable script.

bakup_sdcard.sh

##################################
# set date variable 
################################## 

tdy=`date +%m%d%Y`  

################################## 
# Remove img.gz files older than 21 days 
################################## 

find /path/to/usbdrive/pi_image_bkup.*.img.gz -type f -mtime +21 exec rm {} \;  

################################## 
# consider zeroing unused space before imaging. 
# remove # in front of line below enable this function 
# this step it will reduce the lifespan of the SD card 
################################## 

# dd if=/dev/zero of=/dev/mmcblk0/disk_zero_fill.tmp bs=8M; rm -f /dev/mmcblk0/disk_zero_fill.tmp 

##################################
# image server to new location
##################################

dd bs=8M if=/dev/mmcblk0 conv=sync,noerror | "gzip > /path/to/usbdrive/pi_image_bkup.$tdy.img.gz

I automated the script to backup once a week by adding a Cron Job that runs on Sundays at 2AM.

0 2 * * 0 /path/to/script/bakup_sdcard.sh > /dev/null 2>&1

Now if the SD card goes bad; I can ungzip the latest image on the HDD and burn it to a new SD card and not have to rebuild the Plex server. I have also backed up all my media to a second external drive (just in case).

Bonus: My clean-up script that I run once a week.

echo "Cleaning Up" && 
sudo apt-get update && 
sudo apt-get -y upgrade && 
sudo apt-get -f install && 
sudo apt-get autoremove && 
sudo apt-get -y autoclean && 
sudo apt-get -y clean && 
sudo find /var/log/ -type f -regex '.*\.[0-9]+\.gz$' -delete

Finding a Domain for Your Site

I have a bad habit of buying Internet domains whenever I get a million dollar idea, and then promptly forget to develop them. I just looked, I currently have 18 domains and I am only using a few of them. Most are redirects, like carlofusco.com and fusco.xyz which redirect to fusco.ca, but most are just parked for when I have the time and energy to develop them.

The original reason I registered a domain back in 2004 was to have a custom, easy to type URL for my students. I also set up my first classroom website when I registered my domain. Students found it useful and easy to get to.

It has gotten a lot easier to register a domain and have a web presence today. For example, when you register a domain, you don’t have to set up a server or design a website. You can have the domain redirect to something you are already using. For example, you could register ‘teacher.ca’ and have it redirect to your Google Classroom or any other site you have set up for you and your students.

I have found the easiest way to get yourself a domain is to use Hover.com. They provide the easiest to use interface and some of the best customer support available. Not only that, they are a Canadian company that are owned by Tucows. A company you might remember as the place to download software back in the early days of the Internet.

There are other reasons to use Hover. They can migrate domains you already own to their service, they provide free Whois privacy (so your personal information does not end up in the Whois database), easy to use interface, and you can add two-factor authentication to your account.

What you do with your domain is entirely up to you. It is only limited by your creativity and what you hope to achieve. Below are some of the sites I currently have:

Note: I am not affiliated with Hover, I am just a happy customer.

Finding a Virtual Private Server

From 2004 to 2014, I was using a shared hosting service for my personal domain (fusco.ca) which cost me about C$4/month. It was a great way to get your site up and running and it was really easy to manage. However, as the popularity of the Internet grew and everyone was looking for a place to host their website, I found these shared hosting services became very crowded. This caused my site to slow down dramatically.

If you are using a shared hosting service, check out www.ip-neighbors.com to see how many websites are sharing your IP address and possibly your server. One of the reasons my site slowed down, was because there were a couple of adult sites sharing my IP address and they were using the majority of the server’s resources.

In 2014, I decided to migrate my site to a new server. I had discovered VPS’s (Virtual Private Servers). The difference with this hosting service is that you get to control the Operating System and customize the service to suit your needs. You do share the server hardware with other users but everyone has their own IP address and block of space on the server. They are considerably less crowded than shared hosting.

While looking for a VPS, I came across the site LowEndBox which is like a clearing house for VPS’s. I stumbled onto a great “Black Friday” deal for a VPS with a quad core cpu, 2 GB ram, 30 GB SSD, and a 1 Gbit Internet connection for just US$20/year. The offers are always changing so keep an eye out.

After I found a VPS, I had to learn about administrating it. The first thing I did was install Ubuntu Server LTS as the OS, using much of the advice from this DigitalOcean tutorial. I also found tutorials on setting up a firewall , adding additional security to protect my server, and setting up my LAMP stack to host my site.

The great thing about DigitalOcean is that they have tutorials for a wide variety of OS’s and can guide you through anything you want to do with your server. For example, I followed this guide on Virtual Hosts to host multiple domains on my VPS.

That is it for now, next time I will share how to get a domain and have it connect to your new VPS.