破解 LD_LIBRARY_PATH 以使用 chroot 中最近的 bash

破解 LD_LIBRARY_PATH 以使用 chroot 中最近的 bash

我尝试获取更新版本的bashfrom LinuxMint

我的盒子里有一个chrootDebian Sid

bash我在早期尝试在包装脚本中做什么PATH

#!/bin/bash

LD_LIBRARY_PATH=/path/to/chroot/usr/lib/x86_64-linux-gnu:/path/to/chroot/lib:/path/to/chroot/lib64:/path/to/chroot/var/lib:/path/to/chroot/usr/lib:/path/to/chroot/usr/local/lib /path/to/chroot/bin/bash "$@"

但我得到:

/home/mevatlave/bin/bash: line 3: 1492488 Segmentation fault      (core dumped) LD_LIBRARY_PATH=/path/to/chroot/usr/lib/x86_64-linux-gnu:/path/to/chroot/lib:/path/to/chroot/lib64:/path/to/chroot/var/lib:/path/to/chroot/usr/lib:/path/to/chroot/usr/local/lib /path/to/chroot/bin/bash "$@"

从 chroot 开始:

% ldd /bin/bash
    linux-vdso.so.1 (0x00007fff237fc000)
    libtinfo.so.6 => /lib/x86_64-linux-gnu/libtinfo.so.6 (0x00007f94de839000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f94de658000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f94de9af000)

可行吗?

编辑:

LD_LIBRARY_PATH=/path/to/chroot/lib:/path/to/chroot/lib64:/path/to/chroot/var/lib:/path/to/chroot/usr/lib:/path/to/chroot/usr/local/lib /path/to/chroot/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /path/to/chroot/bin/bash "$@"

我明白了

/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.36' not found 

LD_LIBRARY_PATH=/path/to/chroot/usr/lib/x86_64-linux-gnu:/path/to/chroot/lib:/path/to/chroot/lib64:/path/to/chroot/var/lib:/path/to/chroot/usr/lib:/path/to/chroot/usr/local/lib /path/to/chroot/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /path/to/chroot/bin/bash "$@"

我得到:

Segmentation fault (core dumped) 
LD_LIBRARY_PATH=/path/to/chroot/usr/lib/x86_64-linux- gnu:/path/to/chroot/lib:/path/to/chroot/lib64:/path/to/chroot/var/lib:/path/to/chroot/usr/lib:/path/to/chroot/usr/local/lib: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /path/to/chroot/bin/bash "$@"

编辑2:

我可以运行这个:

#!/bin/bash

LANG=C
LD_LIBRARY_PATH=/path/to/chroot/usr/lib/x86_64-linux-gnu:/path/to/chroot/lib:/path/to/chroot/lib64:/path/to/chroot/var/lib:/path/to/chroot/usr/lib:/path/to/chroot/usr/local/lib /path/to/chroot/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /path/to/chroot/bin/bash "$@"

但是当我跑步时bash --version,我得到:

Segmentation fault (core dumped)
root@debian-sid_chroot:/# dpkg -l | grep libc6
ii  libc6:amd64                  2.36-8                    amd64        GNU C 
Library: Shared libraries
ii  libc6-dev:amd64              2.36-8                    amd64        GNU C 
Library: Development Libraries and Header Files

答案1

我怀疑你的主动态链接器太旧了,你需要使用 chroot 的:

LD_LIBRARY_PATH=/path/to/chroot/usr/lib/x86_64-linux-gnu:/path/to/chroot/lib:/path/to/chroot/lib64:/path/to/chroot/var/lib:/path/to/chroot/usr/lib:/path/to/chroot/usr/local/lib /path/to/chroot/lib64/ld-linux-x86-64.so.2 /path/to/chroot/bin/bash

/lib64/ld-linux-x86-64.so.2是什么,为什么可以用它来执行文件?

答案2

好的,找到了一个解决方法,可以避免我编译bash以及将来需要维护它:

来自 chroot

# apt install bash-static

然后,我的升级脚本LinuxMint

#!/bin/bash

if mount | grep -q "/home/sid-chroot"; then
    chroot /home/sid-chroot <<< 'apt-get -yy update; apt-get -yy upgrade'
else
    debian-sid <<< 'apt-get -y update; apt-get -y upgrade'
fi

apt update
apt-get install zsh
apt-get -y upgrade
zsh<<EOF
mv /bin/bash /bin/bash.origin
mv /usr/bin/bash /usr/bin/bash.origin &>/dev/null
cp -a /home/sid-chroot/bin/bash-static /bin/bash
cp -a /home/sid-chroot/bin/bash-static /usr/bin/bash
EOF

相关内容