LFS chroot cannot find /usr/bin/env

chrootchroot-jaillinuxpathshell

I am building Linux from Scratch (guide version 10.1). Everything compiled without any errors, but I am now stuck at the step where it requires me to enter the chroot environment (section 7.4). My command is the following:

chroot "$LFS" /usr/bin/env -i \
HOME=/root TERM="$TERM" \
PS1='(lfs chroot) \u:\w\$ ' \
PATH=/bin:/usr/bin:/sbin:/usr/sbin \
/bin/bash --login +h

It fails with the following error:

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

I have checked the following things:

$LFS points to the correct path

/dev, /run, /proc, /sys, /dev/pts and /dev/shm are all correctly mounted

/usr/bin/env exists

/bin/bash exists

/bin/sh is a symlink to /bin/bash

/bin/bash and /usr/bin/env have all their dependencies installed to /lib and /lib64 (checked using ldd)

Also, I want to point out that I am doing this build on x86-64, for x86-64, on Ubuntu 20.04 using Linux kernel 5.4.

Best Answer

I found the problem! It was a bad symlink (/lib64/ld-linux-x86-64.so.2 pointed to the absolute path on the host system, not relative to the LFS root, /lib/ld-2.36.so). It is such a shame that chroot gave me such a misleading and vague error message, instead of clarifying what and where went wrong. I changed the link, and now it works perfectly fine.

Related Question