1

So I have /usr as 'ro' filesystem (cannot change that, work rules and security) and I have another directory /bigdata which is 'rw'.

I'm installing some services but it needs to write in /usr/foo, so I thought I could symlink to /bigdata. The problem is I have other files in /usr/foo.

Is there a workaround for this that doesn't include copying all content of fooinbigdata?

Thanks!

  • Sounds like you might be interested in OverlayFS. – Ulrich Schwarz Mar 2 '17 at 13:43
  • For logical separation of the data, a dedicated directory might be wise to do, in addition to simplifying the filesystem management. Or just symlink all the files... The question is also what OS you are on, different systems may have different "advanced" features. – ilkkachu Mar 2 '17 at 13:49
  • As /usr is on a ro filesystem, how would you want to create a symlink there? – ridgy Mar 2 '17 at 14:23
1

One idea would be to override /usr/foo but only for the misbehaving application. The misbehaving application would see /usr/foo as an alias for /bigdata but every other process in the system would continue to see /usr/foo's real contents including the files that are actually in there. This assumed the misbehaving application doesn't care that the normal contents of /usr/foo are inaccessible to it.

sudo unshare --mount sh -c 'mount --make-rprivate / &&
    mount -n --bind /bigdata /usr/foo &&
    exec su "$SUDO_USER" -c misbehaving_application'

(Tested)

Otherwise, OverlayFS might solve your problem, as suggested in the comments.

Finally, as a last resort, some symlink gymnastics can do the trick. The idea would be to:

  • bind mount a copy of /usr/foo somewhere else

    mkdir /writable/place/foo
    mount --bind /usr/foo /writable/place/foo
    
  • Squash /usr/foo with your replacement directory

    mount --bind /bigdata /usr/foo
    
  • Symlink the existing files so they can be accessed from /usr/foo

    for x in /writable/place/foo/*; do
      ln -s "$x" /usr/foo
    done
    

(Not tested)

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.