Results 1 to 10 of 10

Thread: chroot not working: "cannot run command `/bin/bash': No such file or directory"

  1. #1
    Join Date
    Oct 2009
    Beans
    41
    Distro
    Ubuntu 10.10 Maverick Meerkat

    chroot not working: "cannot run command `/bin/bash': No such file or directory"

    I'm trying to change the root directory to /tmp/somedir using chroot, but even using sudo or su-ing to root I get the message:

    Code:
    cannot run command `/bin/bash': No such file or directory
    I tried copying /bin/bash to /tmp/somedir/, but the same error occurs. What's wrong with my chroot?

  2. #2
    Join Date
    Jul 2005
    Location
    2 exits past crazy
    Beans
    4,222
    Distro
    Lubuntu 12.10 Quantal Quetzal

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    Please post the exact command you run when trying to chroot.

  3. #3
    Join Date
    Oct 2009
    Beans
    41
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    Code:
    sudo chroot /tmp/somedir
    or


    Code:
    sudo chroot /tmp/somedir bash

  4. #4
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    How did you create the chroot environment?

    What's the content of /tmp/somedir?

    Code:
    ls /tmp/somedir

  5. #5
    Join Date
    Oct 2009
    Beans
    41
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    I had just created it with "mkdir /tmp/somedir"

    Since I copied bash to it, ls /tmp/somedir gives:

    bin

    and inside it is just bash.

  6. #6
    Join Date
    Aug 2007
    Beans
    949

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    From the manpage:

    Code:
    NAME
           chroot - run command or interactive shell with special root directory
    
    SYNOPSIS
           chroot NEWROOT [COMMAND [ARG]...]
           chroot OPTION
    Without any command, as you invoked it, chroot attempts to run the shell (/bin/sh) but if that doesn't exist in the target directory, then it won't work out.

    If you want to run a specific command in a chroot'ed jail, you should just invoke the command directly instead of trying to meticulously set up an environment within an environment -- much easier that way.

  7. #7
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    Quote Originally Posted by Geraba View Post
    I had just created it with "mkdir /tmp/somedir"

    Since I copied bash to it, ls /tmp/somedir gives:

    bin

    and inside it is just bash.
    The chroot directory must be populated with a minimum set of files.

    You can use debootstrap to create a minimal, Ubuntu or Debian, chroot environment: /community/DebootstrapChroot.

  8. #8
    Join Date
    Oct 2009
    Beans
    41
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    But since I copied bash there, shouldn't it at least run and then give an error about the lack of files?

  9. #9
    Join Date
    Aug 2008
    Beans
    1

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"

    Hello,
    thread is dead for more than 10 months, but maybe this reply will save someone precioussss time...

    For chrooting few things must be done:
    1. creation of directory for chroot environment - e.g. /home/chroot

    2. creation subdirectories proc, dev and lib inside above chroot directory:
      Code:
      mkdir /home/chroot/{dev,proc,lib}
    3. binding /dev/ and /proc/ directories to this chroot directory:
      Code:
      mount --bind /dev/ /home/chroot/dev/
      mount --bind /proc/ /home/chroot/proc/
    4. copying/link files which will be used in chrooted environment into /home/chroot/ into proper directory - e.g. /bin/bash should be placed in /home/chroot/bin/bash

    5. finding and copying/link library files needed for above files (e.g. /bin/bash) into proper directories, must be used command:
      Code:
      ldd /bin/bash


    And after all of this you can try to run chroot environment. I hope that I haven't miss anything important. In fact you should try to google for setting chroot

    At last, but not least: message cannot run command `/bin/bash': No such file or directory" is not complete and can be misleading. It should be more complete for example like this: cannot run command `/bin/bash': No such file, directory or library files for this command".
    Without 2 last steps of creating chroot list, /bin/bash in chrooted environment won't run even if bash would be placed in /home/chroot/bin/ directory (without proper libraries).

  10. #10
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: chroot not working: "cannot run command `/bin/bash': No such file or directory"



    Thread Closed.
    Last edited by sisco311; January 11th, 2012 at 11:55 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •