我使用 buildroot 创建了 rootfs ,但使用 crosstool-ng 工具链和 glibc 。这向我展示了必要的最小文件集。然后我将所有库替换为从armel
的挤压 .deb 包直接拉出的库。然后,我将fakeroot
和fakechroot
添加到混合中(也来自 .deb 包)。我还根据自己的喜好修改了resolv.conf
,hosts
和nsswitch.conf
文件。上传到我的设备后,很多工作正常。 cd /
把我带到了正确的地方。 whoami
返回root。但是,任何DNS相关的东西都不起作用。例如ping google.com
返回错误地址。我已经复制了 libnss _ * 和 libresolv 库以及我认为必要的所有其他内容。输入相同的设置,但在我的主机上使用 qemu 和 chroot 可以正常工作,但我正在尝试弄清楚它在我的目标设备上无法正常工作。
当我运行strace ping google.com
时,我得到以下内容:
open("/data/local/target/bin/ping", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\2\0(\0\1\0\0\0\0\314\0\0004\0\0\0"..., 4094) = 4094
close(3) = 0
execve("/data/local/target/bin/ping", ["ping", "google.com"], [/* 20 vars */]) = 0
brk(0) = 0xb5000
uname({sys="Linux", node="localhost", ...}) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4001d000
open("/data/local/target/usr/lib/fakechroot/libfakechroot.so", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\364\32\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0666, st_size=45540, ...}) = 0
mmap2(NULL, 77628, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40026000
mprotect(0x40031000, 28672, PROT_NONE) = 0
mmap2(0x40038000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xa) = 0x40038000
close(3) = 0
open("/data/local/target/usr/lib/libfakeroot/libfakeroot-sysv.so", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\340'\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0666, st_size=29092, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x4001f000
mmap2(NULL, 60672, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40039000
mprotect(0x40040000, 28672, PROT_NONE) = 0
mmap2(0x40047000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6) = 0x40047000
close(3) = 0
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libc.so.6", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/lib/libc.so.6", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\374V\1\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=1209660, ...}) = 0
mmap2(NULL, 1246468, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40048000
mprotect(0x4016b000, 32768, PROT_NONE) = 0
mmap2(0x40173000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x123) = 0x40173000
mmap2(0x40176000, 9476, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x40176000
close(3) = 0
open("tls/v7l/neon/vfp/libdl.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/lib/libdl.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0$\t\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=9808, ...}) = 0
mmap2(NULL, 41136, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40179000
mprotect(0x4017b000, 28672, PROT_NONE) = 0
mmap2(0x40182000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1) = 0x40182000
close(3) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40020000
set_tls(0x40020170, 0x40020847, 0x40020848, 0x40020170, 0x40025000) = 0
mprotect(0x40182000, 4096, PROT_READ) = 0
mprotect(0x40173000, 8192, PROT_READ) = 0
mprotect(0xb1000, 4096, PROT_READ) = 0
mprotect(0x40024000, 4096, PROT_READ) = 0
brk(0) = 0xb5000
brk(0xd6000) = 0xd6000
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libnss_compat.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/lib/libnss_compat.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0|\r\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=26480, ...}) = 0
mmap2(NULL, 57952, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40184000
mprotect(0x4018a000, 28672, PROT_NONE) = 0
mmap2(0x40191000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x5) = 0x40191000
close(3) = 0
open("tls/v7l/neon/vfp/libnsl.so.1", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/lib/libnsl.so.1", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0x/\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=75732, ...}) = 0
mmap2(NULL, 116488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x40193000
mprotect(0x401a5000, 28672, PROT_NONE) = 0
mmap2(0x401ac000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x11) = 0x401ac000
mmap2(0x401ae000, 5896, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x401ae000
close(3) = 0
mprotect(0x401ac000, 4096, PROT_READ) = 0
mprotect(0x40191000, 4096, PROT_READ) = 0
open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/usr/lib/libnss_nis.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/data/local/target/lib/libnss_nis.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0X\30\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=38608, ...}) = 0
mmap2(NULL, 70236, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401b0000
mprotect(0x401b9000, 28672, PROT_NONE) = 0
mmap2(0x401c0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x8) = 0x401c0000
close(3) = 0
open("tls/v7l/neon/vfp/libnss_files.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/lib/libnss_files.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0\330\31\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=42688, ...}) = 0
mmap2(NULL, 74492, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401c2000
mprotect(0x401cc000, 28672, PROT_NONE) = 0
mmap2(0x401d3000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x9) = 0x401d3000
close(3) = 0
mprotect(0x401d3000, 4096, PROT_READ) = 0
mprotect(0x401c0000, 4096, PROT_READ) = 0
open("/data/local/target/etc/passwd", O_RDONLY|O_CLOEXEC) = 3
fcntl64(3, F_GETFD) = 0x1 (flags FD_CLOEXEC)
_llseek(3, 0, [0], SEEK_CUR) = 0
fstat64(3, {st_mode=S_IFREG|0666, st_size=596, ...}) = 0
mmap2(NULL, 596, PROT_READ, MAP_SHARED, 3, 0) = 0x40021000
_llseek(3, 596, [596], SEEK_SET) = 0
munmap(0x40021000, 596) = 0
close(3) = 0
getpid() = 9034
socket(PF_NETLINK, SOCK_RAW, 0) = 3
bind(3, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 0
getsockname(3, {sa_family=AF_NETLINK, pid=9034, groups=00000000}, [12]) = 0
gettimeofday({1366748508, 414909}, NULL) = 0
sendto(3, "\24\0\0\0\26\0\1\3\\\355vQ\0\0\0\0\0\0\0\0", 20, 0, {sa_family=AF_NETLINK, pid=0, groups=00000000}, 12) = 20
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"0\0\0\0\24\0\2\0\\\355vQJ#\0\0\2\10\200\376\1\0\0\0\10\0\1\0\177\0\0\1"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 108
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"@\0\0\0\24\0\2\0\\\355vQJ#\0\0\n\200\200\376\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 128
recvmsg(3, {msg_name(12)={sa_family=AF_NETLINK, pid=0, groups=00000000}, msg_iov(1)=[{"\24\0\0\0\3\0\2\0\\\355vQJ#\0\0\0\0\0\0\1\0\0\0\24\0\1\0\0\0\0\0"..., 4096}], msg_controllen=0, msg_flags=0}, 0) = 20
close(3) = 0
open("/etc/resolv.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
uname({sys="Linux", node="localhost", ...}) = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 3
connect(3, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
close(3) = 0
open("/etc/nsswitch.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
open("tls/v7l/neon/vfp/libnss_dns.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/lib/libnss_dns.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0000\v\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=18040, ...}) = 0
mmap2(NULL, 49316, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401d5000
mprotect(0x401d9000, 28672, PROT_NONE) = 0
mmap2(0x401e0000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3) = 0x401e0000
close(3) = 0
open("tls/v7l/neon/vfp/libresolv.so.2", O_RDONLY) = -1 ENOENT (No such file or directory)
...
open("/data/local/target/lib/libresolv.so.2", O_RDONLY) = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0(\0\1\0\0\0H$\0\0004\0\0\0"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0777, st_size=71524, ...}) = 0
mmap2(NULL, 79772, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x401e2000
mmap2(0x401f2000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x10) = 0x401f2000
mmap2(0x401f4000, 6044, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x401f4000
close(3) = 0
mprotect(0x401f2000, 4096, PROT_READ) = 0
mprotect(0x401e0000, 4096, PROT_READ) = 0
open("/etc/host.conf", O_RDONLY) = -1 ENOENT (No such file or directory)
stat64("/etc/resolv.conf", 0xbed0eee8) = -1 ENOENT (No such file or directory)
gettimeofday({1366748508, 437074}, NULL) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366748508, 438028}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\234\32\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366748508, 440124}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\234\32\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
gettimeofday({1366748508, 441638}, NULL) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366748508, 442345}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\302\373\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
socket(PF_INET, SOCK_DGRAM|SOCK_NONBLOCK, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(53), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
gettimeofday({1366748508, 444280}, NULL) = 0
poll([{fd=3, events=POLLOUT}], 1, 0) = 1 ([{fd=3, revents=POLLOUT}])
send(3, "\302\373\1\0\0\1\0\0\0\0\0\0\6google\3com\0\0\1\0\1", 28, MSG_NOSIGNAL) = 28
poll([{fd=3, events=POLLIN}], 1, 5000) = 1 ([{fd=3, revents=POLLERR}])
close(3) = 0
open("/data/local/target/etc/hosts", O_RDONLY|O_CLOEXEC) = 3
fcntl64(3, F_GETFD) = 0x1 (flags FD_CLOEXEC)
fstat64(3, {st_mode=S_IFREG|0666, st_size=40, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40021000
read(3, "127.0.0.1\tlocalhost\n127.0.1.1\tbu"..., 4096) = 40
read(3, "", 4096) = 0
close(3) = 0
munmap(0x40021000, 4096) = 0
write(2, "ping: bad address 'google.com'\n", 31) = 31
exit_group(1) = ?
很多事情都是正确的。它知道在搜索可执行文件和库时将 / data / local / target 添加到路径中。您可以看到它找到各种 libnss _ * 库,并且它发现主机文件不仅仅是/etc/hosts
,但为什么您认为它没有找到正确的位置对于nsswitch.conf
和resolv.conf
?这似乎是fakechroot
问题或我如何使用它的问题。
答案 0 :(得分:0)
看起来fopen在其他库/可执行文件中的使用可以通过使用指向libfakechroot的LD_PRELOAD来拦截,但不能在eglibc本身内调用fopen。您必须手动编辑eglibc源并构建它。看起来他们做得很好很容易。
这已经过测试并且有效。