touch /.autorelabel)前提: 開機載入器 (GRUB/LILO) 正常運作。
# 切換至 runlevel 1 (SysV) / rescue.target (systemd)
telinit 1
# 或
systemctl isolate rescue.target
注意: 會斷開所有網路連線、停止服務,僅保留根檔案系統掛載。
linux 或 linux16 / linuxefi 開頭的行systemd.unit=rescue.target 或 rd.break (更早介入,進入 initramfs)single 或 1 或 systemd.unit=rescue.target
# GRUB 選單按 c 進入命令列
grub> set root=(hd0,1)
grub> linux /vmlinuz-5.15.0-91-generic root=/dev/sda1 ro single
grub> initrd /initrd.img-5.15.0-91-generic
grub> boot
single 或 1
grub> root (hd0,0)
grub> kernel /vmlinuz-2.6.32-754.el6 ro root=/dev/sda1 single
grub> initrd /initrd-2.6.32-754.el6.img
grub> boot
# LILO 提示符下
LILO: linux single
# 或
LILO: linux 1
# linux 為 /etc/lilo.conf 中 label 名稱
# 1. 根檔案系統預設唯讀,需重新掛載為讀寫
mount -o remount,rw /
# 2. 重置 root 密碼
passwd root
# 3. 修復 /etc/fstab 錯誤
vi /etc/fstab
# 修正錯誤的 UUID/裝置/掛載點/選項
# 4. 檔案系統檢查修復
fsck -y /dev/sda1 # 針對具體分區
# 5. SELinux 重新標籤 (修改密碼/授權檔後必做)
touch /.autorelabel
# 6. 同步並重啟
sync
reboot
# 或
exec /sbin/init # 切換回目標 runlevel/target
| 特性 | rescue.target (single) | emergency.target |
|---|---|---|
| 掛載 | 掛載本地檔案系統 (唯讀→可重掛讀寫) | 僅掛載根檔案系統 (唯讀) |
| 服務 | 啟動基本系統服務 (systemd, journald, 等) | 最小服務,僅啟動核心服務 |
| 網路 | 通常不啟動 | 不啟動 |
| 適用場景 | 密碼重置、配置修復、fsck | 極度損壞、根分區無法掛載時搶救 |
| 啟動參數 | systemd.unit=rescue.target / single / 1 | systemd.unit=emergency.target / emergency |
| 問題 | 解決 |
|---|---|
| 單用戶模式仍需 root 密碼 | 使用 rd.break 在 initramfs 階段介入,無需密碼 |
| 鍵盤佈局錯誤無法輸入 | GRUB 編輯行加入 keymap=us 或使用 loadkeys us |
| LVM/RAID 根分區無法掛載 | 在 initramfs 階段 (rd.break) 手動組裝:vgchange -ay, mdadm --assemble --scan |
| SELinux 拒絕操作 | 執行 setenforce 0 臨時寬容,修復後 touch /.autorelabel && reboot |