[排错] 解决 Linux 开机时报错 “kernel panic – no syncing: Attempted to kill init ……”

报错代码

/init: error while loading shared libraries: libsystemd-shared-239.so: cannot open shared object file: No such file or directory
kernel panic - no syncing: Attempted to kill init! exitcode=0x00007f00

解决方法

步骤一:进入拯救模式

步骤二:确认第三方软件库

2.1 搜集第三方软件库信息

# ldconfig -p > /tmp/ldconfig.out

2.2 确认有没有第三方软件库

# for l in $(awk '{ print $1 }' /tmp/ldconfig.out); do matches=$(awk "\$1 == \"$l\" { print }" /tmp/ldconfig.out); if [ $(echo "$matches" | wc -l) -ge 2 ]; then echo "$matches"; echo; fi; done

(补充:如果没有第三方软件库的话这里不会有任何输出)

步骤三:检查 /etc/ld.so.conf 文件或者 /etc/ld.so.conf.d/ 目录里的文件去除第三方库

(步骤略)

步骤四:刷新库缓存

# ldconfig

步骤五:为启动失败的系统创建创建 initramfs 文件

# dracut -f /boot/initramfs-(uname -r).img $(uname -r)

(补充:这里以将正在运行的内核版本生成一个新的 initramfs 为例)

(注意:此时原来启动系统时使用的那个 initramfs 文件会被覆盖)

步骤六:重启系统

# reboot

参考文献

https://access.redhat.com/solutions/7096246