3

In terminal when I try to sudo chroot . in home directory I get:

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

When I try to sudo chroot . in external Sd card I get:

chroot: failed to run command ‘/bin/bash’: Permission denied

I found out there was a chroot bug reported about this, but there on 2016/04/12 they say:

"Changed in canonical-devices-system-image:  
status:  
Fix Committed → Fix Released"

I am on a Bq Aquaris m10 HD running Ubuntu 15.04 (OTA-11). This bug also affected OTA 10.1, but I decided to wait for the next OTA. Is anyone else experiencing this behaviour?

I'm asking this because I'd like to install some cli tools without messing the system and breaking much needed OTAs. I'm following this guide: https://askubuntu.com/a/623311.
Is there any other way to install cli tools without setting the filesystem as writable?

Any workaround is welcome

Edit: Problem solved! As terdon and Rinzwind pointed out the "Permission denied" error was due to not having execution permits in my external SDcard. I downloaded and extracted the ubuntu image in a folder in my home directory and I can now chroot in it just fine. Thanks!

2 Answers2

2

I am not at all sure the bug you linked to is relevant here. You can't just chroot to an arbitrary directory like that. By default, chroot will set / to the directory you gave it and then try to run /bin/sh (or whatever the default shell is). Since there is no /bin/sh in the target directory, it complains. That's what you see in the first error:

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

The second error is probably because you have mounted a FAT or NTFS partition in the external drive and you haven't set it up to allow execution. It looks like /path/to/external/bin/sh exists but can't be executed. Try mounting the SD card with execution enabled.

Note that the guide you linked to tells you to download an Ubuntu image and use that as the chroot target. It doesn't tell you to use your home directory for it!

To illustrate:

$ sudo chroot .
chroot: failed to run command ‘/bin/bash’: No such file or directory
$ cp /bin/busybox bin/sh 
$ sudo chroot /bin/sh   ### works!
# /
terdon
  • 104,119
0

Try to do that from a folder not inside /home like

chroot path_chroot_folder

Look at the comment in the bug report link you shared about doing "chroot ." specifically

Jamie Strandboge (jdstrand) wrote on 2016-01-15: #3
The reason why this doesn't work is because this rule carves out
/home: /[^h][^o][^m][^e]** pix,
We needed to do that for autopilot fakeenv-style tests. I think this style of test has been abandoned due to other issues though; if that is true, I can simplify the exec transition rules and remove these autopilot rules. Nicholas, can you comment?
Changed in apparmor-easyprof-ubuntu (Ubuntu): assignee: nobody → Nicholas Skaggs (nskaggs) status: Confirmed → Incomplete