RHEL7 修改内核参数错误,导致系统启动失败
问题现象
当错误的配置hugepages大小时,设置的大于系统内存大小,重启就会发现系统起不来。今天又发现了一个参数,设置错误,也会造成系统启动失败,特此模拟记录下。
先模拟错误发生:
操作系统为RHEL7.6
[root@postgre ~]# cat /proc/sys/fs/file-max
94042
[root@postgre ~]# cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
设置错误参数
[root@postgre ~]# vi /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
fs.file-max=700
"/etc/sysctl.conf" 11L, 465C written
[root@postgre ~]# reboot
好像出现假死的状态:
提示密码都不正确了,密码没变过。
在图形化接面,一直卡住,转圈,好像系统hang了。
问题原因
错误的配置了内核参数
解决方案
因某些修改操作,导致系统重启后无法正常启动,此时可进入救援模式,修复错误配置即可。
我发现7进入救援模式有两种
rw init=/sysroot/bin/sh
- 重启操作系统
- 在启动过程中,当GRUB2菜单出现时,按e键进行编辑
- 按e之后,就会出现如下接面
4. 进入后,找到linux16 开头的一行!按向右的方向键,定位到ro
- 将ro替换为rw init=/sysroot/bin/sh
- 按ctrl+x重启,就会进入到如下界面。
进入系统后,其实只是进入了一个安全模式下的内存系统,并不是真正的咱们正常使用的linux系统 - 使用命令 #chroot /sysroot/ 切换到正常系统中去!
- 修改错误配置
注意;修改完成后,此时直接在命令行重启系统,会报错,因为这不是一个正常的操作系统。
- 硬重启,相当于摁电源重启
启动恢复正常。
systemd.unit=rescue.target
- 在启动过程中,当GRUB2菜单出现时,按e键进行编辑
- 在x86-64系统上的linux16行的末尾或UEFI系统上的linuxefi行的末尾添加以下参数
systemd.unit=rescue.target - 光标向下翻,找到linux16开头的行,Ctrl+e (or End)跳至行的结尾,添加参数
- 按Ctrl+x 使用参数启动系统,需要输入root密码,
- 输入root密码,就会进入操作系统
- vi修改错误配置
- reboot重启操作系统,操作系统就会正常启动。
参考:
https://blog.51cto.com/asd9577/1931442
https://www.freesion.com/article/5686202778/
记录下: