English version below
Hallo,
nachdem ich gerade meine Festplatte vom einen auf den anderen Rechner teilen will/muss, um quasi im Wohnzimmer einen Film zu schauen, berichte ich euch hier geschwind, wie ich mir NFS aufgesetzt habe.
Ich werde in dieser Anleitung demonstrieren, wie man einen Ordner per NFS freigibt, da dies mein Use Case ist. Weitere Ordner funktionieren aber analog.
Ich befolge im Endeffekt grob die Schritte unter https://wiki.archlinux.org/title/NFS .
Schritt 1: Install Deps
Auf Arch ist nur nfs-utils benötigt, auf anderen Distros bitte selbst recherchieren :)
Schritt 2: Mounts einrichten
Es wird in der Arch-Anleitung empfohlen, die Freigaben zwecks Sicherheit auf einen Ordner zu beschränken, in dem Beispiel auf /srv/nfs. Dadurch können User nicht aus Versehen ausbrechen und zu anderen Orten gelangen. Wir legen uns also die nötige Ordnerstruktur an (media_data heißt eine meiner Datenpartitionen)
# mkdir -p /srv/nfs/media_data
und bind-mounten da jetzt unseren eigentlichen Ordner rein:
# mount --bind /media/Data/ra1n /srv/nfs/media_data
(Pfade bitte entsprechend anpassen, links beim mount steht euer Pfad, den ihr freigeben wollt)
Um das Mounten automatisch beim Booten durchzuführen, muss man noch die /etc/fstab bearbeiten:
Sehr straightforward, einfach die beiden Pfade und dahinter die knappen "none bind 0 0" specs.
Schritt 3: Exports festlegen
Hier müssen wir dem NFS-Server quasi mitteilen, welcher Ordner wie freigegeben soll. Dafür verwenden wir die Datei /etc/exports.
Links der Pfad, daneben die erlaubten Client-IPs (mein Privatnetzwerk in diesem Fall; * würde alles erlauben), die Parameter sind folgendermaßen:
- rw - klar, read/write, ro analog für read-only
- crossmnt - wichtig für den root in diesem Fall, erlaubt das automatische Mounten der ganzen Ordnerstruktur
- fsid=0 - nur wichtig für den root
- sync - Bin mir nicht sicher, ein Blick auf die Doku weiter unten bringt mich aber auf den Gedanken, das lieber nicht wegzulassen
Nach dem Ändern der exports-Datei müsst ihr noch "refreshen":
# exportfs -arv
Schritt 4: Starting the server
Ein geschwindtes
# systemctl enable --now nfs-server.service
startet den Dienst und aktiviert ihn beim Systemstart. Sollte der Befehl fehlschlagen, verwendet Eure Distro möglicherweise nicht systemd und ihr müsst euch selbst erkundigen.
Schritt 5: Configure the client
Fast geschafft!
Auf dem Client führt ihr
$ showmount -e server-ip
aus, um die verfügbaren Mounts anzeigen zu lassen. Hier müssten jetzt die konfigurierten Ordner aufgelistet werden. Wenn das nicht passiert, ist das ein Grund zur Panik und man sollte seinen PC anzünden und wegrennen. Vermutlich ist die CIA schon informiert.
Danach kann man mit
# mkdir -p /media/nfs/media_data
# mount -t nfs -o vers=4 servername:/media_data /media/nfs/media_data
in meinem Fall den Ordner an den gewünschten Ort mounten. ArchWiki weist darauf hin, dass bei einigen Distros die leicht andere Syntax
# mount -t nfs -o vers=4 servername:/srv/nfs/media_data /media/nfs/media_data
notwendig sein mag (also den Root-Folder vorneran gestellt). Einfach ausprobieren.
Damit melde ich mich auch schon wieder ab.
English version
Hello,
after I want/need to share my harddisk from one computer to the other, to watch a movie in the livingroom, I'll tell you how I set up NFS.
In this tutorial I will demonstrate how to share one folder via NFS, since this is my use case. However, other folders work analogously.
I end up roughly following the steps at https://wiki.archlinux.org/title/NFS .
Step 1: Install Deps
On Arch only nfs-utils is needed, on other distros please do your own research :)
Step 2: Set up mounts
It is recommended in the Arch instructions to limit the shares to one folder for security reasons, in the example to /srv/nfs. This way users can't accidentally break out and get to other locations. So we create the necessary folder structure (media_data is the name of one of my data partitions)
# mkdir -p /srv/nfs/media_data
and bind-mount our actual folder into it:
# mount --bind /media/Data/ra1n /srv/nfs/media_data
(Please adjust the paths accordingly, on the left side of the mount is the path you want to share)
To do the mount automatically at boot time you have to edit the /etc/fstab:
Very straightforward, just add the two paths and behind them the terse "none bind 0 0" specs.
Step 3: Specify exports
Here we have to tell the NFS server which folder should be shared and how. For this we use the file /etc/exports.
On the left the path, next to it the allowed client IPs (my private network in this case; * would allow everything), the parameters are as follows:
- rw - clear, read/write, ro analog for read-only
- crossmnt - important for root in this case, allows automatic mounting of the whole folder structure
- fsid=0 - only important for the root
- sync - not sure, but a look at the docs below makes me think not to omit this one
After changing the exports file you still have to "refresh":
# exportfs -arv
Step 4: Starting the server
A quick
# systemctl enable --now nfs-server.service
starts the service and enables it at system startup. If the command fails, your distro may not be using systemd and you will have to check for yourself.
Step 5: Configure the client
Almost there!
On the client run
$ showmount -e server-ip
to display the available mounts. The configured folders should be listed here now. If this doesn't happen, this is a reason to panic and you should set your PC on fire and run away. *Probably the CIA is already informed.
After that you can use
# mkdir -p /media/nfs/media_data
# mount -t nfs -o vers=4 servername:/media_data /media/nfs/media_data
in my case mount the folder to the desired location. ArchWiki points out that some distros use the slightly different syntax
# mount -t nfs -o vers=4 servername:/srv/nfs/media_data /media/nfs/media_data
may be necessary (so put the root folder first). Just try it out.
With this I'll sign off again.