Lab 15: Advanced Storage — NFS & Quotas

Time: 40 minutes | Level: Advanced | Docker: docker run -it --rm --privileged ubuntu:22.04 bash

NFS (Network File System) enables sharing directories over a network. Disk quotas enforce per-user or per-group storage limits. Together, they form the backbone of multi-user Linux storage management.


Prerequisites

docker run -it --rm --privileged ubuntu:22.04 bash
apt-get update -qq && apt-get install -y nfs-kernel-server nfs-common quota rsync

Step 1: Set Up NFS Server

# Create directories to export
mkdir -p /srv/nfs/public
mkdir -p /srv/nfs/private
chmod 755 /srv/nfs/public
chmod 700 /srv/nfs/private

# Add content
echo "NFS shared file" > /srv/nfs/public/readme.txt
echo "Private data" > /srv/nfs/private/secret.txt

echo "NFS directories created:"
ls -la /srv/nfs/

📸 Verified Output:

💡 NFS security is based on IP/hostname — use firewall rules to restrict access. Never export sensitive paths to *(rw) on a public network!


Step 2: Configure /etc/exports

📸 Verified Output:

Export options explained:

Option
Meaning

rw

Read-write access

ro

Read-only access

sync

Write to disk before acknowledging client

async

Faster but risks data loss on crash

no_subtree_check

Skip subtree permission checks (improves reliability)

root_squash

Map remote root to nobody (default, safer)

no_root_squash

Allow remote root to act as local root


Step 3: Export and View NFS Shares

📸 Verified Output:

💡 exportfs -r reloads /etc/exports without restarting the NFS server — use this when changing exports in production.


Step 4: NFS Client Mount (Simulated)

In a full environment, you'd mount from another host. Here we simulate localhost NFS:

📸 Verified Output:

💡 The _netdev fstab option ensures the NFS mount is only attempted after the network is up — critical for preventing boot failures.


Step 5: Set Up Disk Quotas

Quotas require a filesystem mounted with quota options. Let's create one:

📸 Verified Output:


Step 6: Enable and Configure Quotas

📸 Verified Output:

💡 Soft limit = warning threshold (grace period applies). Hard limit = absolute maximum — writes are rejected when reached.


Step 7: repquota and edquota

📸 Verified Output:

💡 Grace period (default 7 days) gives users time to clean up after exceeding the soft limit before the hard limit enforcement kicks in.


Step 8: Capstone — rsync Backup of NFS Share

Scenario: Automate daily backups of the NFS share to a local archive, with quota monitoring.

📸 Verified Output:


Summary

NFS Commands

Command
Purpose

exportfs -a

Apply /etc/exports

exportfs -r

Reload exports

exportfs -v

Show active exports

exportfs -u /path

Unexport a directory

mount nfshost:/path /mnt

Mount NFS share

showmount -e nfshost

List server exports

Quota Commands

Command
Purpose

quotacheck -cugm /mnt

Initialize quota database

quotaon /mnt

Enable quota enforcement

quotaoff /mnt

Disable quota enforcement

setquota -u user soft hard sinodes hinodes /mnt

Set user quota

repquota /mnt

Report all user quotas

quota -u username

Show single user quota

edquota -u username

Edit quota interactively

rsync Key Flags

Flag
Meaning

-a

Archive (recursive + preserve all metadata)

--delete

Mirror: delete files removed from source

--exclude='pattern'

Skip matching files

--link-dest=DIR

Hard-link unchanged files (space-efficient incremental)

-n / --dry-run

Simulate without making changes

Last updated