Re: chroot setup problem

2016-04-22 Thread tomas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Fri, Apr 22, 2016 at 09:36:57AM -0400, Haines Brown wrote:
> On Fri, Apr 22, 2016 at 10:36:36AM +0100, Karl E. Jorgensen wrote:
> 
> > >   # LANG=C.UTF8 /usr/sbin/chroot /mnt/debinst /bin/bash
> > >   /usr/sbin/chroot: failed to run command `/bin/bash': No such file or  
> > > directory 
> > > 
> > > /usr/bin/chroot exists. So does /mnt/debinst. So does /bin/bash.
> > 
> > /bin/bash is irrelevant in this context - the filename will be looked
> > up _inside_ the chroot, so you need to check that
> > /mnt/debinst/bin/bash exists (and the shared libraries it uses...)
> > 
> > Hope this helps
> > Karl
> 
> As for existence of /bin/bash in reference to new chroot:
> 
>   $ ls -la /mnt/debinst/bin | grep bash
>   -rwxr-xr-x  1 root   root   941252 Apr 22 06:22 bash
> 
> As for libraries, bash needs these:
> 
>   $ ldd /bin/bash
> linux-gate.so.1 =>  (0xb773e000)
> libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb7702000)
> libdl.so.2 => /lib/i386-linux-gnu/i686/cmov/libdl.so.2 (0xb76fe000)
> libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xb7599000)
> /lib/ld-linux.so.2 (0xb773f000)
> 
> So I create directories and copy libraries to them. I didn't understand
> the first line and apparently there is no linux-gate.so.1 on my
> system. Other than it, I now have:
> 
>   $ ls /mnt/debinst/lib
>   i386-linux-gnu ld-linux.so.2
> 
>   $ ls /mnt/debinst/lib/i386*
>   i686 libtinfo.so.6
> 
>   $ ls -la /mnt/debinst/lib/i386*/i686/cmov
>   ...
>   -rwxr-xr-x 1 root root 1446056 Apr 22 08:47 libc.so.6
>   -rw-r--r-- 1 root root9844 Apr 22 08:49 libdl.so.2
> 
> Now chroot command has better luck:
> 
>   # LANG=C.UTF-8 /usr/sbin/chroot /mnt/debinst/
>   bash-4.2#
>   
> I guess copying over the libraries was the answer. However, my chroot
> prompt used to appear as: root@hostname:/#, so I'm not sure I'm in
> chroot. 

Easy: if you can't see the "rest of the world" (that is the things you
haven't copied over/bind-mounted etc.) then you most probably are :-)

regards
- -- t
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlcaLM8ACgkQBcgs9XrR2kYZUACdEOM/kFg9imCKinslqUQaw6lP
mHoAnilVMOCFGsBxNhEAja1AEYAIDhm7
=TLH8
-END PGP SIGNATURE-



Re: chroot setup problem

2016-04-22 Thread Haines Brown
On Fri, Apr 22, 2016 at 10:36:36AM +0100, Karl E. Jorgensen wrote:

> >   # LANG=C.UTF8 /usr/sbin/chroot /mnt/debinst /bin/bash
> >   /usr/sbin/chroot: failed to run command `/bin/bash': No such file or  
> > directory 
> > 
> > /usr/bin/chroot exists. So does /mnt/debinst. So does /bin/bash.
> 
> /bin/bash is irrelevant in this context - the filename will be looked
> up _inside_ the chroot, so you need to check that
> /mnt/debinst/bin/bash exists (and the shared libraries it uses...)
> 
> Hope this helps
> Karl

As for existence of /bin/bash in reference to new chroot:

  $ ls -la /mnt/debinst/bin | grep bash
  -rwxr-xr-x  1 root   root   941252 Apr 22 06:22 bash

As for libraries, bash needs these:

  $ ldd /bin/bash
linux-gate.so.1 =>  (0xb773e000)
libtinfo.so.5 => /lib/i386-linux-gnu/libtinfo.so.5 (0xb7702000)
libdl.so.2 => /lib/i386-linux-gnu/i686/cmov/libdl.so.2 (0xb76fe000)
libc.so.6 => /lib/i386-linux-gnu/i686/cmov/libc.so.6 (0xb7599000)
/lib/ld-linux.so.2 (0xb773f000)

So I create directories and copy libraries to them. I didn't understand
the first line and apparently there is no linux-gate.so.1 on my
system. Other than it, I now have:

  $ ls /mnt/debinst/lib
  i386-linux-gnu ld-linux.so.2

  $ ls /mnt/debinst/lib/i386*
  i686 libtinfo.so.6

  $ ls -la /mnt/debinst/lib/i386*/i686/cmov
  ...
  -rwxr-xr-x 1 root root 1446056 Apr 22 08:47 libc.so.6
  -rw-r--r-- 1 root root9844 Apr 22 08:49 libdl.so.2

Now chroot command has better luck:

  # LANG=C.UTF-8 /usr/sbin/chroot /mnt/debinst/
  bash-4.2#
  
I guess copying over the libraries was the answer. However, my chroot
prompt used to appear as: root@hostname:/#, so I'm not sure I'm in
chroot. 

Haines



Re: chroot setup problem

2016-04-22 Thread Cindy-Sue Causey
On 4/22/16, Haines Brown  wrote:
> On Fri, Apr 22, 2016 at 12:04:41AM +, Mark Fletcher wrote:
>
>> Does /mnt/debinst/bin/bash exist?
>>
>> It's looking for /bin/bash in the chrooted environment and not finding
>> it.
>
> I fixed this and:
>
>   $ ls -la /mnt/debinst/bin
>   ...
>   -rwxr-xr-x  1 root   root   941252 Apr 22 06:22 bash
>
> but still:
>
>   # LANG=C.UTF8 chroot /mnt/debinst /mnt/debinst/bin/bash
>   chroot: failed to run command `/mnt/debinst/bin/bash':
> No such file or directory
>
> Am I misunderstanding the chroot syntax? It seems the object is to run
> /mnt/debinst/bin/bash with its root being /mnt/debinst/.


This is the [syntax] I use:

LANG=C.UTF-8 chroot /mnt/cin /bin/bash

/mnt/cin was my easier to type and remember alternative to /mnt/debinst.

Gets it done for me every time. It was just a twist on what I'd found
on the Net when I first taught myself that part of Debian (for
debootstrap installations). I'd never *thought* about how or why it
was doing what it was doing until reading through this thread...

Are you all saying that it starts looking for /bin/bash AFTER it's
inside the chroot session?

I started to say: "If the answer to that question is yes, then what's
happening with the failed /mnt/debinst/bin/bash is that the
/mnt/debinst path in fact does *not* exist to your target chroot
session once you're inside chroot. That aspect of the process was hard
for my brain to wrap itself around originally after a few years's
worth of experience where anything Linux was able to access anything
else it wanted."

BUT: After thinking yet that much harder on this, maybe there's some
magic command that a fellow user knows that changes that. The
potential for such a command never occurred to me because I had no
driving need for it. I could always complete what was needed by simply
switching between terminals that represented a latest shiny, new
deboostrap install and its old, worn out, "cruft" filled predecessor.

Just now the thought crossed my mind that maybe some chroot sessions
do in fact demand the ability to access the outside World depending on
their purpose along with what's already installed. Since you're
working with /mnt/debinst, I'm a-suming this is potentially a
phenomenally basic deboostrap install attempt because I remember being
instructed to create that same directory for my own original
debootstrap attempts.

Good luck!

Cindy

-- 
Cindy-Sue Causey
Talking Rock, Pickens County, Georgia, USA

* would run in a pair of rain galoshes... if she owned them *



Re: chroot setup problem

2016-04-22 Thread tomas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Fri, Apr 22, 2016 at 06:57:17AM -0400, Haines Brown wrote:
> On Fri, Apr 22, 2016 at 12:04:41AM +, Mark Fletcher wrote:
> > 
> > On Fri, 22 Apr 2016 at 08:18, Haines Brown  wrote:
> > 
> > I attempt to chroot from /dev/sdb on /dev/sda.
> > 
> >   # mount /dev/sda1 /mnt/debinst
> > 
> > I verify it is mounted and then do:
> > 
> >   # LANG=C.UTF8 /usr/sbin/chroot /mnt/debinst /bin/bash
> >   /usr/sbin/chroot: failed to run command `/bin/bash': No such file or
> >     directory
>  
> > Does /mnt/debinst/bin/bash exist?
> > 
> > It's looking for /bin/bash in the chrooted environment and not finding it.
> 
> I fixed this and:
> 
>   $ ls -la /mnt/debinst/bin
>   ...
>   -rwxr-xr-x  1 root   root   941252 Apr 22 06:22 bash
> 
> but still:
> 
>   # LANG=C.UTF8 chroot /mnt/debinst /mnt/debinst/bin/bash
>   chroot: failed to run command `/mnt/debinst/bin/bash':
> No such file or directory

Once chrooted, the system "sees" /mnt/debinst/bin/bash as /bin/bash.

So in the chroot environment you have to invoke /bin/bash.

Don't forget the libraries. On my system, bash needs:

  tomas@rasputin:~$ ldd /bin/bash
  linux-vdso.so.1 (0x7ffe1ed62000)
  libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 
(0x7fe653e81000)
  libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x7fe653c7d000)
  libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x7fe6538d8000)
  /lib64/ld-linux-x86-64.so.2 (0x55a841653000)

Bash has to "see" them on the same paths, so you'd need to make them
available (copy, bind-mount, whatever) on /mnt/debinst/lib/...

regards
- -- t
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlcaBNMACgkQBcgs9XrR2kYEkwCfQFX6Jom+VS/Cl2p46wRiH6tw
ZsQAn3zQyxbsnPsmdtNvz0AQnHJgxLQl
=8nnp
-END PGP SIGNATURE-



Re: chroot setup problem

2016-04-22 Thread Haines Brown
On Fri, Apr 22, 2016 at 12:04:41AM +, Mark Fletcher wrote:
> 
> On Fri, 22 Apr 2016 at 08:18, Haines Brown  wrote:
> 
> I attempt to chroot from /dev/sdb on /dev/sda.
> 
>   # mount /dev/sda1 /mnt/debinst
> 
> I verify it is mounted and then do:
> 
>   # LANG=C.UTF8 /usr/sbin/chroot /mnt/debinst /bin/bash
>   /usr/sbin/chroot: failed to run command `/bin/bash': No such file or
>     directory
 
> Does /mnt/debinst/bin/bash exist?
> 
> It's looking for /bin/bash in the chrooted environment and not finding it.

I fixed this and:

  $ ls -la /mnt/debinst/bin
  ...
  -rwxr-xr-x  1 root   root   941252 Apr 22 06:22 bash

but still:

  # LANG=C.UTF8 chroot /mnt/debinst /mnt/debinst/bin/bash
  chroot: failed to run command `/mnt/debinst/bin/bash':
No such file or directory

Am I misunderstanding the chroot syntax? It seems the object is to run 
/mnt/debinst/bin/bash with its root being /mnt/debinst/.

I did this:

  # LANG=C.UTF8 chroot /mnt/debinst
  chroot: failed to run command `/bin/bash': No such file or directory

  $ ls /bin | grep bash
  bash
  rbash

  $ ls /mnt/debinst/bin | grep bash
  bash

Haines
 



 






Re: chroot setup problem

2016-04-22 Thread Karl E. Jorgensen
On Thu, Apr 21, 2016 at 07:17:14PM -0400, Haines Brown wrote:
> I attempt to chroot from /dev/sdb on /dev/sda. 
> 
>   # mount /dev/sda1 /mnt/debinst
> 
> I verify it is mounted and then do:
> 
>   # LANG=C.UTF8 /usr/sbin/chroot /mnt/debinst /bin/bash
>   /usr/sbin/chroot: failed to run command `/bin/bash': No such file or  
> directory 
> 
> /usr/bin/chroot exists. So does /mnt/debinst. So does /bin/bash.

/bin/bash is irrelevant in this context - the filename will be looked
up _inside_ the chroot, so you need to check that
/mnt/debinst/bin/bash exists (and the shared libraries it uses...)

Hope this helps

--
Karl



Re: chroot setup problem

2016-04-21 Thread Mark Fletcher
On Fri, 22 Apr 2016 at 08:18, Haines Brown  wrote:

> I attempt to chroot from /dev/sdb on /dev/sda.
>
>   # mount /dev/sda1 /mnt/debinst
>
> I verify it is mounted and then do:
>
>   # LANG=C.UTF8 /usr/sbin/chroot /mnt/debinst /bin/bash
>   /usr/sbin/chroot: failed to run command `/bin/bash': No such file or
> directory
>
> /usr/bin/chroot exists. So does /mnt/debinst. So does /bin/bash.
>
> Haines Brown
>
> Does /mnt/debinst/bin/bash exist?

It's looking for /bin/bash in the chrooted environment and not finding it.

Mark