2

I want to create a chroot for a command that I'll run, and I want the chroot to be completely identical to the "real" filesystem, except for one altered file.

(Let's just assume that this is indeed the right way to approach my problem - I'm exploring other possibilities, too :)

One thing that seemed appealing was to use unionfs - basically have the "upper" directory contain the one file, and the "lower" one be root (/).

Alas, that doesn't work:

$ sudo mount_unionfs mydir /
mount_unionfs: mydir (/usr/home/myuser/chroots/mydir) and / (/) are not distinct paths

I can see why this could be problematic - maybe it would create infinite recursion? But I'm not entirely sure why it's prevented, to be honest.

I could accomplish something similar by having a slew of nullfs mounts inside mydir/..., to match everything mounted under / on my real system.

But is there a nicer way?

This is on FreeBSD, but other *nix advice appreciated, too.

jwd
  • 1,282
  • 8
  • 12
  • I don't have FreeBSD handy to test, but wouldn't something like this work? Nullfs from `/` to `/mychroot`, unionfs from `/somewhere/else` + `/overridden` to `/mychroot/overridden`, then chroot into `/mychroot` – Gilles 'SO- stop being evil' Jan 30 '17 at 23:23
  • @Gilles: I can't do `nullfs` for `/` either, alas - I get the same error: `...are not distinct paths`. – jwd Jan 31 '17 at 19:33

0 Answers0