FedoraForum.org - Fedora Support Forums and Community
Results 1 to 9 of 9
  1. #1
    Join Date
    Oct 2004
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Yet another warning about mount --bind and rm -rf

    I have read many many warnings about mount --bind and also rm -rf. I want to contribute to this corpus and also include some ideas so that if you ever feel posessed to use mount --bind, you might be saved alot of trouble with some alternatives and reminder ideas.
    mount --bind
    It's not as bad as ballancing your margarita on your laptop keyboard or trying to sit on a stack of precariously balanced running server towers wound in knots of network cable but it is n VERYs bad, n in proportion to the importance of the files that you are translocating.


    Mount --bind is not a "neat" feature. It is a messy feature that will entangle the directory tree you have come to presume and rely on ! ! ! MESSY ! !

    Do you really need to mount --bind ???

    It's handy but do you need exactly the same files and directories in two places hot and live prehaps shared by two processes or more???
    Does the same file really need to be in two places on the tree? Won't a copy do?
    Try using cp -a instead !! SO if you think "mount --bind" then please think "cp -a ??" ! !
    Addtionally think "ln -s ??? !!!!!"
    Another option to mount --rebind is to use a symlink to the directory.
    Why is that safer?
    The symbolic link will not be followed in recursion from something like rm -rf but the rebound directory will. Everything below the rebound directory will be deleted in it's original location as well. In the case of the symlink only the symlink will go away.

    Code:
    mount --bind      ==>  cp -a
    mount --bind      ==>  ln -s
    If you must do so for good reason or nerdenity consider the following sugestions.
    There is no astrisk, bold print, or warning on the parent directories where you have transloacted files. You need to create reminders for yourself if the files are important! !
    If you can, rename containing directories with the original name of the remounted directory name or a note appended like:
    Code:
    foo_bin
     or 
    testdir_mountbound
    where you have for example mount --bind bin foo_bin/bar/bin
    Put a POSTIT on your monitor and a stickynote on your desktop to remind you of the new dual tree location of the important files.
    Don't assume that you will remember to unmount and clean up during the same session at the computer. Something will come up that will require your attention and you may forget and need to pick up where you left off later. I Put these reminders just before or after your mount --bind. If you use a personal activity log consistantly then you probably already have a system for messythings like mount --bind. I am currently in no such habbit.


    rm -rf
    First I am a fan. I must admit It is tremendously useful and exactly what is needed now and then. As is well known on most linux file systems (unionfs aside) there is no undo, no rollback and no unrm or undelete. No safty net for your rm -rf.
    That being said why not try:
    Code:
    ls -Rm
    before your rm -rf.

    This will let you browse your directory recursivly to doulbe check that you know what you are about to erase. It will remind you of forgotten ( desparite and depraved) mount --bind situations.

    If you've used mount --bind then also do
    Code:
    mount
    and look to see if your tree is effected before you rm -rf.

    Note that I have not inclued any rm -i prostializing crap here. If you are not seaoned and are at all nervous with the command line then please have fun with rm -i and never use rm -rf. Several minutes of typeing 'Y' is better than hours required for data recovery, restoration, reinstallation or reproduciton. That being said I believe ls -Rm , mount, inspect thouse results and then rm -rf is a good alternative and I may write a script that does this for myself, one that requires typing 'y' 'e' 's' rather than just y but only once for the whole shabang.


    ************

    Zarthon is a shlemiel living in Boston. He has been using linux for many years and has read 10000 warnings on mount --rebind and rm -rf used independently and together but recently used mount --rebind on /etc and then blew it out two days later with rm -rf ! ! Fortunately it was his own workstation. He also has other computers to use in the meantime.
    Last edited by zarthon; 13th March 2007 at 11:10 AM. Reason: clarity

  2. #2
    Join Date
    Nov 2015
    Location
    Home
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    Quote Originally Posted by smr5e4
    What I do is put a bunch of ISO files in my home directory and name it aaaiso. That way if I do rm -rf in the wrong place, I'll notice it's taking more time than it should and hopefully stop it before it does too much damage.

    In a perfect world, no one ever does it in the wrong place--in practice, I suspect many do it at least once.
    Wish I had read this "never use rm -rf. Several minutes of typeing 'Y' is better than hours required for data recovery, restoration, reinstallation or reproduciton." 3 hours ago lol. Thanks for this helpful post.
    Last edited by FedAro; 23rd July 2025 at 03:24 PM.

  3. #3
    Join Date
    Jan 2015
    Location
    Lab, Slovakia
    Posts
    908
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    I actually like the fact that UNIX doesn't try to protect one against oneself.
    --
    Have fun!
    http://www.aeronetworks.ca

  4. #4
    Join Date
    Dec 2007
    Location
    Australia
    Posts
    1,904
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    I actually like the fact that UNIX doesn't try to protect one against oneself.
    Yes. Nevertheless you have a choice. You can alias your critical commands so that you get asked before you actually execute them. You can arrange for yourself to get a second chance with something like the following in .bashrc:
    Code:
    alias rm='rm -i'
    alias cp='cp -i'
    alias mv='mv -i'

  5. #5
    Join Date
    Jan 2015
    Location
    Lab, Slovakia
    Posts
    908
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    and the problem isn't really "rm -rf" - the thing that catches people unawares is that the wildcard "*" includes "."
    --
    Have fun!
    http://www.aeronetworks.ca

  6. #6
    Join Date
    Dec 2007
    Location
    Australia
    Posts
    1,904
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    Yes again. And there's a big difference a space can make if you point to a directory where you want to remove all the files:
    Code:
    rm -rf /dir/*
    compared to:
    Code:
    rm -rf /dir/ *
    Been there, done that, not good.

  7. #7
    Join Date
    Jan 2010
    Posts
    8,687
    Mentioned
    41 Post(s)
    Tagged
    0 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    What I do is put a bunch of ISO files in my home directory and name it aaaiso. That way if I do rm -rf in the wrong place, I'll notice it's taking more time than it should and hopefully stop it before it does too much damage.

    In a perfect world, no one ever does it in the wrong place--in practice, I suspect many do it at least once.

  8. #8
    Join Date
    Dec 2008
    Location
    always where I have to be
    Posts
    1,289
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    Quote Originally Posted by nsnbm
    Yes again. And there's a big difference a space can make if you point to a directory where you want to remove all the files:
    Code:
    rm -rf /dir/*
    compared to:
    Code:
    rm -rf /dir/ *
    Been there, done that, not good.
    He, yes. So I do F8 in mc, it's safer as I can see what folder is highlighted or what folders I selected if more are to be deleted.

  9. #9
    Join Date
    Oct 2010
    Location
    Canberra
    Posts
    4,042
    Mentioned
    20 Post(s)
    Tagged
    1 Thread(s)

    Re: Yet another warning about mount --bind and rm -rf

    Quote Originally Posted by nsnbm
    Yes again. And there's a big difference a space can make if you point to a directory where you want to remove all the files:
    Code:
    rm -rf /dir/*
    compared to:
    Code:
    rm -rf /dir/ *
    Been there, done that, not good.
    An interesting variation on that is relying on a variable
    Code:
    chmod -x $SOMETHING/bin/*
    Took a while to get that machine working again after someone ran the command without having set the variable.

    I have many ideas, even some I haven't thought of yet.

Similar Threads

  1. Max. number of mount --bind ?
    By kraft in forum Using Fedora
    Replies: 0
    Last Post: 1st September 2008, 01:57 AM
  2. Mount bind in fstab
    By macondo in forum Using Fedora
    Replies: 9
    Last Post: 13th June 2007, 09:04 PM
  3. vsftpd + mount --bind does not work
    By leonard in forum Servers & Networking
    Replies: 0
    Last Post: 5th November 2006, 07:51 AM
  4. apache and mount --bind
    By sciguy125 in forum Servers & Networking
    Replies: 2
    Last Post: 20th May 2006, 05:28 AM
  5. Fun with mount --bind
    By Mad Cow in forum Using Fedora
    Replies: 8
    Last Post: 16th December 2004, 01:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •