欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 会展 > 【Linux】之【Get】 chroot 环境下安装deb包时 .postinst:行 9: 201 段错误 (核心已转储)ldconfig

【Linux】之【Get】 chroot 环境下安装deb包时 .postinst:行 9: 201 段错误 (核心已转储)ldconfig

2025/4/19 5:07:16 来源:https://blog.csdn.net/kin_16/article/details/147122531  浏览:    关键词:【Linux】之【Get】 chroot 环境下安装deb包时 .postinst:行 9: 201 段错误 (核心已转储)ldconfig

背景

如题,在postinst文件中直接执行了ldconfig命令, chroot 环境下出错,安装失败

分析

chroot 环境下不能用 ldconfig 和 systemctl
在这里插入图片描述但是:如果环境是 chroot,系统有可能没完整挂载 /proc、/dev、系统路径,跑 ldconfig 就容易段错误(core dump)。

解决

加条件判断,出错后也继续执行接下来的安装任务,防止影响安装。

  • chroot 环境下不能用 systemctl,要添加条件判断
is_chroot() {if [ -f /proc/1/sched ]; then  # 看 /proc/1/sched 这个文件存不存在。➔ 这个文件是记录系统 第一个进程(PID 1) 的状态。➔ 正常系统里 PID 1 是 systemd,如果没这个文件,大概率是特种环境(比如 chroot)。# 检查 init 是不是 systemd 打开 /proc/1/comm 这个小文件,看里面是不是写着 systemd。 ➔ 这个文件保存了 PID 1 的名字。 ➔ 如果看到是 systemd,说明是正常启动的系统,不是 chroot。if grep -q "systemd" /proc/1/comm 2>/dev/null; thenreturn 1    # 不是 chrootelsereturn 0    # 是 chrootfielsereturn 0        # 没有 /proc,肯定是 chrootfi
}if ! is_chroot; thenif command -v systemctl >/dev/null 2>&1; then #检查有没有 systemctl 这个命令。 ➔ 有些很精简的系统,可能没装 systemctl,所以这里保险一点,先检查systemctl daemon-reload || truesystemctl enable xxx.service || truesystemctl daemon-reload || truefielseecho "Running in chroot, skipping systemctl operations."fi

在这里插入图片描述

  • ldconfig = 帮 Linux 记住最新的动态库,避免程序找不到库出错。

  • Debian 包管理系统中常见的脚本有:

    preinst:在安装前执行。用于检查环境、备份等操作。postinst:在安装后执行。用于配置服务、创建文件等任务。prerm:在卸载前执行。用于停止服务、清理工作。postrm:在卸载后执行。用于删除配置文件、清理系统。config:用于配置交互,接收用户输入并生成配置文件。
    

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词