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
  • 100,812
  • Thank you for your answer. I agree, this is the reason for the error I get from running "sudo chroot ." in the home directory. On the SD card however I have made a directory containing an Ubuntu image as the target for the chroot (which contains /bin/bash), still I get that different error (permission denied). – Ciofeca999 Jun 02 '16 at 12:04
  • Don't use an sd card. create chroot on your system. do what needs to be done and then "dd" the iso to the sd card. The sd card probably has its own formatting and does not understand permissions. – Rinzwind Jun 02 '16 at 12:13
  • @Ciofeca999 then please post a separate question about that, explaining how the SD card is mounted, what filesystem it is using etc. You might want to take the [tour] to understand how the site works. – terdon Jun 02 '16 at 12:15
  • I'll try to create a chroot on the system then. If this manages to solve my issue I will mark this answer as accepted and maybe dig more about my sdcard. Thank you both for your inputs! – Ciofeca999 Jun 02 '16 at 12:31
  • Nope. Just tried copying my Ubuntu touch image to a folder in my home directory (/home/phablet/linux) using "cp" and then sudo chrooting in that directory always gives me "Permission denied" – Ciofeca999 Jun 02 '16 at 13:14
  • @Ciofeca999 the details will depend on how you copied it. Was it only the image or did you mount the image and copy the contents? What permissions do you have for the various directories? is your file system mounted with exec? All sorts of details which is why I suggested you ask a different question. Comments aren't the place for this sort of thing. Also, if /home is the problem as suggested by the bug report, just use a different directory. – terdon Jun 02 '16 at 13:17
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