# NFSv3 Different client user mapping despite mount from identical devices



## malbec (Nov 17, 2020)

Hello all,

I have a set of diskless clients that I want to run off of TFTP + NFS / PXEBOOT

To achieve this I have set up an install medium that boots the device , executes a script under systemd(linux) that mounts my FreeBSD 12.1 server and starts copying the files to their new roots.

For some strange reason, this works for half of them. Half of them have all the permissions and users set correctly when the rsync -xav copies the files, the other half does not. Reinstalling is non-deterministic in the sense that the identical client might install correctly one time, but fail the other.

In the correct case, the system mounts NFS and copies everything using PID:GID 0:0 , in the wrong cases my files and folders are created using my FBSD user 1001:1001, my linux devices do not have a user 1001 and BSD doesnt have 1000; so differences are easy to spot.
I use a single install medium, so it is impossible that there are differences in client configurations, but for some reason the outcomes are different.

Can anyone tell me what can cause NFS mounting and file copy/creating to occur under the wrong host user?

obligatory /etc/exports file:

```
# /etc/exports
/nfs -maproot=root -alldirs -network 192.168.88.2 -mask 255.255.255.0
```

rc.conf:

```
nfs_server_enable="YES"
nfs_server_flags="-t -u -h 192.168.88.250 -n 128" 
mountd_enable="YES"
rpcbind_enable="YES"
rpc_lockd_enable="YES"
rpc_statd_enable="YES"
```


----------



## SirDice (Nov 17, 2020)

NFSv3 only looks at the numerical UID/GID, it is therefor imperative that all your accounts have the same UID/GID everywhere. With NFSv4 there is no such limitation as nfsuserd(8) will translate accounts by name to their correct uid/gid for that machine.


----------



## malbec (Nov 17, 2020)

I'm aware of this shortcoming in NFSv3, but would therefore at least expect it to fail consistently in my use case


----------



## SirDice (Nov 17, 2020)

Let me try to get your situation correct in my head. On the NFS server's filesystem the files all have the correct uid/gid. You boot a client system using PXE. That client system mounts the /nfs share locally and copies files from it using rsync to a local filesystem. Is that the correct process?

On the client, before the rsync, can you see what uid/gid the files have on the locally mounted NFS share? Do they look correct? Is the rsync always being run as root?


----------



## malbec (Nov 17, 2020)

Other way around! NFS is completely empty at the beginning.

Client boots from SD card and automatically kicks off a script under root user
script mounts NFS, creates a directory based on clients MAC / IP and rsync (using -a option) its files from the install media to NFS.

I do this on PC1 and it creates a directory on NFS using UID:GID 0:0
I move the SD card to pc2 and run the same thing, but it creates the folder and files under 1001:1001

My linux based SD card does not contain a user 1001, so I fail to understand how the new directory gets this ID from my BSD user.


----------



## SirDice (Nov 17, 2020)

Right. Now I have a better idea of the process. The direction of the copy process is rather important 



malbec said:


> I do this on PC1 and it creates a directory on NFS using UID:GID 0:0
> I move the SD card to pc2 and run the same thing, but it creates the folder and files under 1001:1001


What's being copied from PC1 and PC2? Are those existing files and directories from the PC itself? Are they the same on each PC? Or do the originals all come from that SD card? If the original files on PC1 are 0:0 but on PC2 1001:1001 then rsync would just copy those uid/gid to the NFS share.


----------



## malbec (Nov 17, 2020)

the linux rootfilesystem is what I copy, with some exclusions so I don't recursively copy NFS etc.
They're the exact same, because I used the same SD card for both pcs.

I've included the script, for reference:


----------

