Bienvenido! - Willkommen! - Welcome!

Bitácora Técnica de Tux&Cía., Santa Cruz de la Sierra, BO
Bitácora Central: Tux&Cía.
Bitácora de Información Avanzada: Tux&Cía.-Información
May the source be with you!

Monday, November 7, 2011

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
Quote:
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 translocated 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 habit.
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.

No comments: