Ultra Lightweight NAS

Storage servers are needed every where and usually several. Usually there is absolutely no need for any GUI or other stuff bloating the server. The best is a plain NFS Server - it's fast and romust.

Ultra Lightweight NAS
Photo by Pedro Vit / Unsplash

Actually, it's only a minimal OS and a NFS server running on it. The OS will run on 4 G, but we stick to 8 G (Alpine 2/4 G) for safety and larger cash. A practical Networked Storage is only a small appliance and some ZFS drives, usually Z1 RAID.

The component we will us is a Debian/Ubuntu VM/CT and ZFS for storage, NFS for fast networking (CIFS are too slow) and autofs on the Client for mounting when needed. For the smallest footprint, use Alpine.
AutoFS is not needed but convenient and have some benefits.

NFS Server installation on Debian or Ubuntu

sudo apt-get update && sudo apt-get -y install nfs-kernel-server

Check by systemctl status nfs-kernel-server , it may show a error because of nothing to share

NFS Server installation on Alpine 👌

Alpine is tiny but powerful. It's pure Linux (not bloated by GNU). It's the perfect OS for a Super Lightweight Storage Server, but requires more skills.
Login with default password root and run setup-alpine.

Install and activate the NFS Server on Alpine

apk add nfs-utils

Installation of NFS Server package

rc-update add nfs

Export directories in /etc/exports/

rc-service nfs start

Start up the NFS service on your server

QEMU-Guest-Agent on Alpine

  • Activate the community repository if not activated at setup
    needed to install the QEMU-Guest-Agent
    • install by nano /etc/apk/repositories
    • remove the # in front of the community repository line
  • add the QGA by doas apk add qemu-guest-agent
  • activate the QGA by doas rc-update add qemu-guest-agent
  • start the QGA by doas rc-service qemu-guest-agent start

Setup of the directories to export

sudo mkdir -p /exports/{backup,documents,films,music,photos}
doas mkdir /exports
cd /exports
doas mkdir backups documents films music photos

Create the configuration of the NFS Server

First, move the configuration file to a copy (sudo on deb — doas on Alpine)

sudo mv /etc/exports /etc/exports.orig

Make a copy of the original one

Create a new configuration file

sudo nano /etc/exports
# exports allowed on subnets
/exports/backup 10.10.10.0/255.255.255.0(rw,no_subtree_check)
/exports/documents 10.10.10.0/255.255.255.0(rw,no_subtree_check)
/exports/films 10.10.10.0/255.255.255.0(rw,no_subtree_check)
/exports/music 10.10.10.0/255.255.255.0(rw,no_subtree_check)
/exports/photos 10.10.10.0/255.255.255.0(rw,no_subtree_check)

You can now check the NFS server by: systemctl status nfs-kernel-server

Setup Users on the Server

Create your users by adduser <user name> and give them a password when you are prompted for one, the rest are optional. This way, you do not need to set privileges to 777.

Ad hoc mounting

For stuff, you rarely use or will use only once, you can do all mounting without the AutoFS. Let’s mount one of the shares from the server:

sudo mount 10.10.40.139:/exports/backup-old /mnt/nfs/backup-old

Run df -h to see that the export is mounted and accessible, and list the content of the directory byls -l /mnt/nfs/backup-old.

When we’re finished with a mount, we can unmount it with the umount command:

sudo umount /mnt/nfs/backup/old

On-demand mounting with AutoFS

The settings will be in /etc or /etc/autofs.

sudo apt-get update && sudo apt-get -y install nfs-common autofs

Check that it works by showmount that you can see your exported directories

showmount --exports 10.10.40.139

Create a directory for the exported directories anywhere you like. With many NFS servers, use the last octet of the server IP to keep them separated, e.g., 139. With ghost, they will disappear after a timeout of 60 seconds to avoid messy file locking.

mkdir -p /srv/nfs/139/
nano /etc/auto.master
/srv/nfs/139/ /etc/auto.nfs --ghost --timeout=60

Create the settings for the exported directories, rw is for read and write.

nano /etc/auto.nfs
backup -fstype=nfs4,rw 10.10.40.139:/exports/backup
documents -fstype=nfs4,rw 10.10.40.139:/exports/documents
films -fstype=nfs4,rw 10.10.40.139:/exports/films
music -fstype=nfs4,rw 10.10.40.139:/exports/music
photos -fstype=nfs4,rw 10.10.40.139:/exports/photos
sudo systemctl restart autofs

NFS Configuration options for Server and Client side

  • rw: Grants the client both read and write access to the directory.
  • ro: the directory may only be mounted as read only
  • sync: Forces NFS to write changes to disk before replying.
    This results in a more stable and consistent environment since the reply reflects the actual state of the remote volume.
    The negative is that it also reduces the speed of file operations.
  • async – ignores synchronization checks in favor of increased speed
  • no_subtree_check: Prevents subtree checking.
    It's a process where the host must check whether the file is still available in the exported tree for every request.
    Can cause problems if a file is renamed while the client has it opened.
    In almost all cases, it is better to disable subtree checking.
  • subtree_check – specifies that, in the case of a directory is exported instead of an entire file system, the host should verify the location of files and directories on the host file system

NFS Configuration options for Server

no_root_squash: By default, NFS translates requests from a remote root user into a non-privileged user on the server.
It was intended for security by preventing a client root account from using the file system of the host as root. no_root_squash disables this behavior for some shares.

It's an extremely dangerous option that allows remote root users
the same privilege as the root user of the host machine!

Script

You can download a basic script from my GitHub repository

wget https://github.com/nallej/MyJourney/raw/main/scripts/debInstallNFS.sh

For Debian/Ubuntu based Server installs

GUI for the NAS

Previously I used Cockpit for my Lightweight NAS. Here I recommend not to use a GUI, and if you like one use file browser. See this post how to implement file browser on an Alpine NAS.


References

Autofs [1] Network File System [2] Proxmox [3]
See also this altenative solution. A Lightweight NAS


  1. See thh autofs man page, GitHub and Arch wiki ↩︎

  2. See the NFS man page ↩︎

  3. Proxmox Performance Tweaks wiki ↩︎