How to share hard drive with another computer with NFS?

server ❯ sudo nvim /etc/fstab
/run/media/user/R /srv/nfs/R none bind 0 0
server ❯ sudo mount -a
mount: (hint) your fstab has been modified, but systemd still uses
       the old version; use 'systemctl daemon-reload' to reload.
server ❯ sudo nvim /etc/exports
/srv/nfs            192.168.1.0/24(rw,sync,crossmnt,fsid=0)
/srv/nfs/R          192.168.1.0/24(rw,sync)
server ❯ sudo systemctl enable --now nfs-server.service
client ❯ sudo nvim /etc/systemd/system/data-nfs-R.mount
[Unit]
Description=R
After=network.target

[Mount]
What=192.168.1.122:/nfs/R
Where=/data/nfs/R
Type=nfs
Options=_netdev,auto

[Install]
WantedBy=multi-user.target
client ❯ sudo systemctl enable data-nfs-R.mount
client ❯ sudo nvim /etc/systemd/system/data-nfs-R.automount
[Unit]
Description=Automount R drive share
ConditionPathExists=/data/nfs/R

[Automount]
Where=/data/nfs/R
TimeoutIdleSec=10

[Install]
WantedBy=multi-user.target
client ❯ sudo systemctl enable --now data-nfs-R.automount
client ❯ cd /data/nfs
cd: no such file or directory: /data/nfs
# See UUID in gnome-disk-utility
server ❯ sudo nvim /etc/systemd/system/data-nfs-R.mount
[Unit]
Description=My shared partition

[Mount]
What=/dev/disk/by-uuid/8066D52E66D525A6
Where=/data/nfs/R
Type=ntfs
Options=defaults,rw,noatime

[Install]
WantedBy=multi-user.target

server ❯ sudo systemctl enable --now data-nfs-R.mount
Created symlink /etc/systemd/system/multi-user.target.wants/data-nfs-R.mount → /etc/systemd/system/data-nfs-R.mount.
Job failed. See "journalctl -xe" for details.
server ❯ journalctl -xe
Support: https://forum.manjaro.org/c/support
░░
░░ An n/a= process belonging to unit data-nfs-R.mount has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 16.
jul 16 14:19:59 arch systemd[1]: data-nfs-R.mount: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░
░░ The unit data-nfs-R.mount has entered the 'failed' state with result 'exit-code'.
jul 16 14:19:59 arch systemd[1]: Failed to mount My shared partition.
░░ Subject: A start job for unit data-nfs-R.mount has failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░
░░ A start job for unit data-nfs-R.mount has finished with a failure.
░░
░░ The job identifier is 2550 and the job result is failed.
jul 16 14:19:59 arch audit[3276547]: USER_END pid=3276547 uid=1000 auid=1000 ses=1 subj==unconfined msg='op=PAM:session>
jul 16 14:19:59 arch audit[3276547]: CRED_DISP pid=3276547 uid=1000 auid=1000 ses=1 subj==unconfined msg='op=PAM:setcre>
jul 16 14:19:59 arch sudo[3276547]: pam_unix(sudo:session): session closed for user root
jul 16 14:20:01 arch syncthing[1321]: [H4RSE] INFO: Puller (folder "home" (lgu5e-zpytn), item ".mozilla/firefox/5k3mpg4>
jul 16 14:20:01 arch syncthing[1321]: [H4RSE] INFO: "home" (lgu5e-zpytn): Failed to sync 1 items
jul 16 14:20:01 arch syncthing[1321]: [H4RSE] INFO: Folder "home" (lgu5e-zpytn) isn't making sync progress - retrying i>
jul 16 14:20:31 arch syncthing[1321]: [H4RSE] INFO: Puller (folder "home" (lgu5e-zpytn), item ".mozilla/firefox/5k3mpg4>
jul 16 14:20:31 arch syncthing[1321]: [H4RSE] INFO: "home" (lgu5e-zpytn): Failed to sync 1 items
jul 16 14:20:31 arch syncthing[1321]: [H4RSE] INFO: Folder "home" (lgu5e-zpytn) isn't making sync progress - retrying i

… don’t use the /run/... folder but another dedicated folder as in the example
/run and it’s contents are special as in they do not exist permanently

I’m trying to share the content of a hard drive. How would I do it then?

Mount the device in /data/nfs/R using the mount unit

You don’t use automount on server for a service shares - only on clients.

systemctl enable --now data-nfs-R.mount

/run is a volatile structure recreated on boot - don’t use.

Create a share point in /srv/nfs/R

Bind /data/nfs/R to /srv/nfs/R in fstab- doing so ensures your are not exposing your real file system to computers accessing the service.

Reload fstab

sudo mount -a

differently? :wink:
start with not using the /run directory to mount your drive
The drive has a device name (/dev/sdXx)
That device needs to be mounted to (e.g)

/srv/nfs/R

make sure it is mounted before you try to share it via NFS

run is where the hard drive is mounted by default. How do I make the hard drive mount automatically somewhere else? I don’t want to mount it manually every time.

Assuming this is the system running the nfs server service

You need the partition UUID - replace the yX with the device letter and partition number e.g. sda1

lsblk -no UUID /dev/sdyX

Then in your mount unit /etc/systemd/system/data-nfs-R.mount - (replace $UUID below with the result of above command)

[Unit]
Description=My shared partition

[Mount]
What=/dev/disk/by-uuid/$UUID
Where=/data/nfs/R
Type=ext4
Options=defaults,rw,noatime

[Install]
WantedBy=multi-user.target

enable and start the unit

sudo systemctl enable --now data-nfs-R.mount

on your server

sudo mkdir -p /srv/nfs/R

In your server’s fstab

/data/nfs/R /srv/nfs/R none bind 0 0

I had assumed the mounting was done in the client from reading the tutorial. All this is in the server then?

sharing the device is server

consuming the share is client

both are configured differently - and the guide describes both

  1. the mounting and sharing is described
    https://forum.manjaro.org/t/root-tip-share-data-using-nfs/29667#the-share-3
  2. the client consumption is described
    https://forum.manjaro.org/t/root-tip-share-data-using-nfs/29667#client-10
# See UUID in gnome-disk-utility
server ❯ sudo nvim /etc/systemd/system/data-nfs-R.mount
[Unit]
Description=My shared partition

[Mount]
What=/dev/disk/by-uuid/$UUID
Where=/data/nfs/R
Type=ntfs
Options=defaults,rw,noatime

[Install]
WantedBy=multi-user.target

server ❯ sudo systemctl enable --now data-nfs-R.mount
Created symlink /etc/systemd/system/multi-user.target.wants/data-nfs-R.mount → /etc/systemd/system/data-nfs-R.mount.
Job failed. See "journalctl -xe" for details.
server ❯ journalctl -xe
Support: https://forum.manjaro.org/c/support
░░
░░ An n/a= process belonging to unit data-nfs-R.mount has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 16.
jul 16 14:19:59 arch systemd[1]: data-nfs-R.mount: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░
░░ The unit data-nfs-R.mount has entered the 'failed' state with result 'exit-code'.
jul 16 14:19:59 arch systemd[1]: Failed to mount My shared partition.
░░ Subject: A start job for unit data-nfs-R.mount has failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░
░░ A start job for unit data-nfs-R.mount has finished with a failure.
░░
░░ The job identifier is 2550 and the job result is failed.
jul 16 14:19:59 arch audit[3276547]: USER_END pid=3276547 uid=1000 auid=1000 ses=1 subj==unconfined msg='op=PAM:session>
jul 16 14:19:59 arch audit[3276547]: CRED_DISP pid=3276547 uid=1000 auid=1000 ses=1 subj==unconfined msg='op=PAM:setcre>
jul 16 14:19:59 arch sudo[3276547]: pam_unix(sudo:session): session closed for user root
jul 16 14:20:01 arch syncthing[1321]: [H4RSE] INFO: Puller (folder "home" (lgu5e-zpytn), item ".mozilla/firefox/5k3mpg4>
jul 16 14:20:01 arch syncthing[1321]: [H4RSE] INFO: "home" (lgu5e-zpytn): Failed to sync 1 items
jul 16 14:20:01 arch syncthing[1321]: [H4RSE] INFO: Folder "home" (lgu5e-zpytn) isn't making sync progress - retrying i>
jul 16 14:20:31 arch syncthing[1321]: [H4RSE] INFO: Puller (folder "home" (lgu5e-zpytn), item ".mozilla/firefox/5k3mpg4>
jul 16 14:20:31 arch syncthing[1321]: [H4RSE] INFO: "home" (lgu5e-zpytn): Failed to sync 1 items
jul 16 14:20:31 arch syncthing[1321]: [H4RSE] INFO: Folder "home" (lgu5e-zpytn) isn't making sync progress - retrying i

Make sure you have no colliding mounts from previous attempts.

If the mount point is populated subsequent mounts will fail

this needs to end in the actual UUID of your device - not in “$UUID”

I don’t know how to do that. How can I remove the previous /data/nfs/R mount?

I know, I’ve substituted it when pasting it here.

sudo umount /dev/sdxY

So I have to unmount the hard drive or the created mount point? Would it be sudo umount /data/nfs/R?

You can do that

I just tested to verify

[fh@tiger ~]$ sudo micro /etc/systemd/system/a-ntfs.mount
[fh@tiger ~]$ cat /etc/systemd/system/a-ntfs.mount 
[Unit]
Description=ntfs test mount

[Mount]
What=/dev/disk/by-uuid/3A572DCB04BC70C8
Where=/a/ntfs
Type=ntfs
Options=defaults,rw,noatime

[Install]
WantedBy=multi-user.target

[fh@tiger ~]$ sudo systemctl start a-ntfs.mount
[fh@tiger ~]$ systemctl status a-ntfs.mount
● a-ntfs.mount - ntfs test mount
     Loaded: loaded (/etc/systemd/system/a-ntfs.mount; disabled; preset: disabled)
     Active: active (mounted) since Sat 2022-07-16 14:39:07 CEST; 6s ago
      Until: Sat 2022-07-16 14:39:07 CEST; 6s ago
      Where: /a/ntfs
       What: /dev/sde1
      Tasks: 1 (limit: 76998)
     Memory: 684.0K
        CPU: 5ms
     CGroup: /system.slice/a-ntfs.mount
             └─43943 /usr/bin/mount.ntfs /dev/sde1 /a/ntfs -o rw,noatime

Jul 16 14:39:07 tiger systemd[1]: Mounting ntfs test mount...
Jul 16 14:39:07 tiger ntfs-3g[43943]: Version 2022.5.17 external FUSE 29
Jul 16 14:39:07 tiger ntfs-3g[43943]: Mounted /dev/sde1 (Read-Write, label "", NTFS 3.1)
Jul 16 14:39:07 tiger ntfs-3g[43943]: Cmdline options: rw,noatime
Jul 16 14:39:07 tiger ntfs-3g[43943]: Mount options: allow_other,nonempty,noatime,rw,fsname=/dev/sde1,blkdev,>
Jul 16 14:39:07 tiger ntfs-3g[43943]: Ownership and permissions disabled, configuration type 7
Jul 16 14:39:07 tiger systemd[1]: Mounted ntfs test mount.

[fh@tiger ~]$ mount | grep ntfs
/dev/sde1 on /a/ntfs type fuseblk (rw,nosuid,nodev,noatime,user_id=0,group_id=0,allow_other,blksize=4096)
[fh@tiger ~]$ ls /a/ntfs/
[fh@tiger ~]$ touch /a/ntfs/test.file
[fh@tiger ~]$ ls /a/ntfs
test.file

I’ll restart and try again later because it isn’t mounting for some reason

server ❯ sudo mv /etc/systemd/system/data-nfs-R.mount /etc/systemd/system/r-ntfs.mount
server ❯ lsblk -no UUID /dev/sde1
8066D52E66D525A6
server ❯ sudo cat /etc/systemd/system/r-ntfs.mount
[Unit]
Description=My shared partition

[Mount]
What=/dev/disk/by-uuid/8066D52E66D525A6
Where=/r/ntfs
Type=ntfs
Options=defaults,rw,noatime

[Install]
WantedBy=multi-user.target
server ❯ sudo systemctl start r-ntfs.mount
Failed to start r-ntfs.mount: Unit r-ntfs.mount has a bad unit file setting.
See system logs and 'systemctl status r-ntfs.mount' for details.
server ❯ systemctl status r-ntfs.mount
× r-ntfs.mount - My shared partition
     Loaded: loaded (/etc/systemd/system/r-ntfs.mount; disabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sat 2022-07-16 14:50:32 CEST; 4min 26s ago
      Where: /r/ntfs
       What: /dev/disk/by-uuid/8066D52E66D525A6
        CPU: 4ms

jul 16 14:50:32 arch systemd[1]: Mounting My shared partition...
jul 16 14:50:32 arch mount[157246]: Mount is denied because the NTFS volume is already exclusively opened.
jul 16 14:50:32 arch mount[157246]: The volume may be already mounted, or another software may use it which
jul 16 14:50:32 arch mount[157246]: could be identified for example by the help of the 'fuser' command.
jul 16 14:50:32 arch systemd[1]: r-ntfs.mount: Mount process exited, code=exited, status=16/n/a
jul 16 14:50:32 arch systemd[1]: r-ntfs.mount: Failed with result 'exit-code'.
jul 16 14:50:32 arch systemd[1]: Failed to mount My shared partition.
server ❯ journalctl -xe
jul 16 14:50:32 arch mount[157246]: could be identified for example by the help of the 'fuser' command.
jul 16 14:50:32 arch systemd[1]: r-ntfs.mount: Mount process exited, code=exited, status=16/n/a
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░
░░ An n/a= process belonging to unit r-ntfs.mount has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 16.
jul 16 14:50:32 arch systemd[1]: r-ntfs.mount: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░
░░ The unit r-ntfs.mount has entered the 'failed' state with result 'exit-code'.
jul 16 14:50:32 arch systemd[1]: Failed to mount My shared partition.
░░ Subject: A start job for unit r-ntfs.mount has failed
░░ Defined-By: systemd
░░ Support: https://forum.manjaro.org/c/support
░░
░░ A start job for unit r-ntfs.mount has finished with a failure.
░░
░░ The job identifier is 2576 and the job result is failed.
jul 16 14:50:32 arch sudo[157230]: pam_unix(sudo:session): session closed for user root
jul 16 14:50:32 arch audit[157230]: USER_END pid=157230 uid=1000 auid=1000 ses=1 subj==unconfined msg='op=PAM:session_c>
jul 16 14:50:32 arch audit[157230]: CRED_DISP pid=157230 uid=1000 auid=1000 ses=1 subj==unconfined msg='op=PAM:setcred >
jul 16 14:50:32 arch kernel: audit: type=1106 audit(1657975832.587:430): pid=157230 uid=1000 auid=1000 ses=1 subj==unco>
jul 16 14:50:32 arch kernel: audit: type=1104 audit(1657975832.587:431): pid=157230 uid=1000 auid=1000 ses=1 subj==unco

The number one rule

mount point and mount unit name must match

You cannot use my example letter to letter.

You must uses you own UUID and you must use your path matching the unit name

mount point the Where/data/nfs/R

unit name → data-nfs-R.mount

My bad I fixed the error message.