4

I am trying to reset my root password for my dedicated CentOS 7 server and keep getting the error below

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

I am logged in through "rescue mode" which allows me to reset to password if I forgot it or make any other necessary changes.

I mounted the partition with:

# mount /dev/md127 /mnt/

But when I try to chroot I get the error that bash does not exist even though it does exist as you can see here:

root@rescue:~# chroot /mnt/
chroot: failed to run command ‘/bin/bash’: No such file or directory
root@rescue:~# ls /bin/bash
/bin/bash
root@Rescue:~#

1 Answers1

2

Chroot is complaining because it can't find /bin/bash inside the chroot environment, so it can't drop you on a shell there. Mount your device, then check inside:

# mount /dev/md127 /mnt/
# ls /mnt/bin/bash

If I'm guessing right this won't show anything. If there's a valid shell in your chroot you can change your SHELL environment variable. For instance if bash is at (/mnt)/usr/bin/bash:

# SHELL=/usr/bin/bash chroot /mnt

(Look for sh, csh, dash...)

But you probably don't even need a shell. You can specify the command to run directly when chrooting.

# chroot /mnt passwd

See man chroot for more details.

Also, for changing your password you probably won't need it, but when chrooting for debugging purposes (like if your system doesn't boot) you usually have to bind a few paths like /dev, /dev/tty, /sys and /proc. Eg mount -o bind /dev /mnt/dev. So programs can access your devices, process information etc. while in the chrooted environment.

Pik'
  • 166