LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch
User Name
Password
Linux From Scratch This Forum is for the discussion of LFS.
LFS is a project that provides you with the steps necessary to build your own custom Linux system.

Notices


Reply
  Search this Thread
Old 03-01-2023, 11:53 PM   #1
necromorph98
LQ Newbie
 
Registered: Mar 2023
Posts: 6

Rep: Reputation: 1
Angry LFS 11.2 on Ubuntu Server 22.04: chroot: failed to run command ‘/usr/bin/env’: No such file or directory


I have been following the LFS 11.2 guide and it has gone smoothly up until the chroot part. Although the symlinks have created properly i.e. relative to the LFS directory, the error is still persistent.

Code:
necro-test@necro-server:/mnt/lfs$ ls -la lib64/
total 8
drwxrwxr-x  2 root       root 4096 Mar  1 10:39 .
drwxr-xr-x 17 necro-test root 4096 Mar  1 12:03 ..
lrwxrwxrwx  1 root       root   27 Mar  1 10:39 ld-linux-x86-64.so.2 -> ../lib/ld-linux-x86-64.so.2
lrwxrwxrwx  1 root       root   27 Mar  1 10:39 ld-lsb-x86-64.so.3 -> ../lib/ld-linux-x86-64.so.2
My mounts

Code:
necro-test@necro-server:/mnt/lfs$ findmnt | grep /mnt
    └─/mnt/lfs                                    /dev/sdb2                         ext2        rw,relatime
      ├─/mnt/lfs/dev                              udev                              devtmpfs    rw,nosuid,relatime,size=16241452k,nr_inodes=4060363,mode=755,inode64
      │ └─/mnt/lfs/dev/pts                        devpts                            devpts      rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000
      ├─/mnt/lfs/proc                             proc                              proc        rw,relatime
      ├─/mnt/lfs/sys                              sysfs                             sysfs       rw,relatime
      └─/mnt/lfs/run                              tmpfs                             tmpfs       rw,relatime,inode64
My PATH and ENV

Code:
necro-test@necro-server:/mnt/lfs$ echo $PATH && echo $LFS
    /mnt/lfs/tools/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
    /mnt/lfs


Previous posts had the problem of symlinks being to absolute paths like here. All my compilations were successful and all the directories have been setup properly. This is the command where it's failing

Code:
root@necro-server:/home/necro-test/partitioning# 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
chroot: failed to run command ‘/usr/bin/env’: No such file or directory
EDIT 1: Additional checks done

Code:
root@necro-server:/mnt/lfs# chroot $LFS /lib64/ld-linux-x86-64.so.2 --help
chroot: failed to run command ‘/lib64/ld-linux-x86-64.so.2’: No such file or directory

root@necro-server:/mnt/lfs# $LFS/usr/bin/env
SHELL=/bin/bash
SUDO_GID=1000
SUDO_COMMAND=/usr/bin/su
SUDO_USER=necro-test
PWD=/mnt/lfs
LOGNAME=root
HOME=/root
LANG=en_US.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
LESSCLOSE=/usr/bin/lesspipe %s %s
TERM=xterm-256color
LESSOPEN=| /usr/bin/lesspipe %s
USER=root
SHLVL=1
LFS_TGT=x86_64-lfs-linux-gnu
LFS=/mnt/lfs
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
SUDO_UID=1000
MAIL=/var/mail/root
LFS_DISK=/dev/sdb
_=/mnt/lfs/usr/bin/env

root@necro-server:/mnt/lfs# file $LFS/usr/bin/env
/mnt/lfs/usr/bin/env: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, with debug_info, not stripped

