I am trying to bind mount one file over another file, then remove the file that is now hidden from access. I'm trying to go about this as follows:

folder1# echo a > a
folder1# echo b > b
folder1# mount -o bind a b
folder1# cat b
a #All good - the bind mount worked
folder1# cd ..
# mount -o bind folder1 folder2
# cd folder2
folder2# cat b
b #OK, as expected
folder2# unlink b
rm: cannot remove 'b': Device or resource busy

I want to delete b from the actual disk, but leave the bindmount from a active.

So if it worked, it would go like

# cd folder2
folder2# cat b
folder2# unlink b
folder2# cat b
cat: error: No such file or directory
folder2# cd ../folder1
folder1# cat b
a #The bind mount is still active

How can I make Linux behave how I want?

  • Simplest way is write your own filesystem that allows that behavior. – stark Nov 9 '18 at 15:05
  • @stark Unfortunately not an option; it needs to work on android (rooted of course), and some devices are really messed up and don't allow installation of unsigned kernel modules – Penn Nov 9 '18 at 15:12
  • 1
    Actually, it looks to be dependent on kernel version: lwn.net/Articles/570338 – stark Nov 9 '18 at 15:15
  • @stark 3.13... I'm running 4.9 on my PC and still seeing this behaviour. – Penn Nov 9 '18 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.