HTGWA: Create an NFS share in Linux on a Raspberry Pi

This is a simple guide, part of a series I'll call 'How-To Guide Without Ads'. In it, I'm going to document how I create an NFS share in Linux on a Raspberry Pi.

Install NFS

$ sudo apt-get install -y nfs-kernel-server

Create a shared directory

$ sudo mkdir /mnt/mydrive/shared
$ sudo chmod -R 777 /mnt/mydrive/shared

I won't deal with permissions in this post; read this post for more suggestions.

Configure NFS to share that directory

Edit the NFS exports file with sudo nano /etc/exports, and add the following:

/mnt/mydrive/shared *(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)

Update the NFS active exports

sudo exportfs -ra

Connect to the share

From another computer, access: nfs://[hostname-or-ip-of-pi]/mnt/mydrive/shared

Comments

Just a note if connecting from a Mac running macOS Big Sur: I was having some trouble mounting NFS shares via the Finder, so I found the only way to get the mount to work was by running the following command in the Terminal:

sudo mount -o vers=4,resvport -t nfs xxx.xxx.xxx.xxx:/mnt/mydrive/shared /path/to/local/mountpoint/.

See AskDifferent issue: Can't mount NFS share in Big Sur. Crashes with NFSv4, rpc error with v3.

I know this doesn't really matter but add the -p flag for the mkdir command. That way it will make the parent folder as well.
sudo mkdir /mnt/mydrive/shared -p

Hope this helps a little