2

The kernel contains a filesystem, nsfs. snapd creates a nsfs mount under /run/snapd/ns/<snapname>.mnt for each installed snap. ls shows it as a 0 byte file.

The kernel source code does not seem to contain any documentation or comments about it. The main implementation seems to be here and the header file here.

From that, it seems to be namespace related.

A search of the repo does not even find Kconfig entries to enable or disable it...

What is the purpose of this filesystem and what is used for?

4

That's the "Name Space File System", used by the setns system call and, as its source code shows, Name Space related ioctl's (e.g. NS_GET_USERNS, NS_GET_OWNER_UID...)

NSFS pseudo-files entries used to be provided by the /proc file system until Linux 3.19. Here is the commit of this change.

See Stephen Kitt's comment about a possible explanation about this files presence.

  • You’re welcome! Regarding the underlying question in the question, I suspect (but I’m not 100% sure) that the reason snap bind-mounts those files is so that the corresponding namespace will be kept even when it has no running process. – Stephen Kitt Aug 30 '18 at 8:48
  • Other example ip netns commands mount net namespaces to keep them up without process. Example of use: to have a bridge staying in its own namespace without any iptables/ebtables/nftables interaction from other namespaces (it can still have its own ebtables rules, its own vlan settings etc.). This bridge is then linked to other namespaces with veth pairs – A.B Sep 2 '18 at 22:46
  • This series of articles on what kernel namespaces are also seems relevant: lwn.net/Articles/531114/#series_index – Gert van den Berg Sep 25 '18 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.