AlmaLinux 8 和 9 的單用戶模式 (也稱為救援模式) 指南
單用戶模式是一個精簡的 Linux 環(huán)境,允許系統(tǒng)管理員執(zhí)行維護任務、排查問題和從系統(tǒng)故障中恢復。當您需要重置 root 密碼、修復配置錯誤、修復損壞的文件系統(tǒng)或調(diào)查阻止正常啟動的系統(tǒng)錯誤時,單用戶模式特別有用。
作為基于 RHEL 的發(fā)行版,AlmaLinux 8 和 9 通過 GRUB 引導加載程序提供了一種簡單的進入單用戶模式的方法。本指南將逐步解釋如何在 AlmaLinux 8 和 9 上進入單用戶模式。
什么是單用戶模式?
單用戶模式是 Linux 中的一種特殊引導模式,允許系統(tǒng)以最少的服務和僅一個 root shell 運行。與正常的單用戶模式不同,在單用戶模式下:
- 只有 root 用戶有訪問權(quán)限。
- 網(wǎng)絡(luò)服務被禁用。
- 僅啟動必要的系統(tǒng)進程。
- 系統(tǒng)在命令行模式下運行,沒有圖形界面。
由于系統(tǒng)在此模式下并非完全運行,因此它非常適合于排查關(guān)鍵問題和進行系統(tǒng)級更改。
步驟 1:訪問 GRUB 引導菜單
進入單用戶模式的第一步是訪問 GRUB 引導菜單,該菜單在系統(tǒng)完全啟動之前出現(xiàn)。
如果系統(tǒng)已開啟,請使用以下命令重新啟動:
reboot
系統(tǒng)開始重新啟動后,立即按“Esc”鍵(在某些系統(tǒng)上,可能是 Shift 鍵)。
您將看到一個屏幕,其中顯示 GRUB 菜單中可用的內(nèi)核列表,您現(xiàn)在可以使用箭頭鍵選擇要修改引導設(shè)置的內(nèi)核版本。
選擇內(nèi)核版本后,按“e”鍵編輯引導配置屏幕,您可以在其中修改內(nèi)核參數(shù)。
步驟 2:修改內(nèi)核引導參數(shù)
現(xiàn)在,我們需要添加一個特殊命令來指示系統(tǒng)進入單用戶模式而不是正常的單用戶模式。
找到以 linux
或 linuxefi
(如果您的系統(tǒng)使用 UEFI 引導)開頭的行。
<code>linux /vmlinuz-<version> root=/dev/mapper/almalinux-root ro quiet splash</version></code>
轉(zhuǎn)到此行的末尾并添加以下內(nèi)容:
<code>systemd.unit=rescue.target</code>
修改后,按 Ctrl + X
或 F10
使用修改后的設(shè)置引導。
步驟 3:引導到單用戶模式
按下 Ctrl + X
或 F10
后,系統(tǒng)將開始引導到單用戶模式。
- 您將看到命令行界面而不是正常的登錄屏幕。
- 系統(tǒng)將提示您輸入 root 密碼(在某些系統(tǒng)上,可能不需要)。
- 輸入 root 密碼后,您將對系統(tǒng)擁有完全控制權(quán)。
步驟 4:執(zhí)行系統(tǒng)維護
現(xiàn)在您已進入單用戶模式,您可以執(zhí)行各種系統(tǒng)維護任務。以下是一些您可能需要執(zhí)行的常見操作:
1. 重置 root 密碼
如果您忘記了 root 密碼,可以使用以下命令重置:
passwd root
更改后,請確保通過運行以下命令更新 SELinux 策略(如果已啟用):
touch /.autorelabel
2. 檢查和修復文件系統(tǒng)
如果您的系統(tǒng)由于文件系統(tǒng)損壞而出現(xiàn)引導錯誤,請運行:
fsck -y /dev/mapper/almalinux-root
這將檢查并嘗試修復根分區(qū)上的錯誤。
3. 修改系統(tǒng)配置文件
如果錯誤配置阻止了正常引導,您可以編輯配置文件:
vi /etc/fstab
進行必要的更正并保存文件。
完成必要的維護任務后,重新啟動系統(tǒng)以正常啟動。
reboot
您的系統(tǒng)現(xiàn)在將引導到其正常操作模式。
替代方法:引導到緊急模式
如果單用戶模式不起作用或您需要更低級別的故障排除環(huán)境,您可以使用以下命令修改任何現(xiàn)有的引導參數(shù):
<code>systemd.unit=emergency.target</code>
緊急模式提供的服務比單用戶模式更少,這對于深入故障排除很有幫助。
示例:修復損壞的 fstab 文件
如果 /etc/fstab
文件(控制文件系統(tǒng)如何掛載)配置錯誤或包含不正確的條目,則系統(tǒng)可能無法正常引導。
假設(shè)您手動編輯了 /etc/fstab
并添加了如下錯誤條目:
<code>/dev/sdb1 /mnt/data ext4 defaults 0 0</code>
但分區(qū) /dev/sdb1
不存在。
會發(fā)生什么?
- 如果您正常引導,系統(tǒng)可能會在啟動期間掛起。
- 如果您嘗試單用戶模式,它可能無法正確加載,因為在到達 shell 之前會讀取
/etc/fstab
。
解決方案:引導到緊急模式
由于緊急模式僅加載最基本的系統(tǒng)服務,因此它會跳過在 /etc/fstab
中錯誤定義的文件系統(tǒng)的掛載,從而允許您修復問題。
結(jié)論
AlmaLinux 8/9 中的單用戶模式是一種強大的模式,允許管理員重置密碼、修復文件系統(tǒng)和修復配置錯誤。通過遵循這些步驟,您可以安全地引導到救援模式并有效地排查系統(tǒng)問題。
The above is the detailed content of How to Boot Into Single User Mode in AlmaLinux 8/9. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

