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.