stop rm at same-dev bind mounts

Thomas Moschny thomas.moschny at gmail.com
Sat Sep 10 13:35:40 UTC 2011


Hi,

having a rm command accidentally removing 3/4 of my system yesterday,
I am starting to wonder whether it is possible to have rm reliably
stop at bind mounts. I know there is a --one-file-system option, but
it is not working when the bind mount points to the same device:

% cd /tmp
% mkdir -p a/b c/d ; touch c/d/file ; mount --bind c a/b
% find a
a
a/b
a/b/d
a/b/d/file
% rm -rf --one-file-system a
rm: cannot remove `a/b': Device or resource busy
% find a
a
a/b

`file' has been removed. Imho the name of the --one-file-system option
is misleading as it only compares st_dev fields. Besides filing a
bug/enhancement ticket for coreutils, does someone know a reliable way
to stop rm in such cases?


-- 
Thomas Moschny <thomas.moschny at gmail.com>


More information about the devel mailing list