Difference between revisions of "Setting up NFS for file sharing"

From Da Nerd Mage Wiki
Jump to navigation Jump to search
 
(55 intermediate revisions by 2 users not shown)
Line 4: Line 4:
{{!}} style="text-align: center; width: 60px;" {{!}} [[File:Logo Debian.png{{!}}60px{{!}}link=https://www.debian.org/{{!}}center{{!}}middle{{!}}frameless]]
{{!}} style="text-align: center; width: 60px;" {{!}} [[File:Logo Debian.png{{!}}60px{{!}}link=https://www.debian.org/{{!}}center{{!}}middle{{!}}frameless]]
{{!}} style="text-align: center; width: 40px;" {{!}} 11 (bullseye)
{{!}} style="text-align: center; width: 40px;" {{!}} 11 (bullseye)
{{!}}
{{!}} (This includes LMDE5, Proxmox, OMV...)
 
{{!}}- --="" winderp=""
<br>
{{!}} style="text-align: center; width: 60px;" {{!}} [[File:Logo Windows.png{{!}}60px{{!}}link=https://www.microsoft.com/en-gb/windows{{!}}center{{!}}middle{{!}}frameless]]
{{!}} style="text-align: center; width: 40px;" {{!}} 10
{{!}} (For the client side anyhow...)
{{!}}-
{{!}} style="text-align: center; width: 60px;" colspan="3" {{!}} [[typographic conventions{{!}}A little note about typographic conventions you'll see here]]
{{!}}}
{{!}}}
(A note about [[PVE LXC_Containers#Adding_NFS_to_an_LXC{{!}}LXCs & NFS]])


==Install NFS Server==
== Install NFS Server ==


* <code>sudo apt install nfs-kernel-server</code>
* <code>sudo apt install nfs-kernel-server</code>
Line 18: Line 23:
Add/edit:
Add/edit:


  '''/path/to/be/shared''' *(rw,async,no_root_squash,no_subtree_check)
  '''/PATH/TO/BE/SHARED''' *(rw,async,no_root_squash,no_subtree_check)
For the changes to take effect, export and start NFS service.
For the changes to take effect, export and start NFS service.
* <code>sudo exportfs -a</code>
* <code>sudo exportfs -a</code>
Line 24: Line 29:
Pretty simple...
Pretty simple...


=== A bit about re-sharing ===
== Connecting to the NFS Server ==
Sometimes, you may want to share something that you've actually mounted from an NFS share on another machine...
=== From Linux ===
You'll need NFS installed
* <code>sudo apt install nfs-common</code>
or
* <code>sudo apt install nfs-kernel-server</code>
Then you can check what's shared from any particular machine:
* <code>showmount -e '''[SERVERNAME or ADDRESS]'''</code>
** (requires sudo on Debian...)
will show you what's shared from a machine


A couple of things are different in this case.
==== Setting up & mounting a share ====
* <code>sudo mkdir -p '''/PATH/TO/MOUNT/SHARE'''</code>
* <code>sudo mount '''[SERVERNAME or ADDRESS]''':'''/PATH/TO/BE/SHARED''' '''/PATH/TO/MOUNT/SHARE'''</code>
Better yet tho...
* <code>sudo vi /etc/fstab</code>
& add an entry:
'''[SERVERNAME or ADDRESS]''':'''/PATH/TO/BE/SHARED''' '''/PATH/TO/MOUNT/SHARE''' nfs rw,user,exec 0 0
Then, you can mount anything listed in fstab but not yet mounted
* <code>sudo mount -a</code>
 
=== From Windows (Win10) ===
==== (Tentative Working Notes) ====
<span style="font-size: 18pt;">'''<span style="color: rgb(132, 63, 161);">It has come to my attention... PRO & Enterprise only... Sorry</span>'''</span>
===== Enabling NFS =====
 
First things first... You need to know the [https://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/ UID and GID] of the user on the intended share so that you can emulate it.
 
* <code class="mwt-code" >cat /etc/passwd</code><br>
 
Find the user that is responsible for the share and grab that number. In this case we will use '''tinker''' (so '1000' & '1000') but it could be anything. In this example...


First, you need to ensure that the mounts are done BEFORE you start the NFS server.
<code>tinker:x:1000:1000::/home/tinker:/bin/sh</code>


* <code>sudo vi /etc/init.d/nfs-kernel-server</code>
<span style="color: rgb(132, 63, 161);">'''In an Admin Powershell window:'''</span>
and add:
##########################
echo "Starting out by making sure EVERYTHING is mounted..."
/usr/bin/mount -a
echo "Really..."
echo "This is NOT the right place to do this..."
echo "But, init.d kinda sucks..."
##########################
right near the start.


Then you need to provide an fsid entry (with a unique number) for each export.
Turn on NFS


'''/path/to/be/shared''' *(rw,async,no_root_squash,no_subtree_check''',fsid=1010''')
*<code>Enable-WindowsOptionalFeature -FeatureName ServicesForNFS-ClientOnly, ClientForNFS-Infrastructure -Online -NoRestart</code>
<span style="color: rgb(186, 55, 42); font-size: 14pt;" >'''AND''' it '''STILL''' doesn't start at boot!!!</span>
Set up anonymous credentials to match the credentials of a user with full access to the NFS share from a Linux viewpoint...


But, you can force it to start after booting by logging into the machine & telling it:
Make any servers you connect to think you're somebody important


* <code>sudo /etc/init.d/nfs-kernel-server start</code>
*<code>New-ItemProperty HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default -Name AnonymousUID -Value '''1000''' -PropertyType "DWord"</code>
*<code>New-ItemProperty HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default -Name AnonymousGID -Value '''1000''' &nbsp;-PropertyType "DWord"</code>
The "'''AnonymousUID'''" & "'''AnonymousGID'''" Value's are the UID & GID of a user on the server with appropriate permissions... (In this case, the first user created on the server(s)) and for this purpose, they do not need to be changed. Leave them anonymous. Make sure that the '''1000''' is the actual ID you retrieved.
 
WARNING: If you copy/paste the two lines above, you will find that you can't mount the share (unless you are just lucky and the ID is actually 1000... go buy a lottery ticket). To fix it, you will have to do a <code class="mwt-code" >regedit</code> and change the DWORD value (in hex) to the correct number. You are on your own for that.
 
'''<span style="color: rgb(186, 55, 42);">Reboot the computer</span>'''
 
===== Mount the drive(s) =====
 
<span style="color: rgb(132, 63, 161);">'''In a regular command shell:'''</span>
 
*EXAMPLE FORMAT - mount -o nolock \\IP_or_FQDN_OF_SHARE\\Directory_Of_Share\Sub_Folder [ DRIVE TO MAP IT TO:<code>]</code>
*<code>mount -o nolock \\TinkerData.tinkernet.ca\home\tinker\Documents D:</code>
*<code>mount -o nolock \\Warehouse.tinkernet.ca\mnt\Space_1\Pix P:</code>
You can map to a folder on your machine as well if you want it somewhere like the desktop instead(WIP)
 
EVERY TIME the machine is rebooted, mount the drives... Again...
 
===== Make your mount(s) persistant =====
 
([https://dop-amine.com/posts/persistent-nfs-windows/ Source])
 
Open the Startup folder by opening the Run tool and entering <code>shell:startup</code>
 
Create <code>nfsmount.bat</code> file in that directory with the mount command used above.
 
'''<span style="color: rgb(132, 63, 161);" >If you use Notepad to create that file, make sure to save it as 'All Files' instead of '.txt.'. Otherwise it will be 'nfsmount.bat.txt' and will not work.</span>'''


==Connecting to the NFS Server==
This file will be read on startup and will automatically mount the NFS Share.
You'll need NFS installed
* <code>sudo apt install nfs-common</code>


or
== NFS management From the GUI (sort of...) ==
* <code>sudo apt install nfs-kernel-server</code>


Then you can check what's shared from any particular machine:
[https://github.com/Philippe734/Simple.NFS.GUI Simple NFS GUI for Linux] is an option.
* <code>showmount -e '''[ServerName or Address]'''</code>
** (requires sudo on Debian...)


will show you what's shared from a machine
Installation can be a bit awkward & it's far from polished tho...


===Setting up & mounting a share===
Installing: (On Debian-based systems)


* <code>sudo mkdir -p '''/path/to/mount/share'''</code>
* <code>sudo apt install gambas3</code>
* <code>sudo mount '''[ServerName or Address]''':'''/path/to/be/shared''' '''/path/to/mount/share'''</code>
** (original instructions attempt to do this via a PPA... Good luck with that...)
Better yet tho...
* <code>wget <nowiki>https://github.com/Philippe734/Simple.NFS.GUI/raw/master/Linux/1.0.17/simple-nfs-gui_1.0.17-0ubuntu1_all.deb -P ~</nowiki></code>
* <code>sudo vi /etc/fstab</code>
** To download the package
& add an entry:
* <code>sudo dpkg -i ~/simple-nfs-gui_1.0.17-0ubuntu1_all.deb</code>
'''[ServerName or Address]''':'''/path/to/be/shared''' '''/path/to/mount/share''' nfs rw,user,exec 0 0
** Then install it
Then, you can mount anything listed in fstab but not yet mounted
Once it's installed, you need to run it as root:
* <code>sudo mount -a</code>
* <code>sudo -H Simple_NFS_GUI</code>
Kind of a [https://www.linuxuprising.com/2018/11/easy-nfs-share-setup-in-ubuntu-linux.html guide to using it]
=== Other Options ===
* [https://www.webmin.com/ Webmin] has full support for configuring NFS...


==TBD==
== TBD ==


* Learn what flags do what in '''/etc/exports'''  
* Learn what flags do what in '''/etc/exports'''
* Browsing in the GUI would be nice...
* Look into automounting (including graceful failure modes)
* Look into automounting (including graceful failure modes)  
* Work up some instructions for other non-Linux systems. (Synology, Kodi, Mac)


== Some Links ==
== Some Links ==
Line 89: Line 136:
* [https://linux.die.net/man/5/exports exports(5) - Linux man page]
* [https://linux.die.net/man/5/exports exports(5) - Linux man page]
* [https://linux.die.net/man/8/mount mount(8) - Linux man page]<br>
* [https://linux.die.net/man/8/mount mount(8) - Linux man page]<br>
* [https://linux.die.net/man/5/fstab fstab(5) - Linux man page]
[[Category:Linux]]
[[Category:Linux]]
[[Category: WIP]]
[[Category: WIP]]

Latest revision as of 15:43, 23 September 2024

Proven on:
Logo Debian.png
11 (bullseye) (This includes LMDE5, Proxmox, OMV...)
Logo Windows.png
10 (For the client side anyhow...)
A little note about typographic conventions you'll see here

(A note about LXCs & NFS)

Install NFS Server

  • sudo apt install nfs-kernel-server

Configure NFS Server

  • sudo vi /etc/exports

Add/edit:

/PATH/TO/BE/SHARED *(rw,async,no_root_squash,no_subtree_check)

For the changes to take effect, export and start NFS service.

  • sudo exportfs -a
  • sudo /etc/init.d/nfs-kernel-server start

Pretty simple...

Connecting to the NFS Server

From Linux

You'll need NFS installed

  • sudo apt install nfs-common

or

  • sudo apt install nfs-kernel-server

Then you can check what's shared from any particular machine:

  • showmount -e [SERVERNAME or ADDRESS]
    • (requires sudo on Debian...)

will show you what's shared from a machine

Setting up & mounting a share

  • sudo mkdir -p /PATH/TO/MOUNT/SHARE
  • sudo mount [SERVERNAME or ADDRESS]:/PATH/TO/BE/SHARED /PATH/TO/MOUNT/SHARE

Better yet tho...

  • sudo vi /etc/fstab

& add an entry:

[SERVERNAME or ADDRESS]:/PATH/TO/BE/SHARED /PATH/TO/MOUNT/SHARE nfs rw,user,exec 0 0

Then, you can mount anything listed in fstab but not yet mounted

  • sudo mount -a

From Windows (Win10)

(Tentative Working Notes)

It has come to my attention... PRO & Enterprise only... Sorry

Enabling NFS

First things first... You need to know the UID and GID of the user on the intended share so that you can emulate it.

  • cat /etc/passwd

Find the user that is responsible for the share and grab that number. In this case we will use tinker (so '1000' & '1000') but it could be anything. In this example...

tinker:x:1000:1000::/home/tinker:/bin/sh

In an Admin Powershell window:

Turn on NFS

  • Enable-WindowsOptionalFeature -FeatureName ServicesForNFS-ClientOnly, ClientForNFS-Infrastructure -Online -NoRestart

Set up anonymous credentials to match the credentials of a user with full access to the NFS share from a Linux viewpoint...

Make any servers you connect to think you're somebody important

  • New-ItemProperty HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default -Name AnonymousUID -Value 1000 -PropertyType "DWord"
  • New-ItemProperty HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default -Name AnonymousGID -Value 1000  -PropertyType "DWord"

The "AnonymousUID" & "AnonymousGID" Value's are the UID & GID of a user on the server with appropriate permissions... (In this case, the first user created on the server(s)) and for this purpose, they do not need to be changed. Leave them anonymous. Make sure that the 1000 is the actual ID you retrieved.

WARNING: If you copy/paste the two lines above, you will find that you can't mount the share (unless you are just lucky and the ID is actually 1000... go buy a lottery ticket). To fix it, you will have to do a regedit and change the DWORD value (in hex) to the correct number. You are on your own for that.

Reboot the computer

Mount the drive(s)

In a regular command shell:

  • EXAMPLE FORMAT - mount -o nolock \\IP_or_FQDN_OF_SHARE\\Directory_Of_Share\Sub_Folder [ DRIVE TO MAP IT TO:]
  • mount -o nolock \\TinkerData.tinkernet.ca\home\tinker\Documents D:
  • mount -o nolock \\Warehouse.tinkernet.ca\mnt\Space_1\Pix P:

You can map to a folder on your machine as well if you want it somewhere like the desktop instead(WIP)

EVERY TIME the machine is rebooted, mount the drives... Again...

Make your mount(s) persistant

(Source)

Open the Startup folder by opening the Run tool and entering shell:startup

Create nfsmount.bat file in that directory with the mount command used above.

If you use Notepad to create that file, make sure to save it as 'All Files' instead of '.txt.'. Otherwise it will be 'nfsmount.bat.txt' and will not work.

This file will be read on startup and will automatically mount the NFS Share.

NFS management From the GUI (sort of...)

Simple NFS GUI for Linux is an option.

Installation can be a bit awkward & it's far from polished tho...

Installing: (On Debian-based systems)

  • sudo apt install gambas3
    • (original instructions attempt to do this via a PPA... Good luck with that...)
  • wget https://github.com/Philippe734/Simple.NFS.GUI/raw/master/Linux/1.0.17/simple-nfs-gui_1.0.17-0ubuntu1_all.deb -P ~
    • To download the package
  • sudo dpkg -i ~/simple-nfs-gui_1.0.17-0ubuntu1_all.deb
    • Then install it

Once it's installed, you need to run it as root:

  • sudo -H Simple_NFS_GUI

Kind of a guide to using it

Other Options

  • Webmin has full support for configuring NFS...

TBD

  • Learn what flags do what in /etc/exports
  • Look into automounting (including graceful failure modes)
  • Work up some instructions for other non-Linux systems. (Synology, Kodi, Mac)

Some Links