# chroot /mnt/sys1 /bin/bash
chroot: failed to run command '/bin/bash': No such file or directory
但这不是常见的chroot: failed with No such file or directory
问题,因为文件就在那里:
/mnt/sys1# dir -l bin/bash
-rwxr-xr-x 1 root root 1234376 2022-03-27 14:40 bin/bash*
/mnt/sys1# dir -l
lrwxrwxrwx 1 root root 7 2021-05-08 14:27 bin -> usr/bin/
lrwxrwxrwx 1 root root 7 2021-05-08 14:27 lib -> usr/lib/
lrwxrwxrwx 1 root root 9 2021-05-08 14:27 lib32 -> usr/lib32/
lrwxrwxrwx 1 root root 9 2021-05-08 14:27 lib64 -> usr/lib64/
lrwxrwxrwx 1 root root 10 2021-05-08 14:27 libx32 -> usr/libx32/
/mnt/sys1# dir -ld usr/lib*
drwxr-xr-x 78 root root 4096 2023-04-08 23:48 usr/lib/
drwxr-xr-x 2 root root 4096 2023-04-08 18:35 usr/lib32/
drwxr-xr-x 2 root root 4096 2023-04-08 18:35 usr/lib64/
drwxr-xr-x 4 root root 4096 2023-04-08 18:37 usr/libexec/
drwxr-xr-x 2 root root 4096 2023-04-08 18:35 usr/libx32/
/mnt/sys1# dir -l usr/bin/bash
-rwxr-xr-x 1 root root 1234376 2022-03-27 14:40 usr/bin/bash*
/mnt/sys1# file /bin/bash bin/bash
/bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=31c321f9f0c1f86a379f7efaaeb75f707998f27f, for GNU/Linux 3.2.0, stripped
bin/bash: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=31c321f9f0c1f86a379f7efaaeb75f707998f27f, for GNU/Linux 3.2.0, stripped
/mnt/sys1# cmp /bin/bash bin/bash && echo same
same
与可能丢失的依赖项不同,它在ldd
启动之前失败:
# strace -o /tmp/strace.log chroot /mnt/sys1 /bin/bash
chroot: failed to run command '/bin/bash': No such file or directory
# cat /tmp/strace.log
. . .
lstat("/mnt", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/mnt/sys1", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
chroot("/mnt/sys1") = 0
chdir("/") = 0
execve("/bin/bash", ["/bin/bash"], 0x7ffee9b47ff8 /* 121 vars */) = -1 ENOENT (No such file or directory)
write(2, "chroot: ", 8) = 8
write(2, "failed to run command '/bin/bash"..., 33) = 33
write(2, ": No such file or directory", 27) = 27
. . .
IEexecve
抱怨/bin/bash
不存在但这是正确的那里!
任何想法?
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
答案1
您只能chroot
以 root 用户身份运行。
不幸的是(至少 Debian 的)man chroot
没有提及这一点,但它在官方在线文档,
chroot
使用指定的根目录运行命令。在许多系统上,只有超级用户才能执行此操作。