Arch linux no such file or directory

chroot: failed to run command ‘/bin/bash’: No such file or directory

Can the question be considered a pure duplicate of unix.stackexchange.com/questions/76490/…? The answers to the questions represent a possible solution for the problem definitely worth a link, but that doesn’t make the question a duplicate of it.

The issue for me was that I was using a 32-bit Live CD to mount a 64-bit OS disk and chroot to it. A 32-bit kernel can’t run 64-bit bash. The solution was to get a 64-bit Live CD. (The linked duplicate is entirely unrelated.)

This is not a duplicate, despite the explanation of the source of the problem being applicable to both questions. The question this is marked a duplicate of is about missing libraries on a generic install, whereas this question is specifically about an error occurring in a chrooted environment.

14 Answers 14

This error means that there is no /bin/bash directory inside chroot. Make sure you point it to where bash (or other shell’s) executable is in chroot directory.

If you have /mnt/somedir/usr/bin/bash then execute chroot /mnt/somedir /usr/bin/bash .

Apart from the above, you also need to add libc directory dependencies, as mentioned in the answer here.

It might be caused by some failing command/line in /root/.bashrc or /root/.bash_profile in your chroot . Can you temporarily rename these files? Also can you make sure that bash is executable ( chmod +x /chroot/bin/bash )?

aspade@home-ba:~/DebianArm$ sudo chmod +x rootfs/bin/bash. aspade@home-ba:~/DebianArm$ sudo chroot rootfs. chroot: failed to run command ‘/bin/bash’: No such file or directory

I figured it out. bin/bash is there, but I didn’t have /lib and /lib64 inside it. /bin/bash depends (ofc) on libc, ld-linux, libdl etc. So simple cp -a /usr rootfs/, cp -a /lib rootfs/, cp -a /lib64 rootfs/ was enough. (You can mount-bind those ofc, but I copied them, because I want to run something dangerous, which might corrupt those files in rootfs.) The message from chroot could be more descriptive. «no such file or directory» really means «I can’t run this sh. «.

Читайте также:  Linux приставка для телевизора

I had /bin/bash inside chrooted directory, but I didn’t have /lib and /lib64 inside it. The message from chroot could be more descriptive. «no such file or directory» really means «I can’t run this. «.

/bin/bash depends of course on libc , ld-linux , libdl etc., you can use ldd /bin/bash to see which libraries it requires.

  1. You can mount -o bind these directories under chroot
  2. Or you can copy these libraries to chroot , if you don’t trust the chrooted env to not corrupt them, like so:
cp -a /usr rootfs/ cp -a /lib rootfs/ cp -a /lib64 rootfs/ 

This doesn’t create duplicates if you use the first method (marked as 1)). The second one is useful if you chroot to untrusted environment. For example, you have a partition with a trojan or something.

my «/lib» was not a symlink to usr/lib , it was actually a real folder! that happened after I tried to checkinstall vmwareplayer and it failed saying there was a new version installed. Then I guess that when checkinstall tried to revert the changes, it (or vmwareplayer installer) messed up /lib. That also caused a problem making ubuntu22.04 unbootable because /sbin/init or /etc/init not found.

chroot tries to start the shell that is set in your $SHELL environment variable by default, but it looks for it in your new root dir, which seems not to contain /bin/bash , so it cannot start.

You can tell chroot to start another program inside the new root by simply adding it as a parameter:

chroot /your/new/root /bin/foo --options. 

Note that the path of the command is interpreted inside your new root, so in this example the called program is in fact in /your/new/root/bin/foo

I was getting the same error when trying to ssh to a chrooted account on a remote server. In my case, I was missing the following file in the remote lib64 directory. Server is Centos6.9

It was fixed by executing the following:

cp /lib64/ld-linux-x86-64.so.2 /secure/jail/lib64/ 

didn’t fix it for me, but doing cp -r /lib /lib64 /secure/jail fixed it, i needed something from both lib and lib64, and i didn’t bother to figure out exactly what. (probably because i had multiarch enabled)

In case you are doing a cross compilation you need to use qemu simulator which can run /mnt/somedir/bin/bash. Below are the steps for armhf cross compilation. Steps for other architectures should be similar.

sudo apt-get install qemu-user-static

sudo cp /usr/bin/qemu-arm-static /mnt/usr/bin/

Once you copy the qemu-arm-static into the /mnt/usr/bin you will be able to do chroot.

The errors are same for both the cases. If someone who is doing cross compilation faces this issue, he can find the answer here.

