Skip to content

Instantly share code, notes, and snippets.

@JoryTony
Last active December 30, 2015 08:15
Show Gist options
  • Save JoryTony/dd8893bb115702b53dac to your computer and use it in GitHub Desktop.
Save JoryTony/dd8893bb115702b53dac to your computer and use it in GitHub Desktop.
NIX ex: forced directory replacements (mount bind)
# This is only meant as an example.
# If you are intending a permanent patch, you should just fix the directory structure.
# This tool is primarily for when alterations to the existing tree are impossible, or prohibitively demanding.
# Prep example folders and files
cd ~
mkdir bindTest
mkdir bindTest2
touch bindTest/file
touch bindTest2/file2
# replace the ref of one folder, to point to another
# similar to soft-links, almost an alias
# both paths will look like a real folder/files
# changes to either one will affect both (it is still just one folder)
# mount -o bind [source (abs)] [destination (abs)]
mount -o bind $(pwd)/bindTest2 $(pwd)/bindTest
mount | grep bindTest
ls -al bindTest
# you should see only file2
touch bindTest/file1-2
touch bindTest2/file2-2
ls -al bindTest
ls -al bindTest2
# you should see file2, file1-2, file2-2
umount $(pwd)/bindTest
ls -al bindTest
ls -al bindTest2
# all back to normal
# bindTest contains only: file
# bindTest2 contains: file2, file1-2, file2-2
# cleanup after ourselves
rm -rf bindTest
rm -rf bindTest2
@JoryTony
Copy link
Author

This is really only for when there's no other option (hard-links and softlinks).
I only found this particularly useful in two cases:

  • shared or networked folders without write permissions
    • for which write permission is needed on some subfolders, but only for local purposes.
    • changes in these folders will NOT be reflected in the share, but will only affect the local environment.
      • yes, it's an edge case
  • triage on a server with one full partition, and one nearly empty one.
    • be very careful in this instance, and it should only be a temporary stop-gap to get up and running TEMPORARILY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment