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

New to Debian (Or Linux in general)? Ask your questions here!

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

Postby dx486 » 2019-03-18 13:39

After I reinstalled Windows 10 to my dual boot computer, I cannot reach to the grub menu anymore. To fix this, I booted with a refind live USB stick. It recognized my debian stable system. However when I select the linux system, I don't see the grub menu, debian directly tries to boot, but it fails... During the boot it asks me for my encryption password and it passes that step successfully, however after "Mounted /home" line, it hangs for 1-2 minutes booting fails and it asks me to ENTER to continue. When I press ENTER, process fails with this message: "Cannot open access to console, the root account is locked."

At this point I decided to fix this problem with a most recent debian live USB stick. Unfortunately when I try to chroot to my debian system from the live usb environment, I get "chroot: failed to run command ‘/bin/bash’: No such file or directory" error. I did some research, but the suggestions online are not clear for me. I have been using debian for years but my knowledge of it is poor and I don't want to mess my system up by doing something wrong.

Could you please tell me how can I chroot to my debian system from a debian live usb environment?
dx486
 
Posts: 18
Joined: 2016-02-23 23:47

Re: chroot: failed to run command ‘/bin/bash’

Postby p.H » 2019-03-18 14:09

dx486 wrote:I cannot reach to the grub menu anymore

Can you elaborate ?
Is this a BIOS/legacy or EFI setup ?
dx486 wrote:chroot: failed to run command ‘/bin/bash’: No such file or directory

Did you chroot into the right filesystem ?
How is the system organized (partitions/encryption/LVM...) ?
p.H
 
Posts: 1184
Joined: 2017-09-17 07:12

Re: chroot: failed to run command ‘/bin/bash’

Postby dx486 » 2019-03-18 15:46

p.H wrote:
dx486 wrote:I cannot reach to the grub menu anymore

Can you elaborate ?
Is this a BIOS/legacy or EFI setup ?


I was using my computer with a dual-boot setup: Windows 10 & debian 9 stable. Grub menu was appearing every time I start my computer.
One day I decided to reinstall Windows 10. I deleted Windows partitions and reinstalled Windows 10 by a Windows 10 usb stick.
After that Windows 10 directly boots. There is no grub menu anymore.
It is an EFI setup.

p.H wrote:
dx486 wrote:chroot: failed to run command ‘/bin/bash’: No such file or directory

Did you chroot into the right filesystem ?
How is the system organized (partitions/encryption/LVM...) ?


The debian system's partitions are organized with LVM, encrypted during installation. There is only 1 volume group, contains /, /home and swap. Also there is a separate unencrypted /boot partition. I tried to chroot /boot partition. I cannot directly chroot to / partition as it is encrypted. But as I am writing this I realized that trying to chroot into /boot is nonsense...

Hmm... I guess there is no bash in /boot partition, that's why it cannot find it and gives that error message. I probably should decrypt my / partition with cryptsetup, then chroot to my / to fix the grub, right?

I installed cryptsetup to debian live system and unlocked encrypted partition as explained here, but I got the same error here. This is a volume group, so I probably that's why I cannot mount it. Probably I should try this. This is getting too complicated. :(
dx486
 
Posts: 18
Joined: 2016-02-23 23:47

Re: chroot: failed to run command ‘/bin/bash’

Postby p.H » 2019-03-18 16:46

dx486 wrote:I deleted Windows partitions and reinstalled Windows 10 by a Windows 10 usb stick.
After that Windows 10 directly boots. There is no grub menu anymore.
It is an EFI setup.

Did you also delete the EFI system partition ? Did you create a separate EFI partition for Debian ?
If you deleted the EFI partition used by Debian, you deleted GRUB. You will have to update the UUID for the new EFI partition in /etc/fstab and reinstall GRUB.
If you did not delete the EFI partition containing GRUB, you should be able to select Debian from the UEFI firmware boot menu. Windows boots just because it became first in the boot order. The boot order can be changed with efibootmgr or in the UEFI firmware setup.

dx486 wrote:I guess there is no bash in /boot partition, that's why it cannot find it and gives that error message. I probably should decrypt my / partition with cryptsetup, then chroot to my / to fix the grub, right?

Correct. You must open the encrypted volume and enable the LVM volumes (install lvm2 if not present).
Code: Select all
cryptsetup luksOpen /dev/sdXY sdXY_crypt
vgchange -ay
mount /dev/mapper/<vg>-<lv> /mnt

and so on.
Note that the Debian installer rescue mode offers a more convenient way to chroot a Debian system.
p.H
 
Posts: 1184
Joined: 2017-09-17 07:12

Re: chroot: failed to run command ‘/bin/bash’

Postby dx486 » 2019-03-19 17:14

First of all, thank you for your helpful replies!

p.H wrote:
dx486 wrote:I deleted Windows partitions and reinstalled Windows 10 by a Windows 10 usb stick.
After that Windows 10 directly boots. There is no grub menu anymore.
It is an EFI setup.

Did you also delete the EFI system partition ? Did you create a separate EFI partition for Debian ?
If you deleted the EFI partition used by Debian, you deleted GRUB. You will have to update the UUID for the new EFI partition in /etc/fstab and reinstall GRUB.
If you did not delete the EFI partition containing GRUB, you should be able to select Debian from the UEFI firmware boot menu. Windows boots just because it became first in the boot order. The boot order can be changed with efibootmgr or in the UEFI firmware setup.


Yes, I deleted EFI system partition, thinking debian's EFI files would be in the /boot partition, but it seems I was wrong.
I managed to chroot and read the /etc/fstab file. It is written there in the comments that debian's EFI files were installed to /dev/sda2, while boot files were installed to /dev/sda6 (flagged as /boot during installation). Now Windows' EFI partition is still /dev/sda2, therefore it seems I don't need to change the UUID in the fstab, I just need to reinstall GRUB... However I could not do that. I will explain why below.

p.H wrote:
dx486 wrote:I guess there is no bash in /boot partition, that's why it cannot find it and gives that error message. I probably should decrypt my / partition with cryptsetup, then chroot to my / to fix the grub, right?

Correct. You must open the encrypted volume and enable the LVM volumes (install lvm2 if not present).
Code: Select all
cryptsetup luksOpen /dev/sdXY sdXY_crypt
vgchange -ay
mount /dev/mapper/<vg>-<lv> /mnt

and so on.
Note that the Debian installer rescue mode offers a more convenient way to chroot a Debian system.


I first installed cryptsetup and then lvm2 to the live environment. Then I run the commands you mentioned, then chroot was successful.

However I could not do "apt update" in chroot mode (to / root) with the error message: "The method driver /usr/lib/apt/methods/https could not be found". For the same reason I could not run the command
Code: Select all
apt-get install --reinstall grub-efi
There are no "https" entry in the sources.list file or sources.list.d/base.list file. I don't know why I am getting this error. I cannot use apt or apt-get. I am stuck at this point. I will probably just backup my /home partition and reinstall debian. It seems it will be much hassle-free.
dx486
 
Posts: 18
Joined: 2016-02-23 23:47

Re: chroot: failed to run command ‘/bin/bash’

Postby Head_on_a_Stick » 2019-03-19 17:28

dx486 wrote:There are no "https" entry in the sources.list file or sources.list.d/base.list file

Are you sure? How about any other files under /etc/apt/sources.list.d/?

This will print out all source lines:
Code: Select all
grep -v '^#\|^$' /etc/apt/sources.list{,.d/*}

It is possible that one of your mirrors automatically redirects to https so try using http://deb.debian.org instead (the website itself redirects to https but the source shouldn't if you specify http).

Installing the apt-transport-https package will allow APT to use https sources, here is the .deb so you can use `dpkg -i` to install it:

http://deb.debian.org/debian/pool/main/ ... _amd64.deb
Don't break DebianHow to report bugs

SharpBang GNU/Linux® — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10695
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: chroot: failed to run command ‘/bin/bash’

Postby p.H » 2019-03-19 18:24

dx486 wrote:I managed to chroot and read the /etc/fstab file. It is written there in the comments that debian's EFI files were installed to /dev/sda2, while boot files were installed to /dev/sda6 (flagged as /boot during installation). Now Windows' EFI partition is still /dev/sda2, therefore it seems I don't need to change the UUID in the fstab

The partition number did not change but this is not what is used. If the partition has been deleted, re-created and re-formated, it has a new UUID and you must update it in /etc/fstab. Check with
Code: Select all
blkid /dev/sda2

Do not confuse the UUID with the PARTUUID which is much longer. You can use the PARTUUID value instead if you want, but you also have to replace UUID= with PARTUUID= in fstab.

dx486 wrote:Then I run the commands you mentioned, then chroot was successful.

Did you also mount /boot, /boot/efi, all the pseudo-filesystems which may be needed (/proc, /sys, /dev...) and so on ?

dx486 wrote:I could not run the command
Code: Select all
apt-get install --reinstall grub-efi

Why do you want to reinstall this package ? It is absolutely useless and does nothing by itself. It just depends on grub-efi-amd64|ia32 depending on the system architecture. Anyway you do not need to reinstall this package either. You do not even need to run a chroot to reinstall GRUB. You can do it from the live system.

From the chroot :
Mount /boot, /boot/efi, /proc, /dev, /sys.
Run "grub-install" without argument.
Done.

From the live system :
Mount the boot partition on /boot and the EFI partition on /boot/efi (create these directories if not present).
Install the package grub-efi-amd64-bin and its dependencies.
Run "grub-install" without argument.
Done.
p.H
 
Posts: 1184
Joined: 2017-09-17 07:12

Re: chroot: failed to run command ‘/bin/bash’

Postby dx486 » 2019-03-20 05:51

Head_on_a_Stick wrote:
dx486 wrote:There are no "https" entry in the sources.list file or sources.list.d/base.list file

Are you sure? How about any other files under /etc/apt/sources.list.d/?

This will print out all source lines:
Code: Select all
grep -v '^#\|^$' /etc/apt/sources.list{,.d/*}


It is possible that one of your mirrors automatically redirects to https so try using http://deb.debian.org instead (the website itself redirects to https but the source shouldn't if you specify http).

Installing the apt-transport-https package will allow APT to use https sources, here is the .deb so you can use `dpkg -i` to install it:

http://deb.debian.org/debian/pool/main/ ... _amd64.deb


Thank you for your answer.

Yes you are right, there were a file under the "sources.list.d" directory contained one https link.

I renamed this file to not include it (it was for a third party app) and I become sure that there are not any https anywhere.

"sources.list" file contained "http://ftp.us..." links and "base.list" file contained "http://deb.debian.org..." links... Just in case, I've changed all "ftp.us" links to "http://deb.debian.org" links as you suggested.

Then error regarding "https" disappeared but "Could not resolve" error appeared. Then I pinged google and realized that http addresses were not recognized in chroot mode... :?

I don't understand why did this happen as this was a perfectly working system. Why it did not see hosts file under /etc?

I guess I need to copy live system's hosts file to the chroot system, probably with these commands:

Code: Select all
sudo cp /mnt/etc/hosts /mnt/etc/hosts.old
sudo cp /etc/hosts /mnt/etc/hosts
sudo cp /etc/resolv.conf /mnt/etc/resolv.conf


Instead running these commands and making changes in the local system, I want to try to fix grub without doing a chroot as suggested.
Last edited by dx486 on 2019-03-20 06:01, edited 2 times in total.
dx486
 
Posts: 18
Joined: 2016-02-23 23:47

Re: chroot: failed to run command ‘/bin/bash’

Postby dx486 » 2019-03-20 05:57

p.H wrote:From the live system :
Mount the boot partition on /boot and the EFI partition on /boot/efi (create these directories if not present).
Install the package grub-efi-amd64-bin and its dependencies.
Run "grub-install" without argument.
Done.


This is a much easier method. I will be happy if I can do this. I want to try this without trying anything else. However I have a question first. When I boot to live USB, there is already a /boot of the live USB. How can I mount the boot partition to this already existing path?

Update: OK, I just tried to mount it to that path anyway and it mounted.
Last edited by dx486 on 2019-03-20 08:32, edited 2 times in total.
dx486
 
Posts: 18
Joined: 2016-02-23 23:47

Re: chroot: failed to run command ‘/bin/bash’

Postby p.H » 2019-03-20 08:16

You just mount the partition as usual. Whether the mount directory is empty or not is irrelevant.

Alternatively you can mount the boot and EFI partitions on directories of your choice, but then you have to indicate them in the grub-install command with --boot-directory= and --efi-directory= options.
p.H
 
Posts: 1184
Joined: 2017-09-17 07:12

Re: chroot: failed to run command ‘/bin/bash’

Postby dx486 » 2019-03-20 08:32

OK, I just tried to mount it to that path anyway and it mounted.

/dev/sda2 was my Windows' EFI partition. It only contained 2 directory: EFI/Boot and EFI/Microsoft.
/dev/sda5 was my Debian's /boot partition.

Mounted /dev/sda2 on /boot
Mounted /dev/sda5 on /boot/EFI

Installed grub-efi-amd64-bin and grub2-common packages on live USB.

Run
Code: Select all
sudo grub-install

on live USB.
Result:
Code: Select all
Installing for x84_64-efi platform.
grub-install: error: cannot find EFI directory.

Now I see a "grub" directory created in the /dev/sda2.
I also see some changes in the /dev/sda5. There are a "grub" and "efi" directory there, among other files.
dx486
 
Posts: 18
Joined: 2016-02-23 23:47

Re: chroot: failed to run command ‘/bin/bash’

Postby Head_on_a_Stick » 2019-03-20 10:35

dx486 wrote:/dev/sda2 was my Windows' EFI partition. It only contained 2 directory: EFI/Boot and EFI/Microsoft.
/dev/sda5 was my Debian's /boot partition.

Mounted /dev/sda2 on /boot
Mounted /dev/sda5 on /boot/EFI

You have it backwards: mount /dev/sda5 under /boot and mount /dev/sda2 (the EFI system partition) under /boot/efi

dx486 wrote:Run
Code: Select all
sudo grub-install

on live USB.

Without any arguments that command will look for the ESP under /boot/efi but you have mounted it under /boot

Either mount the ESP (/dev/sda2) under /boot/efi (and mount /dev/sda5 under /boot beforehand) and run the `grub-install` command without arguments or do as p.H suggested:
p.H wrote:you can mount the boot and EFI partitions on directories of your choice, but then you have to indicate them in the grub-install command with --boot-directory= and --efi-directory= options
Don't break DebianHow to report bugs

SharpBang GNU/Linux® — a pre-configured Openbox/Tint2 desktop running on Debian stable
User avatar
Head_on_a_Stick
 
Posts: 10695
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: chroot: failed to run command ‘/bin/bash’

Postby sickpig » 2019-04-03 10:56

p.H wrote:From the live system :
Mount the boot partition on /boot and the EFI partition on /boot/efi (create these directories if not present).
Install the package grub-efi-amd64-bin and its dependencies.
Run "grub-install" without argument.
Done.


A minor correction, grub-efi-amd64-bin's dependencies don't include grub2-common, which has the binary viz. grub-install.

Having said that am immensely grateful to this post. Yesterday I applied an image of my running laptop to my other laptop, an ssd one and was clueless about installing grub efi. This post made it amply clear.

I had figured out how to install grub on an mbr disk but was not sure about a gpt one. Thank you to all the posters here.
User avatar
sickpig
 
Posts: 320
Joined: 2019-01-23 10:34

Re: chroot: failed to run command ‘/bin/bash’

Postby p.H » 2019-04-03 18:41

sickpig wrote:I had figured out how to install grub on an mbr disk but was not sure about a gpt one.

This has nothing to do with GPT vs MBR. GRUB for EFI supports both partition schemes.
p.H
 
Posts: 1184
Joined: 2017-09-17 07:12

Re: chroot: failed to run command ‘/bin/bash’

Postby sickpig » 2019-04-03 20:06

Oh wasn't aware of that.
Thanks p.H, have learnt a lot just by reading your posts. U sir are an institution as far as grub and overall boot logic is concerned.
User avatar
sickpig
 
Posts: 320
Joined: 2019-01-23 10:34


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 9 guests

fashionable