Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Linux 進入單用戶模式 (單用戶維護模式) 完整指南

編輯:Linux 系統常見問題解答

適用場景

  • 忘記 root 密碼重置。
  • 損壞關鍵系統文件 (如 /etc/fstab, /etc/passwd) 修復。
  • 文件系統檢查/修復 (fsck)。
  • SELinux 策略導致無法啟動需授權/重標記。

GRUB 2 (主流發行版) 進入步驟

  1. 開機出現 GRUB 菜單,選中內核行,按 e 編輯。
  2. 找到以 linux / linux16 / linuxefi 開頭的行 (內核參數行)。
  3. 在行末尾添加 single 或 1 或 rd.break (進入 initramfs shell 更早介入)。
  4. 按 Ctrl+x 或 F10 啟動。
  5. 進入單用戶模式後,根文件系統通常以只讀掛載,需重新掛載可寫:
    
    mount -o remount,rw /
    
  6. 執行維護操作 (如 passwd root 重置密碼)。
  7. 退出:exit 或 reboot。

GRUB Legacy (舊版 RHEL 6/CentOS 6) 步驟

  1. GRUB 菜單選中內核,按 e。
  2. 選中 kernel 行,再按 e。
  3. 行末添加 single (或 1),按 Enter。
  4. 按 b 啟動。

LILO 引導器 (極少見) 步驟


# LILO 提示符下輸入:
linux single
# 或
linux 1
# 或
linux -s
# 若內核標籤非 linux,按 Tab 列出可用標籤

systemd 目標對應關係

運行級別systemd Target描述
0poweroff.target關機
1rescue.target單用戶/救援模式 (需 root 密碼)
2,3,4multi-user.target多用戶文本界面 (無圖形)
5graphical.target多用戶圖形界面
6reboot.target重啟

現代系統 single 內核參數實際激活 rescue.target,需輸入 root 密碼;rd.break 在 initramfs 階段打斷,無需密碼但根分區未掛載,需手動掛載 mount /sysroot 並 chroot /sysroot。

單用戶模式常用修復操作


# 重置 root 密碼
passwd root

# 修復 /etc/fstab 錯誤
vi /etc/fstab

# 強制文件系統檢查 (下次重啟)
touch /forcefsck

# SELinux 重標記
touch /.autorelabel

# 卸載並修復 XFS/EXT4
umount /dev/sdaX
xfs_repair /dev/sdaX
# 或
fsck -y /dev/sdaX
Copyright © Windows教程網 All Rights Reserved