详解在 Ubuntu 中引导到救援模式或紧急模式 | Linux 中国
这篇教程将介绍如何在 Ubuntu 22.04、20.04 和 18.04 LTS 版本中引导到救援模式或紧急模式。
- 来源:https://linux.cn/article-14709-1.html
- 作者:Sk
- 译者:郑
(本文字数:4226,阅读时长大约:6 分钟)
这篇教程将介绍如何在 Ubuntu 22.04、20.04 和 18.04 LTS 版本中引导到 救援(Rescue) 模式或 紧急(Emergency) 模式。
你可能已经知道,在 RHEL 7 、RHEL 8 、Ubuntu 16.04 LTS 及其更新的版本的 Linux 发行版中
运行等级(Runlevels) 已经被
系统目标(Systemd target) 所替代。更多关于
运行等级(Runlevel) 和
系统目标(Systemd targets) 的信息,参考 这篇指南 。
这篇指南是针对 Ubuntu 编写的,但是,下面所给的步骤应该也适用于大多数使用 systemd 作为默认服务管理器的 Linux 发行版。
在进入主题前,让我们简单的理解:什么是 救援(rescue) 模式 和 紧急(Emergency) 模式,以及这两种模式的目的是什么。
什么是救援模式?
在 Linux 发行版中,救援模式等效于使用 SysV 作为默认的服务器管理器的 单用户(single user) 模式。在救援模式中,将挂载所有的本地文件系统,将仅启动一些重要的服务。但是,不会启动一般的服务(例如,网络服务)。
救援模式在不能正常引导系统的情况下是很有用的。此外,我们可以在救援模式下执行一些重要的救援操作,例如,重新设置 root 密码 。
什么是紧急模式?
与救援模式相比,在紧急模式中,不会启动任何的东西。不会启动服务、不会挂载挂载点、不会建立套接字、什么都不会启动。你将所拥有的只是一个 原始的 shell 。紧急模式适用于调试目的。
首先,我们将看到如何在 Ubuntu 22.04 和 20.04 LTS 发行版中引导到救援模式或紧急模式。在 Ubuntu 22.04 和 20.04 LTS 中的过程是完全相同的!
在 Ubuntu 22.04 / 20.04 LTS 中引导到救援模式
我们可以使用两种方法来引导到救援模式。
方法 1
打开你的 Ubuntu 系统。在 BIOS 徽标出现后,按下 ESC
按键来显示 GRUB 菜单。
在 GRUB 菜单中,选择第一项,并按下 e
按键来编辑它。
按下 ↓
按键,并找到以单词 linux
开头的一行代码,并在其结尾处添加下面的一行代码。为到达其结尾处,只需要按下 Ctrl + e
组合键,或使用你键盘上的 END
按键或 ←
/→
按键。
systemd.unit=rescue.target




在添加上面的代码行后,按下 Ctrl + x
组合键或按下 F10
按键来引导到救援模式。
数秒后,你将作为 root 用户来登录到救援模式(即单用户模式)。将会提示你按下回车键来进入维护。
下图是 Ubuntu 22.04 / 20.04 LTS 系统的救援模式的样子:




现在,在救援模式中做你想做的任何事。在救援模式中,在你执行任何操作前,你可能需要以 读/写模式来挂载根(/
)文件系统。
mount -n -o remount,rw /




在完成后,按下 Ctrl + d
组合键来引导到正常模式。或者,你可以输入下面的任意一个命令来引导到正常模式。
systemctl default
或者,
exit
如果你想重新启动系统,而不是引导到正常的模式,输入:
systemctl reboot
方法 2
在这种方法中,你不需要编辑 GRUB 启动菜单项目。
打开系统电源,并从 GRUB 启动菜单中选择 Ubuntu 高级选项(Advanced options for Ubuntu)。




接下来,你将看到一个带有内核版本的可用的 Ubuntu 版本的列表。在 Ubuntu 中的 GRUB 启动菜单中选择 恢复模式(Recovery mode) 。




数秒后,你将看到 Ubuntu 的 恢复(Recovery) 菜单。从恢复菜单中,选择 进入 root 的 shell 提示符(Drop to root shell prompt) 选项 ,并按下回车键。




现在,你将进入维护。




通过输入下面的命令来 以读/写模式的方式 来挂载根(/
)文件系统:
mount -n -o remount,rw /




在救援模式中做你想做的任何事。
在完成后,输入 exit
来返回到恢复菜单。
exit
最后,选择 救援正常启动(Resume normal boot) 选项,并按下回车键。




再次按下回车键来退出恢复模式,并继续引导到正常模式。




如果你不想引导到正常模式,从救援模式中输入 reboot
并按下回车键来重新启动你的系统。
在 Ubuntu 22.04 / 20.04 LTS 中引导到紧急模式
当 GRUB 菜单出现时,按下 e
按键来编辑它。




找到以单词 linux
开头的一行代码,并在其结尾处添加下面的一行代码:
systemd.unit=emergency.target




在添加上面的代码行后,按下 Ctrl + x
组合键,或按下 F10
按键来引导到紧急模式。
数秒后,你将作为 root
用户来进入维护。将会提示你按下回车键来进入紧急模式。
下图是 Ubuntu 22.04 / 20.04 LTS 系统的紧急模式的样子:




现在,在紧急模式中做你想做的任何事。在紧急模式中,在你执行任何操作前,你可能需要以读/写模式来挂载根(/
)文件系统。
mount -n -o remount,rw /
在完成后,按下 Ctrl + d
组合键来引导到正常模式。或者,你可以输入下面的任意一个命令来引导到正常模式。
systemctl default
或者,
exit
如果你想重新启动系统,而不是引导到正常模式,输入:
systemctl reboot
在 Ubuntu 18.04 LTS 中引导到救援模式
启动你的 Ubuntu 系统。当 GRUB 菜单出现时,选择第一项并按下按键 e
来编辑。(为到达其行尾处,只需要按下 Ctrl + e
组合键,或使用你键盘上的 END
按键或 ←
/→
按键):




如果你没有看到 GRUB 菜单,只需要在 BIOS 徽标出现后,按下 ESC
按键来显示 GRUB 菜单。
找到以单词 linux
开头的一行代码,并在其结尾处添加下面的一行代码(为到达其行尾处,只需要按下 Ctrl + e
组合键,或使用你键盘上的 END按键或
←/
→` 按键):
systemd.unit=rescue.target




在添加上面的代码行后,只需要按下 Ctrl + x
组合键,或按下 F10
按键来引导到救援模式。数秒后,你将作为 root
用户进入维护(即单用户模式)。
下图是 Ubuntu 18.04 LTS 服务器系统的救援模式的样子:




接下来,输入下面的命令来挂载根(/
)文件系统为读/写模式。
mount -n -o remount,rw /
在 Ubuntu 18.04 LTS 中引导到紧急模式
引导你的 Ubuntu 到紧急模式基本与上述方法相同。你所需要做的全部工作是,在编辑 GRUB 菜单时,将 systemd.unit=rescue.target
替换为 systemd.unit=emergency.target
。




在你添加 systemd.unit=emergency.target
后,按下 Ctrl + x
组合键,或按下 F10
按键来引导到紧急模式。




最后,你可以使用下面的命令来以读/写模式的方式来挂载根(/
)文件系统:
mount -n -o remount,rw /
在救援模式和紧急模式之间切换
如果你正在救援模式中,你不必像我上述提到的那样来编辑 GRUB 的菜单启动项。相反,你只想要输入下面的命令来立刻切换到紧急模式:
systemctl emergency
同样,为从紧急模式切换到救援模式,输入:
systemctl rescue
总结
现在,你知道了什么是救援模式和紧急模式,以及如何在 Ubuntu 22.04 、20.04 和 18.04 LTS 系统中启动到这些模式。正如我已经提到的,在这里提供的这些步骤应该也适用于大多数当前使用 systemd 作为默认服务管理器的 Linux 发行版。
via: https://ostechnix.com/how-to-boot-into-rescue-mode-or-emergency-mode-in-ubuntu-18-04/
作者:sk 选题:lkxed 译者:robsean 校对:wxy
本文由 LCTT 原创编译,Linux中国 荣誉推出
2024最新激活全家桶教程,稳定运行到2099年,请移步至置顶文章:https://sigusoft.com/99576.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。 文章由激活谷谷主-小谷整理,转载请注明出处:https://sigusoft.com/8452.html