root@necro-server:/mnt/lfs# ls -la
total 48
drwxr-xr-x  16 necro-test root       4096 Mar  2 13:27 .
drwxr-xr-x   3 root       root       4096 Mar  2 08:10 ..
drwxrwxr-x   2 root       root       4096 Mar  2 12:24 bin
drwxrwxr-x   2 necro-test necro-test 4096 Mar  2 11:31 boot
drwxr-xr-x  21 root       root       4600 Mar  2 07:35 dev
drwxrwxr-x   2 root       root       4096 Mar  2 12:19 etc
drwxrwxr-x   2 root       root       4096 Mar  2 11:31 lib
drwxrwxr-x   2 root       root       4096 Mar  2 12:03 lib64
dr-xr-xr-x 534 root       root          0 Mar  2 13:29 proc
drwxrwxrwt   2 root       root         40 Mar  2 13:29 run
drwxrwxr-x   2 root       root       4096 Mar  2 11:31 sbin
drwxrwxr-x  25 necro-test necro-test 4096 Mar  2 13:22 sources
dr-xr-xr-x  13 root       root          0 Mar  2 07:35 sys
drwxrwxr-x   8 root       root       4096 Mar  2 12:03 tools
drwxrwxr-x   9 root       root       4096 Mar  2 12:40 usr
drwxrwxr-x   3 root       root       4096 Mar  2 12:19 var
I have already gone through previous posts having this problem but there nothing regarding this for the 11.2 revision so none of the solutions have helped me. What am i missing?

Last edited by necromorph98; 03-02-2023 at 11:05 PM. Reason: Additional Checks Done
 
Old 03-03-2023, 05:58 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,499
Blog Entries: 19

Rep: Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410
Is $LFS correctly set in this session? It's always worth checking.

Does the directory $LFS/usr/bin contain the env program?
 
Old 03-03-2023, 01:12 PM   #3
necromorph98
LQ Newbie
 
Registered: Mar 2023
Posts: 6

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by hazel View Post
Is $LFS correctly set in this session? It's always worth checking.

Does the directory $LFS/usr/bin contain the env program?
Yeah already double checked it it. Plus reinstalled everything just to be sure. The one thing that's bothering me is the following
Code:
necro-test@necro-server:/mnt/lfs$ ls -la lib64/
total 8
drwxrwxr-x  2 necro-test necro-test 4096 Mar  3 15:31 .
drwxr-xr-x 13 necro-test root       4096 Mar  3 14:32 ..
lrwxrwxrwx  1 necro-test necro-test   27 Mar  3 15:31 ld-linux-x86-64.so.2 -> ../lib/ld-linux-x86-64.so
lrwxrwxrwx  1 necro-test necro-test   27 Mar  3 15:31 ld-lsb-x86-64.so.3 -> ../lib/ld-linux-x86-64.so.2
necro-test@necro-server:/mnt/lfs$ ls -la lib
total 8
drwxrwxr-x  2 necro-test necro-test 4096 Mar  3 14:32 .
drwxr-xr-x 13 necro-test root       4096 Mar  3 14:32 ..
So we are creating a symlink to ld-linux-x86-64.so.2 in $LFS/lib but the directory is empty. I have repeated the whole install about 3-4 times now but i have the same result.
 
Old 03-04-2023, 04:47 AM   #4
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,499
Blog Entries: 19

Rep: Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410
Quote:
Originally Posted by necromorph98 View Post
Yeah already double checked it it. Plus reinstalled everything just to be sure. The one thing that's bothering me is the following
Code:
necro-test@necro-server:/mnt/lfs$ ls -la lib64/
total 8
drwxrwxr-x  2 necro-test necro-test 4096 Mar  3 15:31 .
drwxr-xr-x 13 necro-test root       4096 Mar  3 14:32 ..
lrwxrwxrwx  1 necro-test necro-test   27 Mar  3 15:31 ld-linux-x86-64.so.2 -> ../lib/ld-linux-x86-64.so
lrwxrwxrwx  1 necro-test necro-test   27 Mar  3 15:31 ld-lsb-x86-64.so.3 -> ../lib/ld-linux-x86-64.so.2
necro-test@necro-server:/mnt/lfs$ ls -la lib
total 8
drwxrwxr-x  2 necro-test necro-test 4096 Mar  3 14:32 .
drwxr-xr-x 13 necro-test root       4096 Mar  3 14:32 ..
So we are creating a symlink to ld-linux-x86-64.so.2 in $LFS/lib but the directory is empty. I have repeated the whole install about 3-4 times now but i have the same result.
Then you have installed glibc (and probably your other libraries) wrongly. They are supposed to go into $LFS/lib with only symbolic links in $LFS/lib64.

My guess is that you did not have $LFS properly set when you were building glibc. If I were you, I would wipe the LFS partition and start again.
 
Old 03-04-2023, 05:26 AM   #5
necromorph98
LQ Newbie
 
