QuidsUp - Creating a NAS with Ubuntu Server

Creating a NAS with Ubuntu Server

This tutorial guide will explains how to create a Network Attached Storage (NAS) system with Ubuntu Server and MDADM software RAID; and how to create Samba and NFS shares.
Use this guide along with my Youtube Video: How to Create a NAS with Ubuntu Server

Items Required:
  • Wired Network Connection
  • Small USB Flash drive (or CD) to install the OS
  • 8GB (Minimum) Flash drive to run the OS / or Small SSD
  • A couple of spare hours

Hardware Requirements

A NAS device can be created with minimal hardware, such as: Single core 1.0GHz CPU, 512 MB RAM, 160GB Hard Drive, and a USB 2.0 Flash drive.


My NAS

For my NAS I’m using: AMD Sempron 3850 AM1 1.3GHz Quad Core CPU, ASUS AM1M-A Motherboard, 8GB DDR3 RAM, 4x 3TB Seagate hard drives, and a SanDisk SATA 2 32GB for the Ubuntu Server 18.04 OS.
The system is running with RAID5, giving me a single 9TB drive mounted in /mnt. It has SMB shares setup, which allows shared access for all devices (computers, media player, and Android tablet) on my LAN.
I’m also using the system as a Media Downloader to download files from Usenet.

Majority of user interaction is done via Web GUI, although there’s remote access terminal available via SSH. Since everything can be done remotely over the network the NAS sits there running as a headless server (no keyboard or monitor connected).

I used to run the system from a USB 3.0 Flash drive, but I found that it would sometimes break Grub when the kernel was updated. Long term it has been a lot easier to run the OS from a cheap Solid State Disk.

2. Installing Ubuntu Server

Download Ubuntu Server ISO from: http://www.ubuntu.com/download/server
Either write the ISO file to small USB Flash drive or CD

We are going to install the operating system to a USB Flash drive, this makes it easier to use the hard drives in a RAID array and keep the OS separate from data storage. Ubuntu Server is light enough to run on a Flash drive, and with enough RAM theres no appreciable delay in using the NAS.
It's certainly a cheaper alternative than installing the OS on a Solid State Disk, however for a permanent solution I would recommend installing the OS on a small SSD.

Disconnect all hard drives and then install the Server OS onto the Flash drive. (Skip this step if you're installing the OS to a hard drive or SSD)

Near the end of the install, the installer asks you which components you would like to add, choose SSH Server, and Samba from the list.

Shutdown the computer, reconnect all hard drives, and then switch back on.

If all being well the system will boot up and you will see a login screen.
Login with your Username and Password that you set during the install.

Check for updates

Before we get too far, its worth installing updates.

sudo apt-get update
sudo apt-get dist-upgrade
sudo reboot

3. Network Setup

Set Static IP Address

We will be accessing the NAS from other computers, therefore we need to know what the IP address is. One way is to set a Static IP address.

Alternative option, if you have control over your DHCP server you could assign an IP based on MAC address. Use ifconfig to obtain details of the MAC address.

1.1.1.1 and 1.0.0.1 is a DNS resolver operated by Cloudflare, I find this a lot better than my ISP’s DNS Server.

sudo nano /etc/network/interfaces

iface eth0 inet static
	address 192.168.1.100
	network 192.168.1.0
	netmask 255.255.255.0
	broadcast 192.168.1.255
	gateway 192.168.1.1
	dns-nameservers 1.1.1.1 1.0.0.1
Add NAS IP Address to your Local DNS Lookup

This is for any Linux computer that you would like to access the NAS from.

echo -e "192.168.1.100\t nas.local" | sudo tee -a /etc/hosts

\t represents tab character
tee -a appends line to file

The NAS can be accessed via SSH with the following terminal command:

ssh [email protected]

Or if you're using the same username on both systems:

ssh nas.local

4. Setup RAID

Install MDADM RAID Controller

Optional step if using Software based RAID.

sudo apt-get --no-install-recommends install mdadm
Install Webmin

Webmin is a web based administration tool, which allows you to carry out various admin tasks on a server.

echo "deb http://download.webmin.com/download/repository sarge contrib" | sudo tee /etc/apt/sources.list.d/webmin.list
cd ~/
wget http://www.webmin.com/jcameron-key.asc
sudo apt-key add jcameron-key.asc
rm jcameron-key.asc
sudo apt-get update
sudo apt-get install libapt-pkg-perl libnet-ssleay-perl libauthen-pam-perl libio-pty-perl apt-show-versions
sudo apt-get install webmin
sudo reboot
Setup MDADM RAID

Video tutorial guide: How to Create an Mdadm Raid using Webmin in Ubuntu Server

Create folder to mount the raid:

sudo mkdir /mnt/raidmount

Open browser and navigate to: https://nas.local:10000

  • Create and mount RAID via Webmin RAID setup utility.
  • Setup a mount point for the RAID as /mnt/raidmount
(It took approximately 36 hours to create a 9TB RAID5 array on my system, but the RAID was full usable, albeit slightly slower than normal, for the duration)

5. Setup JBOD (Just A Bunch of Disks)

Create a mounting folder and take ownership:

sudo mkdir /mnt/disk1
sudo chown -hR $(whoami):$(whoami) /mnt/disk1
sudo mkdir /mnt/disk2
sudo chown -hR $(whoami):$(whoami) /mnt/disk2

Get the UUID of the drive(s) you wish to mount:

sudo blkid
/dev/sdb1: LABEL="Data1" UUID="48991511-fce2-4195-8e12-e0ec45ecfb9d" TYPE="ext4" PARTUUID="1eab1357-b163-1f1d-b448-4ada7c8863fe"
/dev/sdc1: LABEL="Data2" UUID="41599175-d52e-42b3-9caf-7cb11e46a91f" TYPE="ext4" PARTUUID="b8eb2d1d-6d19-42a4-ba5c-4ada7c8863fe"

Take a note of the UUID number for the drive(s) you would like to mount:

sudo nano /etc/fstab

Add the following lines to the end of /etc/fstab

UUID="48991511-fce2-4195-8e12-e0ec45ecfb9d"	/mnt/disk1	ext4 rw,user,auto	0	2
UUID="41599175-d52e-42b3-9caf-7cb11e46a91f"	/mnt/disk2	ext4 rw,user,auto	0	2

6. Share The Drives

What would the use of a NAS be without the drives shared to other computers...
We have a couple of options of making the drives accessible to other computers: NFS and Samba.

NFS (Network File System) is used with Unix operating systems such as Linux and Apple macOS. Skip this step if you only want to share with Microsoft Windows-based computers.

Samba (or SMB/CIFS) is used with Microsoft Windows, but can also be understood by Linux and Android phones.

7. NFS

Install dependencies:

sudo apt install nfs-kernel-server
Export the drive folders

NFS will only export specified folders to a certain network range when they‘re added to /etc/exports:

sudo nano /etc/exports

Add the following to the end of the exports file:
Note: Use tab instead of space between the folder and IP address

/mnt/disk1	192.168.1.0/24(rw,sync,root_squash,subtree_check)
/mnt/disk2	192.168.1.0/24(rw,sync,root_squash,subtree_check)
/mnt/raidmount	192.168.1.0/24(rw,sync,root_squash,subtree_check)
Restart NFS
sudo service nfs-server restart

Please see this NFS Setup Tutorial for further information on NFS setup and what you need to add to the /etc/fstab file on your other client systems.

8. Samba

Install dependencies:

sudo apt install samba samba-common-bin
Setup Network Shares

Edit the Samba config:

sudo nano /etc/samba/smb.conf

Add the following to the end of the smb.conf file:

[mynas]
	comment = Samba on My NAS
	path = /mnt/
	read only = no
	browsable = yes

This creates a share called “mynas” allowing access to all the drives mounted under the /mnt folder.
Read-only is set to no, which permits modifying and writing data to the share.
Browsable allows the share to be seen by a Linux file manager or Windows Explorer.

Add user account to access the Samba share

Since Samba doesn’t use the system account password, we need to set up a Samba password for our user account:
You can also specify a different username, although it must exist on the system.

sudo smbpasswd -a $(whoami)
sudo smbpasswd -a anotheruser
Restart Samba
sudo service smbd restart
Connect to the Share

You can now connect to the share using \\IP address of NAS from Windows Explorer.

Or smb://IP address of NAS from a Linux file manager.