10

Is there a possibility to create a hard link for an unix socket? I'm creating a jail and symbolic links won't work, so I'm looking for a solution, how to provide an unix socket inside chrootted environment.

The only idea I'm coming across is to use something like netcat but is there any reliable possibility?

eRIZ
  • 220
  • 2
  • 10
  • 5
    I'm not sure why this is marked as a duplicate. The other question just asks about creating listening sockets in the filesystem, this one is about duplicating them. – Will Manley Jul 04 '17 at 08:09
  • 3
    Agreed, if I had the rep I would be casting a reopen vote here. – Peter Green Oct 19 '17 at 14:35

1 Answers1

6

Linux at least would allow you to use a bind mount to make either a directory or alternatively a single file available at multiple places.

  # mount --bind /var/MySQL.sock /chroot/var/MySQL.sock 
Xunnamius
  • 103
  • 4
HBruijn
  • 72,524
  • 21
  • 127
  • 192
  • Bind works only for directories, so it doesn't solve the problem. – eRIZ Apr 17 '14 at 20:26
  • In the words of the man page `One can also remount a single file (on a single file)`, and I have no problems accessing the MySQL daemon through the socket in the bind mount. But I don't have any chroot set up to test more. – HBruijn Apr 18 '14 at 12:57
  • Parameter list consist on two directories. I mean mounting a link directly, without separated directory. Could you provide your command line I can test against? Is this the above you cited? I tried to make it happen but this doesn't work. – eRIZ Apr 18 '14 at 17:56
  • You can also put the socket in a directory created for this purpose, and bind mount that. – Falcon Momot Apr 18 '14 at 18:43
  • @FalconMomot, I know but I want to solve problem. I'm aware of a workaround. [; – eRIZ Apr 18 '14 at 21:55
  • How does that not solve the problem? Bind the directory the socket goes in, see to it that it goes in there, and you're done. – Falcon Momot Apr 19 '14 at 03:58
  • Doesn't solve - it enforces me creating a separated directory for various set of sockets. I want to specify it more flexible, so is that why I asked for a particular link for a socket if it's possible. – eRIZ Apr 19 '14 at 14:15
  • 1
    I know Docker uses single file bind mounts, but the bind command does not accept them. (And your mount command parameters is wrong, it is `--bind` or `-t none -o bind`) – Gert van den Berg May 24 '19 at 09:40
  • 1
    HBruijn's is the correct answer (with @GertvandenBerg's fix). Thanks for this! See: http://www.mardy.it/blog/2018/10/how-to-bind-mount-single-file.html – Xunnamius May 09 '20 at 09:28