Skip to content

Commit d00c661

Browse files
JesAppdlech
authored andcommitted
[WIP] Add docs on mounting NFS share via systemd (#386)
* remove fstab section, add mount unit section, add author (me) * add section on NFS mount unit
1 parent a6107b8 commit d00c661

File tree

1 file changed

+33
-37
lines changed

1 file changed

+33
-37
lines changed

docs/tutorials/setting-up-an-nfs-file-share.md

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Setting Up an NFS File Share
33
group: advanced-networking
4-
author: [ "@antonvh","@rhempel","JNFitzgerald" ]
4+
author: [ "@antonvh","@rhempel","JNFitzgerald", "Jesko Appelfeller" ]
55
---
66

77
* Table of Contents
@@ -97,56 +97,50 @@ After creating the file, the `nfsd` daemon [should automatically start up][OSXSe
9797

9898
If you make changes to `/etc/exports`, activate them with `nfsd update`.
9999

100-
Now update the fstab on the EV3.
101-
102100
## How To Do It - EV3
103101

104-
On the EV3 we first need to enable and start NFS modules. Type these commands on the command line:
105-
106-
sudo systemctl enable nfs-common.service
107-
sudo systemctl start nfs-common.service
108-
sudo systemctl enable rpcbind.service
109-
sudo systemctl start rpcbind.service
110-
111-
Next you'll need to update a file (as root) called `/etc/fstab`. You should have already set up USB Networking, so `ssh` to the EV3 and run an editor like `vi` or `nano` to edit the file. Here's the line you want to add to `/etc/fstab` - DO NOT TOUCH ANYTHING ELSE IN THERE!
102+
On the client - ev3dev - side, we need to create, test and enable a systemd `mount.unit` file in order to mount our newly created NFS share.
112103

104+
{% include /style/icon.html type="warning" %}
105+
The classic way of mounting the NFS share via an entry in `/etc/fstab` does not work! It can cause ev3dev to hang during boot up.
106+
{: .alert .alert-warning}
113107

114-
# NOTE - the following examples all use the same IP address for the host, in practice, there would
115-
# be separate addresses for each host!
108+
First off, we need to create our `mount.unit` file. This file needs to be named after the directory where we want to mount our NSF share, with the slashes replaced by hyphens. For this tutorial, we will mount the NFS share at `/home/robot/nfsshare/` - feel free to change this to suit your needs.
116109

117-
# For the Linux example, it would look like:
118-
192.168.2.1:/home/hostuserid/nfs/ev3dev /home/robot/nfs/linux nfs users,noauto,rw,vers=3 0 0
119-
120-
# For the Windows Hanewin example, it would look like:
121-
192.168.0.199:\E\Users\James\Dropbox\ev3dev /home/robot/nfs/windows nfs users,noauto,rw,vers=3 0 0
122-
123-
# For the OSX example, it would look like:
124-
192.168.2.1:/Users/youruserid/Public /home/robot/nfs/osx nfs users,noauto,rw,vers=3 0 0
110+
Create and open the file `/etc/systemd/system/home-robot-nfsshare.mount`. Add the following sections:
125111

112+
[Unit]
113+
Description=Mount an nfs share
114+
After=network.target
115+
116+
[Mount]
117+
What=192.168.0.10:/path/to/shared/folder
118+
Where=/home/robot/nfsshare
119+
Type=nfs
120+
121+
[Install]
122+
WantedBy=multi-user.target
123+
124+
The `[Unit]` section provides a general description of the systemd unit file we have just created. The `After=network.target` line tells systemd to only attempt to mount this after a network connection has been established.
126125

127-
It's not too hard to figure out what's going on here. The host machine with the nfs mount is at `192.168.2.1` and we added `/home/hostuserid/nfs/ev3dev` (or whatever the host is exporting the directory as) to the `/etc/exports` file on that machine. The next section of the line says we want to mount it locally at `/home/ev3userid/nfs/linux`, or whatever directory you choose.
126+
The `[Mount]` section describes what to mount where. For the `What=` line, replace `192.168.0.10` with the IP addres of the computer on which you configured your NFS share and `/path/to/shared/folder` with the folder you have configured to be shared. As stated above, `/home/robot/nfsshare` is the path where we want to mount the NFS share.
128127

129-
The options tell `mount` that:
128+
The `[Install]` section describes, when to start this unit after it has been enabled. `WantedBy=multi-user.target` means that this file will be executed after the system is ready for a user to log in.
130129

131-
- this is an nfs share
132-
- we do not want to automatically mount it at boot time (in case the host is not connected)
133-
- general users are allowed to mount the share
134-
- we want read/write access
135-
- we are using nfs V3 on the host
130+
In order to mount the NFS share, you first need to reload the systemd daemon:
136131

137-
Once you've updated the `/etc/fstab` file, you will need to create the mount points. Since I test `ev3dev` o n all three major platforms, I have separate directories for each nfs host. You probably only need to create one of these, but this script creates all three for me:
132+
sudo systemctl daemon-reload
133+
134+
Then, we need to start the mount unit we have just created:
138135

139-
mkdir -p ~/nfs/linux
140-
mkdir -p ~/nfs/windows
141-
mkdir -p ~/nfs/osx
136+
sudo systemctl start home-robot-nfsshare.mount
137+
138+
To verify that everything worked, look into the `/home/robot/nfsshare` directory and check that the files from your NFS share are there. **Note**: The directory `/home/robot/nfsshare` should have been created automatically.
142139

143-
Then all you need to do is mount the share, like this:
140+
If you want your NFS share to be mounted at boot, you need to enable the mount unit by typing:
144141

145-
mount ~/nfs/linux
146-
147-
...or whichever of the above three directories you want to mount.
142+
sudo systemctl enable home-robot-nfsshare.mount
148143

149-
And then you should be able to see the files on your host computer when you do `ls /home/ev3userid/nfs/ev3dev`!
150144

151145
## References
152146

@@ -165,3 +159,5 @@ And then you should be able to see the files on your host computer when you do `
165159
[OSXexports5]: http://www.manpages.info/macosx/exports.5.html
166160
[OSXnfsd]: http://www.manpages.info/macosx/nfsd.8.html
167161
[OSXshowmount]: http://www.manpages.info/macosx/showmount.8.html
162+
[systemd mount units]: https://www.freedesktop.org/software/systemd/man/systemd.mount.html
163+

0 commit comments

Comments
 (0)