Add NFS Shares on Raspberry Pi OS
Before installing new software it is always good to make sure the system is up to date, for that follow the instructions in page Update Raspberry Pi OS System.
To add NFS shares, first install the NFS server:
$ sudo apt-get install nfs-kernel-server
Next get the ID for the pi user:
$ id pi
The result should look like this:
uid=1000(pi) gid=1000(pi) groups=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),105(input),109(netdev),999(spi),998(i2c),997(gpio)
Take note of the uid and gid for the pi user as it is needed for the exports.
The next step is to edit the newly created /etc/exports file for adding the shares:
$ sudo nano /etc/exports
Add each directory to be exported to the exports as follows, including the pi id numbers for anonymous users:
/media/USBHDD1 *(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)
/media/USBHDD2 *(rw,all_squash,insecure,async,no_subtree_check,anonuid=1000,anongid=1000)
The last step is to update the current table of exports:
sudo exportfs -ra
The export should be available via NFS now.