Create a link to the Unix socket

6,427

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 
Share:
6,427

Related videos on Youtube

eRIZ
Author by

eRIZ

Updated on September 18, 2022

Comments

  • eRIZ
    eRIZ over 1 year

    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
    eRIZ about 10 years
    Bind works only for directories, so it doesn't solve the problem.
  • HBruijn
    HBruijn about 10 years
    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.
  • eRIZ
    eRIZ about 10 years
    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.
  • Falcon Momot
    Falcon Momot about 10 years
    You can also put the socket in a directory created for this purpose, and bind mount that.
  • eRIZ
    eRIZ about 10 years
    @FalconMomot, I know but I want to solve problem. I'm aware of a workaround. [;
  • Falcon Momot
    Falcon Momot about 10 years
    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.
  • eRIZ
    eRIZ about 10 years
    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.
  • Gert van den Berg
    Gert van den Berg almost 5 years
    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)
  • Xunnamius
    Xunnamius about 4 years
    HBruijn's is the correct answer (with @GertvandenBerg's fix). Thanks for this! See: mardy.it/blog/2018/10/how-to-bind-mount-single-file.html