# Sharing directory between 2 NFS mounts



## Simba7 (Oct 1, 2013)

Basically, what I'm trying to do is have /usr/ports and /usr/portage (for my Gentoo installs) sharing a single distfiles directory. So far, I have:


```
/usr/ports
/usr/portage
/usr/distfiles

mount_nullfs /usr/ports/distfiles /usr/distfiles
mount_nullfs /usr/portage/distfiles /usr/distfiles
```
Unfortunately, NFS doesn't seen to like this because it's saying "access denied" whenever I try to access the /usr/*/distfiles directory. I was wondering if I'm doing something wrong or if there is a setting I missed.

I'm utilizing ZFS on all the filesystems.


----------



## ShelLuser (Oct 1, 2013)

Simba7 said:
			
		

> mount_nullfs /usr/ports/distfiles /usr/distfiles
> mount_nullfs /usr/portage/distfiles /usr/distfiles
> 
> Unfortunately, NFS doesn't seen to like this because it's saying "access denied" whenever I try to access the /usr/*/distfiles directory.


Quite frankly that setup won't work either way, NFS or not.

Because you can't just combine mountpoints, at best the new mount will replace the previous one. You can see for yourself if you use nullfs to mount a directory somewhere and then use the same mountpoint to mount another directory (also using nullfs).

You'll notice that you won't end up with a combination but will end up with the second directory. The moment you unmount it the first will show up after which you're back to where you started. This seems no different.


----------



## Simba7 (Oct 1, 2013)

I was able to do this in Gentoo (utilizing `mount --rbind`) without issues. Here's a section of my /etc/fstab on the Gentoo-powered WD MyBook Live:


```
/dev/sda5               /mnt/hddp2      ext4            defaults        0 0
/mnt/hddp2/distfiles    /mnt/hddp2/gentoo/distfiles     none    rw,rbind        0 0
/mnt/hddp2/distfiles    /mnt/hddp2/freebsd/distfiles    none    rw,rbind        0 0
/mnt/hddp2/gentoo       /usr/portage    none            rw,rbind        0 0
```

I have both /mnt/hddp2/gentoo and /mnt/hddp2/freebsd exported via NFSv3 and NFS seems to like this (for some weird reason). I'm just trying to do the same on FreeBSD.

BTW: I'd switch the MBL to FreeBSD if I could. There's a[]lot of proprietary code for the APM82181 processor (PPC464 compatible) in the kernel, so I'm stuck with Linux 2.6.32.60 for now.


----------



## SirDice (Oct 2, 2013)

Try mounting them the other way around.

`mount -t nullfs /usr/distfiles /usr/ports/distfiles`
`mount -t nullfs /usr/distfiles /usr/portage/distfiles`


----------



## Simba7 (Oct 2, 2013)

That is working perfect locally, but NFS ignores the distfiles mountpoint.

EDIT: I mounted /usr/ports on a different system and it seems to completely ignore the NULLFS mountpoint. I can create files in /usr/ports/distfiles on a remote system, but they only show up on the physical directory, not the NULLFS mount.


----------



## SirDice (Oct 2, 2013)

You should be able to export /usr/portage/distfiles and /usr/ports/distfiles now.


----------



## Simba7 (Oct 3, 2013)

SirDice said:
			
		

> You should be able to export /usr/portage/distfiles and /usr/ports/distfiles now.


If that were the case, I'd just export /usr/ports, /usr/portage and /usr/distfiles separately.

I wanted to just mount a single NFS mountpoint and have access to the distfiles directory within, which should be mounted via NULLFS to /usr/distfiles.


----------



## ShelLuser (Oct 3, 2013)

Maybe a strange idea, but I'll share anyway.

What about setting up /usr/distfiles (personally I'd rather use /opt/distfiles but your mileage may vary). Then create two subdirectories: freebsd and gentoo. nullfs should now be usable to assign these to their regular location (so I could imagine doing `# mount -t nullfs /opt/distfiles/freebsd /usr/ports/distfiles`). Now the only thing left to do is the NFS export. If you use -alldirs then an NFS client should be able to directly mount a child directory. Or, from the exports(5) manualpage:



> The second is to specify the pathname of the root of the file system fol-
> lowed by the -alldirs flag; this form allows the host(s) to mount at any
> point within the file system, including regular files if the -r option is
> used on mountd(8).


So now you have one NFS export which should be usable by multiple clients... or at least I think so


----------

