May 18, 2026 12:00 AM
NFS Server for Notes on local server
Setting Up a Raspberry Pi 4 as an NFS Server
Overview
Setting up a Raspberry Pi 4 as an NFS (Network File System) server is ideal for Linux and macOS users who require efficient file sharing. This guide covers installing Raspberry Pi OS, enabling SSH, and setting up NFS.
Parts
- Raspberry Pi 4
- MicroSD card
- Raspberry Pi Imager
Steps
#### Choosing the Right Raspberry Pi OS
For an efficient NFS server, use Raspberry Pi OS Lite (64-bit) as it is lightweight and optimized for server tasks.
- Best Option: Raspberry Pi OS Lite (64-bit) (no desktop, minimal resources used)
- Alternative: Raspberry Pi OS with Desktop (64-bit) (if a GUI is needed)
Note: Choose 64-bit unless you have older software requiring 32-bit.
#### Installing Raspberry Pi OS
1. Download Raspberry Pi Imager
- Install the official Raspberry Pi Imager on your computer.
2. Flash the SD Card
- Insert your microSD card into your computer.
- Open Raspberry Pi Imager.
- Click "Choose OS" → Select Raspberry Pi OS Lite (64-bit).
- Click "Choose Storage" → Select your SD card.
- Click "Settings" (⚙️ icon in the bottom-right corner).
#### Enable SSH and Set Username
- Enable SSH via OS Customization (Recommended)
- Set Hostname (optional, e.g., raspberrypi-nfs).
- Enable SSH → Choose "Use password authentication" (unless using SSH keys).
- Set Username & Password (prevents setup later).
- Click Save, then Write the OS to the SD card.
- Alternative: Manually Enable SSH After Flashing
- Insert the SD card into your computer.
- Navigate to the boot partition and create an empty file named
ssh: touch /boot/ssh- Eject the SD card, insert it into the Raspberry Pi, and boot it up.
#### Connect to Raspberry Pi via SSH
- Find your Raspberry Pi's IP using your router or
raspberrypi.local (mDNS).- Connect using:
ssh pi@<IP_ADDRESS>#### Setting Up the NFS Server
1. Install NFS Server
- Update the system and install NFS:
`bashsudo apt update && sudo apt upgrade -y
sudo apt install nfs-kernel-server -y
`2. Create a Shared Directory
- Set up a folder to share over the network:
`bashsudo mkdir -p /mnt/nfs_share
sudo chown nobody:nogroup /mnt/nfs_share
sudo chmod 777 /mnt/nfs_share
`3. Configure NFS Exports
- Edit the NFS configuration file:
`bashsudo nano /etc/exports
`- Add this line (adjust for your LAN subnet):
`/mnt/nfs_share 192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)
`- Save and exit (CTRL + X, then Y, then ENTER).
4. Apply Changes and Restart NFS Service
`bashsudo exportfs -a
sudo systemctl restart nfs-kernel-server
sudo systemctl enable nfs-kernel-server
`#### Mounting the NFS Share on Clients
Linux Clients
1. Install NFS support:
`bashsudo apt install nfs-common -y
`2. Create a local mount point:
`bashsudo mkdir -p /mnt/nfs_client
`3. Mount the NFS share:
`bashsudo mount -t nfs 192.168.1.X:/mnt/nfs_share /mnt/nfs_client
`- Replace
192.168.1.X with the Raspberry Pi’s IP.4. Make the mount permanent: Add this line to
/etc/fstab:`192.168.1.X:/mnt/nfs_share /mnt/nfs_client nfs defaults 0 0
`macOS Clients
1. Create a local mount point:
`bashsudo mkdir -p /mnt/nfs_client
`2. Mount the NFS share:
`bashsudo mount -t nfs -o vers=4 192.168.1.X:/mnt/nfs_share /mnt/nfs_client
`3. Make the mount persistent: Edit
/etc/auto_nfs and add:`/mnt/nfs_client -fstype=nfs,resvport,vers=4 192.168.1.X:/mnt/nfs_share
`- Then update AutoFS:
`bashsudo automount -vc
`Notes
- Your Raspberry Pi 4 is now a fully functional NFS server, providing fast and efficient file sharing for Linux and macOS devices.
- If you run into any issues, check logs using:
`bashsudo journalctl -xe
`