chroot

chroot: failed to run command '/bin/bash': Permission denied

$ sudo chroot /mnt/linux /bin/bash
chroot: failed to run command '/bin/bash': Permission denied

The error is what it says: /mnt/linux/bin/bash was found, but you are not allowed to execute it, even if you are root.
You will get the same error message if you run the command directly:

# /mnt/linux/bin/bash
bash: /mnt/linux/bin/bash: Permission denied

Most likely, the partition was mounted with the noexec flag, disallowing running any executable stored on that partition.
To check this, check the output of findmnt:

$ findmnt
...

chroot

Troubleshooting

When you use chroot, beware not to import variables from the host system which may affect the behaviour in the chroot system.

For example, one may experience strange bash errors in the chroot system. The genesis of the problem might be thus:

sudo mount -v -o bind /home /mnt/gentoo/home # /home is shared between the two systems!
sudo chroot /mnt/gentoo /bin/bash            # bash ariables from the host will bleed into the chroot'ed system
                                             # Bash scripts within ~/ will be eval'ed!

Where is my PS1 defined?

When I chroot into my gentoo environment, PS1 is defined but I don't know where.

$ sudo chroot /mnt/gentoo
# echo $PS1
\[\033]0;\u@\h:\w\007\]\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\]
/ # env-update && source /etc/profile
>>> Regenerating /etc/ld.so.cache...
# echo $PS1
\[\033]0;\u@\h:\w\007\]\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\]

I greped but couldn't find where that PS1 was defined...

Syndicate content