When encountering DNS problems, first check the /etc/resolv.conf file to see if the correct nameserver is configured; secondly, you can manually add public DNS such as 8.8.8.8 for testing; then use nslookup and dig commands to verify whether DNS resolution is normal. If these tools are not installed, you can first install the dnsutils or bind-utils package; then check the systemd-resolved service status and configuration file /etc/systemd/resolved.conf, and set DNS and FallbackDNS as needed and restart the service; finally check the network interface status and firewall rules, confirm that port 53 is not

As a system administrator, you may find yourself (today or in the future) working in an environment where Windows and Linux coexist. It is no secret that some big companies prefer (or have to) run some of their production services in Windows boxes an

Built on Chrome’s V8 engine, Node.JS is an open-source, event-driven JavaScript runtime environment crafted for building scalable applications and backend APIs. NodeJS is known for being lightweight and efficient due to its non-blocking I/O model and

In Linux systems, 1. Use ipa or hostname-I command to view private IP; 2. Use curlifconfig.me or curlipinfo.io/ip to obtain public IP; 3. The desktop version can view private IP through system settings, and the browser can access specific websites to view public IP; 4. Common commands can be set as aliases for quick call. These methods are simple and practical, suitable for IP viewing needs in different scenarios.

Linuxcanrunonmodesthardwarewithspecificminimumrequirements.A1GHzprocessor(x86orx86_64)isneeded,withadual-coreCPUrecommended.RAMshouldbeatleast512MBforcommand-lineuseor2GBfordesktopenvironments.Diskspacerequiresaminimumof5–10GB,though25GBisbetterforad

Written in C, MySQL is an open-source, cross-platform, and one of the most widely used Relational Database Management Systems (RDMS). It’s an integral part of the LAMP stack and is a popular database management system in web hosting, data analytics,

Ubuntu has long stood as a bastion of accessibility, polish, and power in the Linux ecosystem. With the arrival of Ubuntu 25.04, codenamed “Plucky Puffin”, Canonical has once again demonstrated its commitment to delivering a

MongoDB is a high-performance, highly scalable document-oriented NoSQL database built to manage heavy traffic and vast amounts of data. Unlike traditional SQL databases that store data in rows and columns within tables, MongoDB structures data in a J
