使用 ldd 进行 chroot

发布于 2025-01-06 12:52:12 字数 1108 浏览 6 评论 0原文

我在 sdb 上创建了非常小的 chroot 环境并将其安装在 /mnt/sdb 上。我还创建了一个指向 /usr/bin/gcc 的符号链接 /mnt/sdb/bin/cc

ldd /mnt/sdb/bin/cc 返回

 linux-gate.so.1 => (0xb7829000)
 libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb76dd000)
 /lib/ld-linux.so.2 (0xb782a000)

所以我通过运行复制了必要的库:

 cp /lib/i686/cmov/libc.so.6 /mnt/sdb/lib/i686/cmov/libc.so.6
 cp /lib/ld-linux.so.2 /mnt/sdb/lib/ld-linux.so.2

浏览 这篇文章,我想既然linux-gate.so.1是内核的一部分,我不需要复制它超过。

但是,在我运行 chroot /mnt/sdb /bin/sh 后尝试 cc ,我得到了

cc: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory

How come ldd Can't Tell cc need libm.so.6?有没有一种简单的方法可以让 cc 在 chroot 环境中工作,而无需简单地复制所有库?我只是想暂时使用 cc,这样我就可以用它构建 tcc,然后用 tcc 构建其他所有内容(我也尝试过简单地在外部构建 tcc,然后在 chroot 中使用它,但我担心这可能值得它自己的帖子)。

注意:

我在 Virtualbox 中使用 Debian,当前在 chroot 环境中运行的唯一程序是单个(静态)busybox 二进制文件。

I've created very minimal chroot environment on sdb and mounted it on /mnt/sdb. I've also created a symbolic link /mnt/sdb/bin/cc that points to /usr/bin/gcc.

ldd /mnt/sdb/bin/cc returned

 linux-gate.so.1 => (0xb7829000)
 libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb76dd000)
 /lib/ld-linux.so.2 (0xb782a000)

So I copied the necessary libraries by running:

 cp /lib/i686/cmov/libc.so.6 /mnt/sdb/lib/i686/cmov/libc.so.6
 cp /lib/ld-linux.so.2 /mnt/sdb/lib/ld-linux.so.2

Glancing through this article, I figured that since linux-gate.so.1 is a part of the kernel, I don't need to copy it over.

However, after I run chroot /mnt/sdb /bin/sh then try cc I get

cc: error while loading shared libraries: libm.so.6: cannot open shared object file: No such file or directory

How come ldd couldn't tell cc needed libm.so.6? Is there an easy way to get cc to work in the chrooted environment without simply copying over all the libraries? I'd just like to use cc temporarily so that I can build tcc with it, then build everything else with tcc (I've also tried simply building tcc outside then using it in chroot, but I'm afraid that that might deserve its own post).

Note:

I'm using Debian in Virtualbox, and the only program that currently runs in the chroot environment is a single (static) busybox binary.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文