Score:0

umount2() for an NFS mountpoint returns EPERM, even when called as root

ro flag

I'm running Ubuntu 20.04, but I've had this problem back to Ubuntu 14.04.

I've been trying to automate unmounting NFS mounts when my VPN connection closes, but no matter how I call "umount", I get "Operation not permitted" even though I'm running with root privileges. I thought it would be easier to diagnose the issue if I just wrote a small stand-alone program to do the unmounting:

int main(int argc, char **argv)
{
 int rc; 

   rc = setuid(0); 
   printf("setuid: rc %i, %s\n", rc, strerror(errno));

   rc = umount2(argv[1], MNT_FORCE | MNT_DETACH); 
   printf("umount2: rc %i, %s\n", rc, strerror(errno));

   return 0;
}

When I run this in a shell session, I get exactly what I expect:

setuid: rc 0, Success
umount2: rc 0, Success

When I run it in a script triggered by my VPN software (OpenVPN), I get this:

setuid: rc 0, Success
umount2: rc -1, Operation not permitted

The setuid() call works, so I know I'm running as root (and in fact, the program is called already running as root, so this shouldn't be required anyway).

What other permission would umount2() be looking for that's not just UID 0?

David avatar
cn flag
The only version of Ubuntu mentioned in this question is a long gone EOL version 14.04. What version of Ubuntu are you currently using?
Vince avatar
ro flag
Sorry - we're on 20.04
I sit in a Tesla and translated this thread with Ai:

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.