That was actually my case, I created a rootfs for arm64 on a x86 and using debootstrap but in order for the chroot to work I had to run qemu-debootstrap which added ‘usr/bin/qemu-aarch64-static` under the rootfs. Somehow the chroot command is able to detect it and execute the bash inside the qemu

On an Ubuntu Jammy amd64 host, and Debian Unstable riscv64 chroot, I simply installed qemu-user-static on the host and it started working. No need to copy anything, which is nice.

I was getting this error as well, but the solution turned out to be much simpler for me than many of the above answers. I was simply chroot’ing to the wrong directory.

On modern versions of the product my team supports, the product chroot is /opt/productname , hence we use sudo chroot /opt/productname .

On very old versions of the product, the product chroot is named /opt/productname-x-y-z . ie it has the version appended to the product chroot name.

So sudo chroot /opt/productname on the old system, gave me the «chroot: command failed . » error. On the old system, /opt/productname existed, but was not actually a chroot directory.

Make it sure /lib is a symlink to usr/lib .

In my case, in ubuntu 22.04, after I tried to checkinstall vmwareplayer, the /lib got messed up when it failed saying there was a new version installed. Then I guess that when checkinstall tried to revert the changes, it (or vmwareplayer installer) messed up /lib.

So the /lib was not a symlink to usr/lib , it was actually a real empty folder!

That also caused a serious problem making ubuntu22.04 unbootable because of /sbin/init or /etc/init not found: run-init: can’t execute ‘/sbin/init’: No such file or directory and /etc/init permission denied
It caused also kernel panic attempted to kill init on boot time.

you need to run ldd against bash ldd $(which bash) , then you might find a missing dependency, for example if you didn’t mount/copy lib64, for 64 systems, it will through this error.

Something no one has mentioned yet, if the goal is not to keep copies of libraries you locate with ldd. When you build busybox it respects LDFLAGS=—static per their FAQ. This will build all necessary libraries into your binaries. This does increase the size of the binaries, but. you’d need most of this disk space to store what you’re locating with ldd anyway.

Note that you may still need to copy your c library (libc.so.6), core math library (libm.so.6), namespace resolution library (libresolv.so.2), and kernel library (in my case, since I am using a raspberry pi, ld-linux-armhf.so.3) . You can use the ldd tool as directed in other answers on your static busybox binary to discover whether this is the case.

These may in turn depend on other libraries. To discover whether this is the case you can use the file tool. I am using the full path to raspberry pi’s libm.so.6 as an example :

file /chroot/lib/arm-linux-gnueabihf/libm.so.6 

In my case, since ARM processors need many libraries, I copied my entire arm-linux-gnueabihf folder into my lib folder, allowing me to access my chroot.

Источник

Arch Linux

the /lib/modules/3.2.5-1-ARCH folder is there alright but no build, I guess that’s a temporary folder for build but I cannot see how I can fix this?

Last edited by dabbi2000 (2012-02-25 13:21:27)

#2 2012-02-16 21:53:10

Re: [SOLVED] Build failed: no such file or directory?

Did you upgrade your kernel and forget to reboot? 3.2.6-1-ARCH is out.

EDIT: 3.2.6-2-ARCH is out now. Haha. As was also suggested, please make sure you have linux-headers installed as well.

Last edited by jstoik1 (2012-02-16 22:03:45)

#3 2012-02-16 21:58:33

Re: [SOLVED] Build failed: no such file or directory?

 pacman -Syu base-devel linux-headers 

Last edited by Cory_j (2012-02-16 22:50:06)

#4 2012-02-16 22:12:20

dabbi2000 Member From: Reykjavik, Iceland Registered: 2011-09-28 Posts: 119 Website

Re: [SOLVED] Build failed: no such file or directory?

I did a pacman -Syu, everything is up to date, doesn’t upgrade to 3.2.6.1-ARCH but are you 100% sure that is the problem, the correct version folder is there?

#5 2012-02-16 22:12:39

Re: [SOLVED] Build failed: no such file or directory?

The PKGBUILD should be fixed, it should use the ‘extramodules’ dir now:

$ ls /lib/modules/ 3.2.6-2-ARCH extramodules-3.2-ARCH

Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

#6 2012-02-16 22:28:49

Re: [SOLVED] Build failed: no such file or directory?

pacman -Syu base-devel linux-headers 

Last edited by Cory_j (2012-02-16 22:47:07)

#7 2012-02-16 23:06:03

Re: [SOLVED] Build failed: no such file or directory?

My suggestion still stands.

Got Leenucks? :: Arch: Power in simplicity :: Get Counted! Registered Linux User #392717 :: Blog thingy

#8 2012-02-18 15:10:48

dabbi2000 Member From: Reykjavik, Iceland Registered: 2011-09-28 Posts: 119 Website

Re: [SOLVED] Build failed: no such file or directory?

B, do you mean the install -D [. ] part? Sorry I’m not so good with PKGBUILD (but willing to learn!)

Cory, base-devel gives me tons of options:

1) autoconf 2) automake 3) binutils 4) bison 5) fakeroot 6) flex 7) gcc 8) libtool 9) m4 10) make 11) patch 12) pkg-config

I haven’t got a clue which one to install!

Источник

Оцените статью
Adblock
detector