[arch-general] Executing a command of a chroot outside of the chroot
I have a chroot environment on /data/workbench/mnt and I want to execute a binary which is inside the chroot environment (for example /data/workbench/mnt/bin/bash). I added the chroot library path to $LD_LIBRARY_PATH and I just did /data/workbench/mnt/bin/bash. I get a very strange error: No such file or directory. I am ABSOLUTELY sure that the file exists. When I chroot /data/workbench/mnt /bin/bash everything runs smoothly without errors. What's going on? BTW: I'm on armv7l -- (\_ /) copy the bunny to your profile (0.o ) to help him achieve world domination. (> <) come join the dark side. /_|_\ (we have cookies.)
On 6 December 2012 15:07, Δημήτρης Ζέρβας <01ttouch@gmail.com> wrote:
I have a chroot environment on /data/workbench/mnt and I want to execute a binary which is inside the chroot environment (for example /data/workbench/mnt/bin/bash). I added the chroot library path to $LD_LIBRARY_PATH and I just did /data/workbench/mnt/bin/bash. I get a very strange error: No such file or directory. I am ABSOLUTELY sure that the file exists. When I chroot /data/workbench/mnt /bin/bash everything runs smoothly without errors. What's going on?
BTW: I'm on armv7l
Just a guess but the file that doesn’t exist might be the ELF loader aka interpreter. You can find out what it is by using the “ldd”, or “readelf” commands: $ readelf --segments /bin/bash . . . INTERP 0x0000000000000238 0x0000000000400238 0x0000000000400238 0x000000000000001a 0x000000000000001a R 1 [Requesting program interpreter: /lib/ld-linux-x86-64.so.2] It should vary depending on architecture and ABI. Then you might be able to invoke it manually: ROOT/lib/ld-linux-WHATEVER ROOT/bin/bash Hope this helps, but it would probably only be practical for really simple programs; you’ll probably have the same problem when Bash tries to execute something.
the main system is android and the chroot is Arch linux, so I have no ldd nor readelf...
On Fri, Dec 7, 2012 at 7:03 AM, Δημήτρης Ζέρβας <01ttouch@gmail.com> wrote:
the main system is android and the chroot is Arch linux, so I have no ldd nor readelf...
But the dynamic loader must exist... you can invoke it manually if only you know the name. You can get the name of the interpreter with "objdump -j .interp -s program". Or you can try and guess. For example, in my Arch box it is "/lib/ld-linux.so.2" (a link to "/lib/ld-2.16.so"), so it is likely that it is names something similar. So run: # /data/workbench/mnt/lib/ld-linux.so.2 /data/workbench/mnt/bin/bash and see what happens. -- Rodrigo
yes, you're right, I skipped some useful info. with ld-linux2.so it works!! Is there a way to automate it? e.g. '/data/workbench/mnt/bin/bash'?
On 7 December 2012 23:50, Δημήτρης Ζέρβας <01ttouch@gmail.com> wrote:
yes, you're right, I skipped some useful info. with ld-linux2.so it works!! Is there a way to automate it? e.g. '/data/workbench/mnt/bin/bash'?
Maybe can you make a symbolic link? ln -s /data/workbench/mnt/lib/ld-linux2.so /lib/
I think that linking won't solve my problem as I include /data/workbench/mnt/lib in my $LD_LIBRARY_PATH...
Op 7 dec. 2012 23:46 schreef "Δημήτρης Ζέρβας" <01ttouch@gmail.com> het volgende:
I think that linking won't solve my problem as I include /data/workbench/mnt/lib in my $LD_LIBRARY_PATH...
In that case; isn't it enough to include /data/workbench/mnt/lib as the first item in $LD_LIBRARY_PATH ? I realise that my understanding of this var could be flawed. Mvg, Guus
On Sat, Dec 8, 2012 at 12:16 AM, Guus Snijders <gsnijders@gmail.com> wrote:
Op 7 dec. 2012 23:46 schreef "Δημήτρης Ζέρβας" <01ttouch@gmail.com> het volgende:
I think that linking won't solve my problem as I include /data/workbench/mnt/lib in my $LD_LIBRARY_PATH...
In that case; isn't it enough to include /data/workbench/mnt/lib as the first item in $LD_LIBRARY_PATH ? I realise that my understanding of this var could be flawed.
Mvg, Guus
That link should work as long as it does not clash with the real dynamic loader. Since you are using an Android, it should not happen. In my Android phone the dynamic loader is "/system/bin/linker" and the "/lib" directory doesn't even exist. AFAIK, there is no way to change the embedded dynamic linker when running the executable directly. Maybe some trick with the "binfmt_misc" could do the trick but I don't think it is enabled on Android. If you really need this, you may have to resort to change every program in the chroot for a script that does the magic needed. Now what really intrigues me is why you want to call a chroot'ed program from outside of the chroot... -- Rodrigo
participants (4)
-
Guus Snijders
-
Martin Panter
-
Rodrigo Rivas
-
Δημήτρης Ζέρβας