Registered: Mar 2023
Posts: 6

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by hazel View Post
My guess is that you did not have $LFS properly set when you were building glibc. If I were you, I would wipe the LFS partition and start again.
I am using the following script to automate the installation.
Code:
export LFS=/mnt/lfs
export LFS_TGT=x86_64-lfs-linux-gnu
export LFS_DISK=/dev/sdb

sudo mkdir -pv "$LFS"

if ! grep -q "$LFS" /proc/mounts; then
    source setupdisk.sh "$LFS_DISK"
    sudo mount "${LFS_DISK}2" "$LFS"
    sudo chown -v $USER "$LFS" 
fi

sudo apt install texinfo gcc g++ make bash binutils bison coreutils diffutils findutils gawk \
    grep gzip linux-headers-$(uname -r) m4 patch perl python3 sed tar xz-utils \
    help2man -y

mkdir -pv $LFS/{sources,tools,boot,etc,bin,lib,sbin,usr,var} $LFS/usr/{bin,lib,sbin}

case $(uname -m) in
    x86_64) mkdir -pv $LFS/lib64 ;;
esac

cp -rf *.sh chapter* *.csv "$LFS/sources"
cd "$LFS/sources"
export PATH="$LFS/tools/bin:$PATH"

source download.sh


#CHAPTER 5      
for package in linux-api-headers binutils gcc glibc libstdc++; do  
    echo -n ""
    source packageinstall.sh 5 $package
done

#CHAPTER 6 
for package in m4 bash coreutils diffutils file findutils gawk \
         grep gzip make patch sed tar xz binutils gcc ncurses; do   
    echo -n ""
    source packageinstall.sh 6 $package
done
Glibc scripts is as follows
Code:
case $(uname -m) in
    i?86) ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
    ;;
    x86_64) ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64
    ln -sfv ../lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
    ;;
esac

patch -Np1 -i ../glibc-$VERSION-fhs-1.patch

mkdir -v build
cd build

echo "rootsbindir=/usr/sbin" > configparms

../configure \
    --prefix=/usr \
    --host=$LFS_TGT \
    --build=$(../scripts/config.guess) \
    --enable-kernel=3.2 \
    --with-headers=$LFS/usr/include \
    libc_cv_slibdir=/usr/lib

make
make DESTDIR=$LFS install
sed '/RTLDLIST=/s@/usr@@g' -i $LFS/usr/bin/ldd

echo 'int main(){}' | gcc -xc -
readelf -l a.out | grep ld-linux
if [ $? == 0 ]; then
    rm -v a.out
    $LFS/tools/libexec/gcc/$LFS_TGT/12.2.0/install-tools/mkheaders
else
    echo "Error!: Sanity check not satisfied"
    exit 1
fi
I rechecked the commands for all the other libraries as well. They seem to match up with the book.

Which libraries are supposed to exist inside $LFS/lib other than glibc?

Last edited by necromorph98; 03-04-2023 at 05:31 AM.
 
Old 03-05-2023, 08:15 AM   #6
necromorph98
LQ Newbie
 
Registered: Mar 2023
Posts: 6

Original Poster
Rep: Reputation: 1
Fixed it by locating ld-linux-x86-64.so.2. It was in $LFS/usr/lib instead on $LFS/lib so i changed the symlink to
Code:
case $(uname -m) in
    i?86)   ln -sfv ld-linux.so.2 $LFS/lib/ld-lsb.so.3
    ;;
    x86_64) ln -sfv ../usr/lib/ld-linux-x86-64.so.2 $LFS/lib64
            ln -sfv ../usr/lib/ld-linux-x86-64.so.2 $LFS/lib64/ld-lsb-x86-64.so.3
    ;;
esac

Last edited by necromorph98; 03-06-2023 at 05:20 AM.
 
Old 03-05-2023, 11:58 AM   #7
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,499
Blog Entries: 19

Rep: Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410
That's not a solution, it's a sticking plaster. If you have installed something in the wrong place, you will keep on getting grief from it, more and more so as you go on. It's like building a wall: each row of bricks rests on the previous one. If a row is badly constructed, all the following rows will be affected, not just the next row up.

LFS is a good learning experience but it does require a certain degree of discipline to make it work. You have to be prepared to scrub everything and start again if something as basic as this is wrong.
 
Old 03-05-2023, 11:05 PM   #8
necromorph98
LQ Newbie
 
