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:


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 14.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.

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
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.


8.8.8.8, 8.8.4.4 is Google’s DNS Server, 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 8.8.8.8 8.8.4.4
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
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

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)

Or Mount a Single Drive instead
sudo mkdir /mnt/disk1
sudo chown -hR $(whoami):$(whoami) /mnt/disk1
sudo blkid

Take a note of the ID number for the drive you would like to mount

sudo nano /etc/fstab

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

UUID="ID From blkid" /mnt/disk1    ext4 rw,user,auto 0    0 
Create Shared Folders

Note: for the remainder of the document I refer to the mounted drive as "raidmount", but this doesn’t mean it has to be a RAID

cd /mnt/raidmount
sudo mkdir Folder1
sudo mkdir Folder2
sudo mkdir Folder3...

Depending how you would like Samba / SMB shares to be accessed you have two choices:

  1. Read/Write Access for one user, and Read Only Access for everyone else
  2. Read/Write Access for everyone

1. Read/Write Access for one user:

sudo chown user:user Folder1/
sudo chown user:user Folder2/

2. Read/Write Access for everyone:

sudo chmod a=rw -R /mnt/raidmount
sudo chown nobody:nogroup Folder1/
sudo chown nobody:nogroup Folder2/
Setup NFS Shares

NFS Shares is covered under a seperate tutorial: How to Setup NFS in Ubuntu

Setup Samba Shares

Backup old Config File:

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old

Example smb.conf file can be found below:
Use Webmin > Servers > Samba Windows File Sharing > Edit Config File, to copy and paste example Config file into.

Click "Restart Samba Servers" button after editing Config file

#Example smb.conf file
#======================= Global Settings =======================

[global]
    log file = /var/log/samba/log.%m
    load printers = no
    passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
    obey pam restrictions = yes
    null passwords = yes
    map to guest = Bad User
    encrypt passwords = yes
    passdb backend = tdbsam
    passwd program = /usr/bin/passwd %u
    dns proxy = no
    server string = %h server (Samba, Ubuntu)
    unix password sync = yes
    workgroup = WORKGROUP
    debug level = 1
guest account = nobody
    os level = 20
    auto services = global
    syslog = 0
    usershare allow guests = yes
    panic action = /usr/share/samba/panic-action %d
    max log size = 1000
    pam password change = yes
    use sendfile = yes
    time server = no
    wins support = no


#======================= Share Definitions =======================

[homes]
    browseable = no
    comment = Home Directories
    available = no

[Folder1]
    read list = nobody,user
    write list = user, add nobody here for passwordless read/write access
    force directory mode = 0755
    store dos attributes = no
    create mask = 0755
    hide dot files = yes
    user = nobody,user
    public = yes
    ea support = no
    inherit acls = yes
    browseable = yes
    writeable = yes
    inherit permissions = yes
    printable = no
    path = /mnt/raiddisk/Folder1
    force create mode = 0755
    comment = Folder 1
    directory mask = 0755
    valid users = nobody,user
Back