另類實驗 Linux啟動後,rm刪除全部磁碟的效果

2021-09-29 10:58:49 字數 3055 閱讀 4439

另類實驗

疑問:在linux啟動後,執行rm -rf /刪除所有目錄及檔案,系統還能執行嗎?

環境建議:最好在虛擬機器(如vmware)中安裝linux系統進行測試,這樣可以利用虛擬機器的快照功能,隨時可以恢復。

linux啟動後,以root使用者執行。提公升需要增加:--no-preserve-root 引數,然後增加引數再試

[root@centosa ~]# rm -rf /

rm: it is dangerous to operate recursively on 『/』

rm: use --no-preserve-root to override this failsafe

[root@centosa ~]# rm -rf --no-preserve-root /

然後增加引數再rm嘗試。rm刪除過程中提示了很多「rm: cannot remove」

刪除完後,發現可用的命令有cd 、 pwd、export等命令。許多日常常用的命令都無法使用。甚至poweroff關機命令也無法執行只能強行關機。如下圖( bash: sed: command not found 這句提示可忽略 )

...(省略)...

...(省略)...

rm: cannot remove 『/var/lib/nfs/rpc_pipefs/nfs』: operation not permitted

rm: cannot remove 『/var/lib/nfs/rpc_pipefs/mount』: operation not permitted

rm: cannot remove 『/var/lib/nfs/rpc_pipefs/lockd』: operation not permitted

rm: cannot remove 『/var/lib/fwupd』: device or resource busy

rm: cannot remove 『/tmp』: device or resource busy

rm: cannot remove 『/usr』: device or resource busy

rm: cannot remove 『/home』: device or resource busy

bash: sed: command not found

[root@centosa /]#

bash: sed: command not found

root@centosa /]# df -m

bash: df: command not found

bash: sed: command not found

[root@centosa ~]# cd /

bash: sed: command not found

[root@centosa /]# pwd

/bash: sed: command not found

[root@centosa /]# ls

bash: ls: command not found

bash: sed: command not found

重新找乙個linux環境,或者利用虛擬機器的快照恢復到上步刪除前。

linux啟動後,以root使用者執行。  刪除前,先執行一些命令,例如:cd 、pwd、vi、ls、top、ps、df、export、echo等。執行後,相當於把命令的內容載入到記憶體中。

[root@centosa tmp]# cd /etc/

[root@centosa etc]# pwd

/etc

[root@centosa etc]# vi /etc/passwd

[root@centosa etc]# ls

[root@centosa etc]# top

[root@centosa etc]# ps

[root@centosa etc]# df -m

[root@centosa etc]# export

[root@centosa etc]# echo "aaa"

然後再執行刪除:rm -rf --no-preserve-root / 

[root@centosa etc]# cd /etc/

bash: sed: command not found

[root@centosa etc]# pwd

/etc

bash: sed: command not found

[root@centosa etc]# vi /etc/passwd

bash: /usr/bin/vi: no such file or directory

bash: sed: command not found

[root@centosa etc]# ls

bash: /usr/bin/ls: no such file or directory

bash: sed: command not found

[root@centosa etc]# top

bash: /usr/bin/top: no such file or directory

bash: sed: command not found

[root@centosa etc]# ps

bash: /usr/bin/ps: no such file or directory

bash: sed: command not found

entosa etc]# echo "aaa"

aaabash: sed: command not found

能用的還是那幾個命令(多了echo命令可以用),其他命令還是不能用。但提示已經變成了:no such file or directory

可以刪除全部磁碟內容(除非明確提示不能刪),刪除後系統處於不可用狀態。

已經載入到記憶體中的可以使用(注意兩次使用提示的變化)。但是有些命令執行過程中,需要訪問磁碟,只要訪問磁碟,就無法執行。

日常使用 rm -rf /  linux有保護性提示,不容易誤操作。

重灌windows後,Linux無法啟動的問題

很多朋友應該都有這樣的經歷,自己在電腦上用的是雙系統,ubuntu windows。在重灌windows後,linux根本就無法啟動,也就是說,電腦啟動時根本到不了grub 選擇選單那裡。解決這樣的問題很簡單,只用乙個linux系統光碟即可修復。因為重灌windows時,原來的grub啟動選單不見了...

linux 使用者啟動後載入檔案

shell會涉及兩個引數,互動 非互動 登入 分登陸 他們是可以交叉組合的,比如你是互動,可以登陸,也可以不登入.由於他們的關係可以相互組合,為了清楚以下先針對單獨情況討論。non interactive 非互動使用者 預設無輸入輸出。一般是由程式產生的。命令需指定fullpath。a呼叫b,簡寫成...

linux系統重啟後nginx啟動報錯

nginx報錯如下 root localhost 01 sbin nginx emerg open var run nginx nginx.pid failed 2 no such file or directory 出錯原因 虛擬機器重啟後,var run nginx,nginx這個資料夾都會被刪...