Registered: Mar 2023
Posts: 6

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by hazel View Post
That's not a solution, it's a sticking plaster. If you have installed something in the wrong place, you will keep on getting grief from it, more and more so as you go on. It's like building a wall: each row of bricks rests on the previous one. If a row is badly constructed, all the following rows will be affected, not just the next row up.

LFS is a good learning experience but it does require a certain degree of discipline to make it work. You have to be prepared to scrub everything and start again if something as basic as this is wrong.
Hey would it be possible for us to get together over a call and troubleshoot this? I have been stuck on this stage for the past 5-6 days, restarted the whole process 10-11 times but i don't want to do this the wrong way. I'll update the solution after our call.

Last edited by necromorph98; 03-06-2023 at 03:25 AM.
 
Old 03-06-2023, 04:31 AM   #9
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,499
Blog Entries: 19

Rep: Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410
I don't do calls; I have a low-cost internet connection with limited bandwidth. If you are in the UK, we could perhaps talk over the telephone but I doubt if that would do much good as I wouldn't be able to see your system.

I suspect that when you talk about "restarting the whole process", you mean starting the builds again. But what has gone wrong in your case is probably more basic than that, such as a wrongly defined environment for your LFS user. LFS newbies are always tempted to rush over the initial chapters in which the build environment is set up because that's boring and they want to get on and actually build their system. I can understand that, but LFS only works if you follow all the instructions systematically and exactly.

Checking your host software against the approved list is another job that newbies tend to skip over. For example, your host is a Debian derivative, so your system shell will be dash, not bash (bash is the default user shell but it won't be used in build scripts). And your awk program will be mawk and not gawk. Those things make a difference and have to be corrected before you start.

If I were in your position, I would clear the new partition completely except for the source packages. The tools directory goes too. Then start again from the very beginning, reading and following each paragraph in turn and not leaving anything out.

Last edited by hazel; 03-06-2023 at 04:33 AM.
 
Old 03-06-2023, 05:19 AM   #10
necromorph98
LQ Newbie
 
Registered: Mar 2023
Posts: 6

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by hazel View Post
I suspect that when you talk about "restarting the whole process", you mean starting the builds again. But what has gone wrong in your case is probably more basic than that, such as a wrongly defined environment for your LFS user.
This was exactly my suspicion as well. Actually i had been following this guide on youtube and that was my downfall. I skipped the following command in 4.2 which was the real culprit.
Code:
cd "$LFS"
for i in bin lib sbin; do
  ln -sv usr/$i $LFS/$i
done
Quote:
LFS newbies are always tempted to rush over the initial chapters in which the build environment is set up because that's boring and they want to get on and actually build their system. I can understand that, but LFS only works if you follow all the instructions systematically and exactly.
Completely agree with this assessment. I kept on going through all the library installations but i left out the inital setup commands assuming that the guide was complete and comprehensive. Learned a valuable lesson today.

Quote:
Checking your host software against the approved list is another job that newbies tend to skip over. For example, your host is a Debian derivative, so your system shell will be dash, not bash (bash is the default user shell but it won't be used in build scripts). And your awk program will be mawk and not gawk. Those things make a difference and have to be corrected before you start.
I already made sure this was fixed. Ran versioncheck.sh.

Now i can mark this issue as truly resolved. Let this post be a lesson to all future LFS newbies. Thanks for all your help hazel

Last edited by necromorph98; 03-06-2023 at 05:27 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] LFS 11.0 Stable -- 7.4 "Cannot enter chroot. "failed to run command /usr/bin/env : no such file or directory" ILikeTux Linux From Scratch 2 02-24-2022 10:08 AM
[SOLVED] 10.1 chroot issue with /usr/bin/env : No such file or directory goldennuggets Linux From Scratch 3 03-28-2021 12:50 PM
LFS 9.1 chroot: failed to run command ‘/tools/bin/env’: No such file or directory Dakaedr Linux From Scratch 10 04-05-2020 01:19 PM
[SOLVED] chroot: failed to run command ‘/tools/bin/env’: No such file or directory: chapter 6.4 zoelee4 Linux From Scratch 28 09-10-2016 06:38 PM
echo $PATH = /home/g3rc4n/bin:/usr/local/bin:/usr/bin:/bin:/usr/games ? i_heart_pandas Linux - Software 7 09-18-2009 08:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Linux From Scratch

All times are GMT -5. The time now is 06:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration