4.0 KiB
title | summary | date | categories | tags | ||||
---|---|---|---|---|---|---|---|---|
Using NFS shares on a Raspberry Pi | A quick and short guide on how to setup an NFS share on a Raspberry Pi. | 2022-08-07T07:19:54+02:00 |
|
|
I use this mainly on my amateur radio hotspot when I work on my sleek dashboard.
This setup lets me edit the php-files on my computer while I use the already installed webserver as a development server to view the actual changes/progress. The advantage of that is: I don't have to feed pseudo-random data into the tables, the data gets pulled live from the logs -- like it would be on the final system.
Installation and configuration
$ sudo apt update
$ sudo apt install nfs-kernel-server
$ sudo vim /etc/exports
We have to export our directories in the file /etc/exports
on our Raspberry Pi.
# file: "/etc/exports"
/var/www/html 192.168.1.123(rw,async,all_squash,insecure,no_subtree_check,anonuid=1000,anongid=1000)
/opt/MMDVMDash 192.168.1.123(rw,async,all_squash,insecure,no_subtree_check,anonuid=1000,anongid=1000)
So we allow 192.168.1.123
read- and write-access to the directories above.
{{< alert circle-info >}} For the record: my user on my laptop (192.168.1.123) has the same UID (1000) as my user on the Raspberry Pi (192.168.1.124). {{< /alert >}}
Also edit /etc/hosts.allow
to grant access for your network or host.
# file: "/etc/hosts.allow"
ALL: 192.168.1.123
After we changed the contents of /etc/exports
we have to run the exportfs
command and restart the nfs-server.
$ sudo exportfs -ra
$ sudo systemctl restart nfs-server.service
Accessing the directories
I usually look at the logs on my Raspberry Pi with journalctl -fe
and let
this running.
Now on my laptop in my home directory. I create a temporary directory with
mkdir tmp
and try to mount the nfs share into that. On most linux systems
only root is allowed to use mount without an entry in /etc/fstab
.
So we run
$ sudo mount 192.168.1.124:/var/www/html tmp/
and if it does not print anything, all is good. On the Raspberry Pi you should see a new line looking like:
raspi4 rpc.mountd[30223]: authenticated mount request from 192.168.1.123:894 for /opt/MMDVMDash/html (/opt/MMDVMDash/html)
{{< alert circle-info >}}
To eliminate the confusion: I've mounted /var/www/html
but the log shows
/opt/MMDVMDash/html
. This is because /var/www/html
is currently a symbolic
link to /opt/MMDVMDash/html
. But if I remove the symlink and replace it with
real files the export will still work.
{{< /alert >}}
And that's it. Unmount with sudo umount tmp/
and we should create an entry
in our /etc/fstab
file to let the system mount this share when starting.
When unmounting, you should see another line on your Raspberry Pi.
raspi4 rpc.mountd[30223]: authenticated unmount request from 192.168.1.123:696 for /opt/MMDVMDash/html (/opt/MMDVMDash/html)
Creating entries in our /etc/fstab
file
First, let us create a directory on our laptop.
$ mkdir -p ~/raspi4/html
# file: "/etc/fstab"
192.168.1.124:/var/www/html /home/dominic/raspi4/html nfs noauto,users,nodev,async,soft,_netdev,x-systemd.automount,x-systemd.device-timeout=1,x-systemd-idle-timeout=1min,x-systemd.mount-timeout=10,timeo=10,retry=3 0 0
After changing that file, make sure to reload Systemd with
sudo systemctl daemon-reload
.
Mount them from your home directory with mount raspi4/html
. The same line
should appear on your Raspberry Pi (if you still have journalctl -fe
running!).
You may use less confusing settings in your fstab
file, but I'm going with
those from above on my Manjaro box, as I also use other NFS shares on my NAS and
it turned out those work best for my scenario for now.
You could try by only using noauto,users,nodev,async
as a starting point. If
it fails, try adding only _netdev
first -- I can't exactly remember why, but I
keep thinking I researched this a while back and sticked with it.