rm -rf / についてのメモ

良く冗談で、「rm -rf /」を実行なんて話がありますが、試したメモです。


SolarisのrmコマンドはSolaris10以降、GNU Core Utilitiesのrmコマンドは6.4以降だと、
誤って削除されないように保護する仕組みが機能するようになっているようです。

OpenSolarisの場合


OpenSolaris(2009.06)で試した結果です。
GNU coreutilsは6.7。

# uname -a
SunOS opensolaris 5.11 snv_111b i86pc i386 i86pc Solaris
# /usr/gnu/bin/rm --version
rm (GNU coreutils) 6.7
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering.
# /usr/gnu/bin/rm -rf /
/usr/gnu/bin/rm: cannot remove root directory `/'

# /bin/rm -rf /
rm of / is not allowed

# /usr/bin/rm -rf /
rm of / is not allowed


異なるパスにいくつかrmコマンドがありましたが、
いずれも「rm -rf /」は実行されませんでした。

Linux(CentOS5/RHEL6 Beta)の場合


まずCentOS5.5で試しました。
GNU coreutilsは5.97。


何も指定しない場合は、コマンドが実行されてしまいました。

# uname -a
Linux centos5 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 i686 i386 GNU/Linux
# /bin/rm --version
rm (GNU coreutils) 5.97
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software.  You may redistribute copies of it under the terms of
the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Rubin, David MacKenzie, Richard Stallman, and Jim Meyering.
# /bin/rm -rf /
/bin/rm: cannot remove `//proc/asound/I82801AAICH': 許可されていない操作です
/bin/rm: cannot remove `//proc/asound/card0/oss_mixer': 許可されていない操作です
/bin/rm: cannot remove `//proc/asound/card0/id': 許可されていない操作です
/bin/rm: cannot remove `//proc/asound/card0/intel8x0': 許可されていない操作です
/bin/rm: cannot remove `//proc/asound/card0/pcm1c/oss': 許可されていない操作です
/bin/rm: cannot remove `//proc/asound/card0/pcm1c/sub0/prealloc_max': 許可されていない操作です
*****(略)*****
/bin/rm: cannot remove directory `//dev/shm': デバイスもしくはリソースがビジー状態です
/bin/rm: cannot remove `//dev/pts/0': 許可されていない操作です
/bin/rm: cannot remove directory `//boot': デバイスもしくはリソースがビジー状態です


次にRHEL6 Betaです。
GNU coreutilsは8.4。


こちらは警告が出て、コマンドは実行されませんでした。

Linux rhel6 2.6.32-44.1.el6.x86_64 #1 SMP Wed Jul 14 18:51:29 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux
# /bin/rm --version
rm (GNU coreutils) 8.4
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Rubin, David MacKenzie, Richard M. Stallman,
and Jim Meyering.
# /bin/rm -rf /
rm: it is dangerous to operate recursively on `/'
rm: use --no-preserve-root to override this failsafe


RedHat6以降はひとまず安心かなと思います。


GNU coreutils6.4以前でも、
rmコマンド実行時に「--preserve-root」オプションを付けておくと、
rm -rf /」は実行されません。
(6.4以降はこれがデフォルトになったようです)

# /bin/rm --preserve-root -rf /
/bin/rm: it is dangerous to operate recursively on `/'
/bin/rm: use --no-preserve-root to override this failsafe


今日はこんな所で。