Loading ...
Sorry, an error occurred while loading the content.

BIND mounts for Linux

Expand Messages
  • Thad Floryan
    Read up first: http://docs.1h.com/Bind_mounts http://backdrift.org/how-to-use-bind-mounts-in-linux Why would one want to use it? Think about it for a moment.
    Message 1 of 4 , Mar 19 5:41 PM
    • 0 Attachment
      Read up first:

      http://docs.1h.com/Bind_mounts

      http://backdrift.org/how-to-use-bind-mounts-in-linux

      Why would one want to use it? Think about it for a moment. If
      you have a directory /home and then mount something as /home, all
      files that were in /home are "no longer accessible" unless one does
      a bind mount. When you umount the filesystem that overlayed /home,
      all of /home's contents are again accessible and visible.

      Here's a copy'n'paste of two articlesfrom several of the 100s of Usenet
      linux groups recently:

      " He doesn't need to unmount it in order to get to the obscured
      " contents. All he needs to do is bind-mount the root directory to
      " another directory such as /mnt, and then he can access the files
      " in /home which are still on the root filesystem.

      and

      " >> He doesn't need to unmount it in order to get to the obscured
      " >> contents. All he needs to do is bind-mount the root directory to
      " >> another directory such as /mnt, and then he can access the files in
      " >> /home which are still on the root filesystem.
      " >
      " > I don't get it. What does the OP mean by saying the contents are
      " > obscured?
      " >
      " > I can access any file on my machine I want to.
      " >
      " > (Some require root access.)
      "
      " Well, okay, suppose you have your root filesystem, and you have a
      " second, separate filesystem for (the contents of) /home. The directory
      " /home itself exists as an inode on the root filesystem, and as a
      " directory entry in the root directory. The files *inside* /home are on
      " the second filesystem.
      "
      " Now, when the filesystem for /home is mounted, any files that were
      " *already present* in the /home directory *before the mount* will be
      " obscured *by* the mount. You will no longer have (direct) access to
      " those files for so long as the second filesystem is mounted on /home.
      " Once you unmount the second filesystem from /home again, you can see and
      " manipulate the original files in the /home directory, because those are
      " files which reside on the root filesystem itself.
      "
      " A way to get around this is to bind-mount *the root directory* - note:
      " _not the root filesystem_ - to another, empty directory, e.g. /mnt, and
      " by then descending into /mnt/home, you can access those obscured files
      " again, because the second filesystem isn't being bind-mounted along with
      " the root directory (even though this too is possible with the proper
      " bind-mount options).
      "
      " Quoting from the /bin/mount man page - reformatted for readability...:
      "
      " [/QUOTE]
      "
      " The bind mounts.
      " Since Linux 2.4.0 it is possible to remount part of the file
      " hierarchy somewhere else. The call is
      "
      " mount --bind olddir newdir
      "
      " or shortoption
      "
      " mount -B olddir newdir
      "
      " or fstab entry is:
      "
      " /olddir /newdir none bind
      "
      " After this call the same contents is accessible in two places.
      " One can also remount a single file (on a single file).
      "
      " This call attaches only (part of) a single filesystem, not
      " possible submounts. The entire file hierarchy including submounts
      " is attached a second place using
      "
      " mount --rbind olddir newdir
      "
      " or shortoption
      "
      " mount -R olddir newdir
      "
      " Note that the filesystem mount options will remain the same
      " as those on the original mount point, and cannot be changed by
      " passing the -o option along with --bind/--rbind. The mount
      " options can be changed by a separate remount command, for
      " example:
      "
      " mount --bind olddir newdir
      " mount -o remount,ro newdir
      "
      " Note that behavior of the remount operation depends on the
      " /etc/mtab file. The first command stores the 'bind' flag to
      " the /etc/mtab file and the second command reads the flag from
      " the file. If you have a system without the /etc/mtab file or if
      " you explicitly define source and target for the remount command
      " (then mount(8) does not read /etc/mtab), then you have to use
      " bind flag (or option) for the remount command too. For example:
      "
      " mount --bind olddir newdir
      " mount -o remount,ro,bind olddir newdir
      "
      " [/QUOTE]
      "
      " By consequence, if ########## has files that ended up in /home before
      " the /home filesystem was mounted and he needs to access those files - I
      " will use "ls" as the action to perform for the sake of an example - then
      " he will have to issue the following commands...
      "
      " $ sudo mount --bind / /mnt
      " $ cd /mnt/home
      " $ ls
      "
      " Now, say that he wants to move those files into the mounted /home
      " filesystem. He can do that as follows...
      "
      " $ sudo mv /mnt/home/* /home/.
      "
      " The period after the last slash is not needed, but I am typing it here
      " because many newsreaders interpret a word between two slashes as a
      " formatting with an italicized font, and the period, when used on the
      " command line like this, will not affect the working of the command. It
      " is still correct shell syntax.
      "
      " Also note that it is probably safer to not move those files to /home
      " directly (because they may overwrite newer files), but to instead
      " temporarily park them under /tmp or some other directory.
      "
      " Then, when all is done, he can unmount the bind-mount again, like so...
      "
      " $ sudo umount --bind / /mnt

      Thad
    • Matt Bailey
      On Wed, 19 Mar 2014 17:41:14 -0700 ... This is slick, thanks for sharing! I did not know of such a thing. I can see how someone could get in trouble with this
      Message 2 of 4 , Mar 19 8:50 PM
      • 0 Attachment
        On Wed, 19 Mar 2014 17:41:14 -0700
        Thad Floryan <thad@...> wrote:

        > Read up first:
        >
        > http://docs.1h.com/Bind_mounts
        >
        > http://backdrift.org/how-to-use-bind-mounts-in-linux
        >
        > Why would one want to use it? Think about it for a moment. If
        > you have a directory /home and then mount something as /home, all
        > files that were in /home are "no longer accessible" unless one does
        > a bind mount. When you umount the filesystem that overlayed /home,
        > all of /home's contents are again accessible and visible.

        This is slick, thanks for sharing! I did not know of such a thing. I
        can see how someone could get in trouble with this if used improperly
        (by ending up with a large, disorganized "web" of multiple-mounted
        directories, symlinks, and bind-mounts)...but that's Linux, it
        gives you the tools and the capability to do wonders, including hanging
        yourself. :P

        Linux, table saws, airplanes, and guns: four things that have huge
        potential to be awesome when used right, or get you in trouble if used
        wrong. :)

        Matt
      • Thad Floryan
        Matt Bailey wrote ... Hi Matt, Neither did I and I m sure you know I ve used both UNIX and Linux since their respective Day 1s. That was today s Learn
        Message 3 of 4 , Mar 20 12:16 AM
        • 0 Attachment
          Matt Bailey wrote
          > > On Wed, 19 Mar 2014 17:41:14 -0700 Thad Floryan <thad@...> wrote:
          > > Read up first:
          > > http://docs.1h.com/Bind_mounts
          > > http://backdrift.org/how-to-use-bind-mounts-in-linux
          > > [...]
          >
          >This is slick, thanks for sharing! I did not know of such a thing.

          Hi Matt,

          Neither did I and I'm sure you know I've used both UNIX and Linux since
          their respective Day 1s.

          That was today's "Learn something new every day" topic. :-)

          That's why I use Usenet for it's worldwide body of knowledge and why I'm
          still so PO'd at the Yahoo idiots who hosed Yahoo Groups with NEO ruining
          our message archives that go back to January 1998.

          They are still mucking with NEO and worsening it further -- they added
          "Use fixed-width font" by simply replacing the proportional font with a
          fixed-width font without any knowledge of how it used to be, so all our
          code, script and table examples in the message archives are unreadable
          because all spaces and tabs are compressed down to one.

          Last I could verify (during the 24-hour period last October when the old
          interface could be used on the sly) the "raw" message database it still
          OK, but the idiot incompetent Yahoo H1-B Visa types doing the NEO coding
          have no idea how to code properly and this group's messahes archives are
          still garbaged when NEO retrieves messages from it.

          And whatever they did to do that now locks up Firefox and I had to kill
          the running-wild process while attempting to read our group messages so
          that means I won't be reading them much anymore. I will check to see
          if IE on one of my Windows boxes will work with Yahoo.

          I haven't logged in to Yahoo in a long time (meaning my account will soon
          expire), and when I start receiving bounced email after posting to linux
          due to an expired account that'll be it -- no more posts from me.

          Feel welcome to start using Usenet (100s of Linux groups there though
          many are regional) which I've been using since its 1981 beginnings.

          > I can see how someone could get in trouble with this if used improperly
          > (by ending up with a large, disorganized "web" of multiple-mounted
          > directories, symlinks, and bind-mounts) ... but that's Linux, it
          > gives you the tools and the capability to do wonders, including hanging
          > yourself. :P

          Heh! Even the find command can be subtly dangerous with '-exec' if
          one is sudo'd and not mindful of $PWD.

          > Linux, table saws, airplanes, and guns: four things that have huge
          > potential to be awesome when used right, or get you in trouble if used
          > wrong. :)

          For those who've forgotten and/or need a laugh:

          http://thadlabs.com/FILES/Tools_and_how_to_use_them_HUMOR.pdf 358kB

          BTW, and off-topic, but since you mentioned airplanes ...

          Latest news has the Malaysian 777 landed in Pakistan. The excursion to
          45,000 feet during the hijack was to kill passengers since the crew in
          the cockpit have special oxygen equipment. Also note Pakistan has nuke
          capability they've already demonstrated [1], think back to the WTC 9/11,
          and a fully-fueled 777 can fly to almost anywhere that's "interesting".

          BTW, US news media is censored and manipulated which is why I don't cite
          MSM (Main Stream Media) for anything important.

          Thad

          [1] http://en.wikipedia.org/wiki/Pakistan_and_weapons_of_mass_destruction#Development_of_nuclear_weapons
        • Thad Floryan
          I dislike typos noting I type so fast I m often lines ahead and don t notice them until later if I bother to re-read before posting, so ... ... its ...
          Message 4 of 4 , Mar 20 12:25 AM
          • 0 Attachment
            I dislike typos noting I type so fast I'm often lines ahead and don't
            notice them until later if I bother to re-read before posting, so ...

            On 3/20/2014 12:16 AM, Thad Floryan wrote:

            > That's why I use Usenet for it's worldwide body of knowledge and why I'm
            its

            > have no idea how to code properly and this group's messahes archives are
            messages archive
          Your message has been successfully submitted and would be delivered to recipients shortly.