|
|
| Next: mail server at linux |
| Author |
Message |
Angel Tsankov External

Since: May 04, 2006 Posts: 66
|
Posted: Fri May 05, 2006 10:33 am Post subject: chroot cannot find command Archived from groups: comp>os>linux>misc (more info?) |
|
|
I checked that /bin/ls exists, then I ran the following command
chroot /bin /bin/ls
and I got this:
chroot: cannot run command `/bin/ls`: No such file or directory
What is wrong?! |
|
| Back to top |
|
 |
Angel Tsankov External

Since: May 04, 2006 Posts: 66
|
Posted: Fri May 05, 2006 11:04 pm Post subject: Re: chroot cannot find command [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
>> I checked that /bin/ls exists, then I ran the following command
>>
>> chroot /bin /bin/ls
>>
>> and I got this:
>>
>> chroot: cannot run command `/bin/ls`: No such file or directory
>>
>> What is wrong?!
>
> Because in the chroot'd environment, it's not /bin/ls, it's /ls.
>
> Note that this is not likely to work either, since /bin/ls will probably
> require libraries in /lib, which will be inaccessible from the chroot'd
> environment.
Neither the above chroot command, neither the following work:
chroot /bin /ls
They both fail with exactly the same error message: chroot: cannot run command `/bin/ls`: No such file or directory
I also compiled a simple C program and put it in /bin (/bin/a.out):
int main( )
{
return 0;
}
Then I executed
chroot /bin /bin/a.out
chroot /bin /a.out
Both failed with chroot: cannot run command `...`: No such file or directory |
|
| Back to top |
|
 |
Vilmos Soti External

Since: May 03, 2005 Posts: 140
|
Posted: Fri May 05, 2006 11:04 pm Post subject: Re: chroot cannot find command [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
"Angel Tsankov" <fn42551 DeleteThis @fmi.uni-sofia.bg> writes:
>>> I checked that /bin/ls exists, then I ran the following command
>>> chroot /bin /bin/ls
>>> and I got this:
>>> chroot: cannot run command `/bin/ls`: No such file or directory
>>> What is wrong?!
>> Because in the chroot'd environment, it's not /bin/ls, it's /ls.
>> Note that this is not likely to work either, since /bin/ls will
>> probably require libraries in /lib, which will be inaccessible from
>> the chroot'd environment.
>
> Neither the above chroot command, neither the following work:
>
> chroot /bin /ls
>
> They both fail with exactly the same error message: chroot: cannot
> run command `/bin/ls`: No such file or directory
>
> I also compiled a simple C program and put it in /bin (/bin/a.out):
>
> int main( )
> {
> return 0;
> }
>
> Then I executed
> chroot /bin /bin/a.out
> chroot /bin /a.out
>
> Both failed with chroot: cannot run command `...`:
> No such file or directory
That's seems right. That error message "No such file or directory"
doesn't mean that your program is "missing", but that the dynamic
loader, and later the libraries, are not present.
Link your program statically, and it will (hopefully) work. This is
actual output, I just edited (threw out the invariant stuff) from
the output of "file":
# cat a.c
int main (void);
int main (void)
{
return 0;
}
# gcc -static -o a.static a.c
# gcc -o a.dynamic a.c
# file a.static
a.static: 80386, statically linked, not stripped
# file a.dynamic
a.dynamic: 80386, dynamically linked (uses shared libs), not stripped
# chroot /tmp/ /a.dynamic
chroot: cannot run command `/a.dynamic': No such file or directory
# chroot /tmp/ /a.static
#
Vilmos |
|
| Back to top |
|
 |
Douglas Mayne External

Since: Feb 13, 2006 Posts: 269
|
Posted: Fri May 05, 2006 11:04 pm Post subject: Re: chroot cannot find command [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
On Fri, 05 May 2006 23:04:47 +0300, Angel Tsankov wrote:
>>> I checked that /bin/ls exists, then I ran the following command
>>>
>>> chroot /bin /bin/ls
>>>
>>> and I got this:
>>>
>>> chroot: cannot run command `/bin/ls`: No such file or directory
>>>
>>> What is wrong?!
>>
>> Because in the chroot'd environment, it's not /bin/ls, it's /ls.
>>
>> Note that this is not likely to work either, since /bin/ls will probably
>> require libraries in /lib, which will be inaccessible from the chroot'd
>> environment.
>
> Neither the above chroot command, neither the following work:
>
> chroot /bin /ls
>
> They both fail with exactly the same error message:
> chroot: cannot run command `/bin/ls`: No such file or directory
>
> I also compiled a simple C program and put it in /bin (/bin/a.out):
>
> int main( )
> {
> return 0;
> }
>
> Then I executed
> chroot /bin /bin/a.out
> chroot /bin /a.out
>
> Both failed with chroot: cannot run command `...`: No such file or directory
>
Erik Max Francis tried to tell you that libraries are required. chroot is
non-trivial because the "root" filesystem is a fundamental element of
unix design. If you break it, you get to keep both pieces.
I compiled "Hello World" using the defaults. The resulting executable
includes these library dependancies:
$ ldd a.out
libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x40027000)
libm.so.6 => /lib/libm.so.6 (0x400df000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x40103000)
libc.so.6 => /lib/libc.so.6 (0x4010c000)
/lib/ld-linux.so.2 (0x40000000)
If any of the links are broken in the chroot'ed environment, then the
command won't run. The application's library links must resolve
_relative_ to the chroot environment. Most likely, /bin is not appropriate
for these links to resolve.
--
Douglas Mayne |
|
| Back to top |
|
 |
John-Paul Stewart External

Since: Mar 29, 2005 Posts: 1520
|
Posted: Fri May 05, 2006 11:04 pm Post subject: Re: chroot cannot find command [Login to view extended thread Info.] Archived from groups: per prev. post (more info?) |
|
|
Angel Tsankov wrote:
>>>I checked that /bin/ls exists, then I ran the following command
>>>
>>>chroot /bin /bin/ls
>>>
>>>and I got this:
>>>
>>>chroot: cannot run command `/bin/ls`: No such file or directory
>>>
>>>What is wrong?!
>>
>>Because in the chroot'd environment, it's not /bin/ls, it's /ls.
>>
>>Note that this is not likely to work either, since /bin/ls will probably
>>require libraries in /lib, which will be inaccessible from the chroot'd
>>environment.
>
>
> Neither the above chroot command, neither the following work:
>
> chroot /bin /ls
>
> They both fail with exactly the same error message: chroot: cannot run command `/bin/ls`: No such file or directory
Of course.
The error message is probably coming from 'ldd' (the dynamic linker)
when it can't find libraries under /lib (as the previous poster
mentioned). Do an 'ldd /bin/ls' and you'll get a list of all the
libraries that it requies. (The list is surprisingly long on this
system.) You'll need *all* of those libraries to appear under /lib *in
the chroot environment*.
Which brings us to the question: why are you trying to chroot to /bin?
That makes no sense. Build a full chroot environment someplace else
(/var/chroot or /home/chroot or ...) with copies of /bin and /lib (and
possibly bits of /dev and /etc and ...) and chroot to *that*. You
cannot just chroot to random points and you almost certainly don't want
the chroot environment cluttering up your /bin.
If you really don't want to have a copy of (parts of) /lib in your
chroot environment, you'll have to re-build all of the necessary
binaries using static linking. That's probably more work and would
likely take up more disk space than a proper chroot environment. |
|
| Back to top |
|
 |
|
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
| |
|
|