Home NAS Setup
Post
Cancel

NAS Setup

A network attached storage (NAS) device is an extremely conveniant utility to have in your envoronment and makes a very efficient and useful central location for storage of resources of all kinds. It will act as a server for other clients on the network that can use the NAS to store and retrieve files.

The main use case for us is to have a central location to store VM images and disks for our Proxmox virtualization datacenter. With this implementation using a network file system server we will only need to upload .iso files once and then be able to boot from them on any node in the cluster.

Hardware Configuration

The preferred hardware configuration for this kind of setup would be a server with as many large drives as possible and two small small drives for the OS installation. The drives for the OS should be set up in a RAID 1 configuration and the storage dives should be set up in a RAID 5 configuration.

Ubuntu Server Install

To set up the NAS we first need to install an operating system. We’ve chosen to use Ubuntu server 20.04, but you can easily set up an NFS server with any standard linux server distribution.

Flash a usb drive with the .iso of your choice using either Rufus or Etcher and then boot from it and follow the install process. Make sure to note the IP address of the server (you will want to set this up as a static address). You will also want to set up ssh access.

Storage Configuration

Now that you have ubuntu server installed you should ssh into it and configure the storage you want to serve out with NFS.

Partition

The first step to configuring storage for NFS is partitioning the drive you wish to use, in our case the RAID 5 configured virtual disk.

Use fdisk -l to list the drives installed on the machine, they will be of the format /dev/sdX (X being some letter). Identify the correct disk by checking the size that fdisk displays.

If there are any existing partitions you should remove them with fdisk /dev/sdX then d to delete each partition until the disk is clean, then w to write.

Now you will want to create a single partition with the parted tool. Enter:

parted /dev/sdX

mklabel gpt

unit TB

mkpart primary 0.00TB #.##TB where #.## is the size of the disk in terabytes

print to list partitions and verify correct setup

quit

Configure Filesystem

Enter mkfs.ext4 /dev/sdX1 where /dev/sdX1 is the new partition that you just created.

Mount

Make a directory where you want to mount the new filesystem with mkdir /DIRECTORY_NAME. Then, mount with mount /dev/sdX1 /DIRECTORY_NAME where /dev/sdX1 is the new partition you just made.

NFS

Install NFS with sudo apt install nfs-kernel-server

Run:

sudo chown nobody:nogroup /DIRECTORY_NAME

sudo chmod 777 /DIRECTORY_NAME

Edit the /etc/exports file by adding the line /DIRECTORY_NAME {SUBNET_IP}/{SUBNET_MASK}(rw,sync,no_subtree_check)

Run sudo exportfs -a to make the filesystem available, then sudo systemctl restart nfs-kernel-server to restart the NFS server.

Finally, run

sudo ufw allow 111

sudo ufw allow 2049

echo -e "mountd\t\t6666/tcp" | sudo tee -a /etc/services

echo -e "mountd\t\t6666/udp" | sudo tee -a /etc/services

sudo ufw allow 6666

You should now have a working NFS file server! Please note this setup is NOT SECURE and for testing only. Once you test out usage of the file server you edit the /etc/exports file so that only certain clients can access the file share and implement firewall rules so that only machines that need to access the server can.