Score:0

Mount nfs at startup as specific user, and allow unmount?

fr flag

I am using:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:    20.04
Codename:   focal

$ mate-about --version
MATE Desktop Environment 1.24.0

... as an NFS client.

I have an nfs4 share on the server; my entry in /etc/fstab on the client is like this:

172.16.0.5:/mydata /media/user/mydata_nfs nfs4 nosuid,nodev,nofail,x-gvfs-show,rw,relatime,user,noauto,uhelper=udisks2 0 0

I have manually created the /media/user/mydata_nfs, which at start has these permissions:

$ ls -la /media/user/
total 20
drwxr-x---+ 5 root          root          4096 Jul 25 15:56 .
drwxr-xr-x  3 root          root          4096 Jul 19 18:43 ..
...
drwxr-xr-x  2 user          user          4096 Jul 25 12:11 mydata_nfs

The above fstab entry allows that the share is not mounted at startup, and so I manually have to click in the "file explorer" GUI (here caja), to do so; however, once the share is mounted, the ownership (and timestamp) changes:

$ ls -la /media/user/
total 20
drwxr-x---+ 5 root          root          4096 Jul 25 15:56 .
drwxr-xr-x  3 root          root          4096 Jul 19 18:43 ..
...
drwxrwxrwx  6 root          root          4096 Jul 29 06:15 mydata_nfs

On the NFS server, no_root_squash is enabled; as I understand it, in that case UID/GID from client user is propagated to server, and since on server I also have user with uid:gid of 1000:1000 (as on client), this works fine for me (when I create files, etc, inside the share from the command line on client, ownership of user is kept on the share) - except for the mount point on client being owned by root (which causes me problems: some programs installed by snap will not even list the share as a directory).

Also - even with the above fstab line (which requires me to mount manually), when I try to unmount from the GUI, I cannot, and I get a dialog with:

Unable to unmount mydata_nfs
Error finding object for block device 0:56

So, what I'd like to have is:

  • NFS share to be automatically mounted at startup - with user owning the share
  • Allow for user to unmount the share from the GUI

Is this possible at all - and what would be the right fstab line to have that?


Note that uid fstab option (which otherwise does this kind of mapping for ntfs) does not work here - syslog will complain:

Jul 29 07:03:49 mypc mount[1148]: mount.nfs4: an incorrect mount option was specified
Jul 29 07:03:49 mypc kernel: [   17.179641] nfs4: Unknown parameter 'uid'
Jul 29 07:03:49 mypc systemd[1]: media-user-mydata_nfs.mount: Mount process exited, code=exited, status=32/n/a
Jul 29 07:03:49 mypc systemd[1]: media-user-mydata_nfs.mount: Failed with result 'exit-code'.
Jul 29 07:03:49 mypc systemd[1]: Failed to mount /media/user/mydata_nfs.

Also allow_other is unknown parameter for NFS.

Score:0
fr flag

Ok, got a bit further, this is what I tried:

After /media/user/mydata_nfs was manually mounted (from the caja GUI), and showed up as owned by root (as in the OP), I did:

sudo chown user:user /media/user/mydata_nfs

... and indeed, this did change the ownership - which I expected to be temporary (for current session only) at first. Since I cannot unmount from the GUI, I did reboot, and then at next boot, mounted the partition manually (from caja GUI) again. I was quite surprised to see that this was remembered, so now in the listing I have:

$ ls -la /media/user/
total 20
drwxr-x---+ 5 root          root          4096 Jul 25 15:56 .
drwxr-xr-x  3 root          root          4096 Jul 19 18:43 ..
...
drwxrwxrwx  6 user          user          4096 Jul 29 08:05 mydata_nfs

So for some reason, this change in ownership of the mounted NFS partition persists - which is nice, as it suits my use case.

Then, I simply removed the noauto from the /etc/fstab entry - and now I have the partition mounted at boot, with user being shown as the owner - which is exactly how I want it.

It turns out, however, that this is not enough to get software installed by snap to use it - as noted in Snap application doesn't see files from another partition :

Snaps are typically confined. By default snaps can access nothing but their own writable areas, but they can gain permissions by way of interfaces. There are two interfaces that provide the ability to access files beyond the default: the home interface, and the removable-media interface. ...

So what worked for me in that case, was a mount with bind, as answered in that post:

$ mkdir ~/mydata_nfs
$ sudo mount --bind /media/user/mydata_nfs ~/mydata_nfs

... and then pointing the snap software to read/write files in ~/mydata_nfs.


This solved most of my problems, except for the unmounting of the NFS share from the GUI - so I'd still love an answer to that, if anyone knows how to do it ...

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.