Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Unsupported Software
  • Search

Trying to debug my custom initramfs: ENOENT [SOLVED]

This forum covers all Gentoo-related software not officially supported by Gentoo. Ebuilds/software posted here might harm the health and stability of your system(s), and are not supported by Gentoo developers. Bugs/errors caused by ebuilds from overlays.gentoo.org are covered by this forum, too.
Post Reply
Advanced search
11 posts • Page 1 of 1
Author
Message
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

Trying to debug my custom initramfs: ENOENT [SOLVED]

  • Quote

Post by Zucca » Sun May 25, 2025 5:10 pm

Firstly, this is a amd64/musl/llvm system.

I've managed to set up almost everything in order, and I decided (yet again) to build a completely custom initramfs.
For some reason Linux, the kernel, cannot execute /init on my initramfs, so I extracted the image and tried to chroot into it.
Whatever I pass to chroot as the command I get "no such file or directory" -error.
So I started to dig deeper:

Code: Select all

# strace chroot /home/zucca/initramfstest /bin/bb
execve("/usr/bin/chroot", ["chroot", "/home/zucca/initramfstest", "/bin/bb"], 0x7ffe7011d220 /* 49 vars */) = 0
arch_prctl(ARCH_SET_FS, 0x7eff32cb7358) = 0
set_tid_address(0x7eff32cb4d88)         = 5383
brk(NULL)                               = 0x55d0fa79d000
brk(0x55d0fa79f000)                     = 0x55d0fa79f000
mmap(0x55d0fa79d000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x55d0fa79d000
mprotect(0x7eff32cb3000, 4096, PROT_READ) = 0
mprotect(0x55d0dbf1e000, 4096, PROT_READ) = 0
readlink("/home", 0x7ffee236af40, 1023) = -1 EINVAL (Invalid argument)
readlink("/home/zucca", 0x7ffee236af40, 1023) = -1 EINVAL (Invalid argument)
readlink("/home/zucca/initramfstest", 0x7ffee236af40, 1023) = -1 EINVAL (Invalid argument)
chroot("/home/zucca/initramfstest")     = 0
chdir("/")                              = 0
execve("/bin/bb", ["/bin/bb"], 0x7ffee236b4e8 /* 49 vars */) = -1 ENOENT (No such file or directory)
fcntl(1, F_GETFL)                       = 0x8002 (flags O_RDWR|O_LARGEFILE)
writev(2, [{iov_base="chroot: ", iov_len=8}, {iov_base=NULL, iov_len=0}], 2chroot: ) = 8
writev(2, [{iov_base="", iov_len=0}, {iov_base="failed to run command \342\200\230/bin/bb"..., iov_len=35}], 2failed to run command ‘/bin/bb’) = 35
writev(2, [{iov_base=": No such file or directory", iov_len=27}, {iov_base=NULL, iov_len=0}], 2: No such file or directory) = 27
writev(2, [{iov_base="", iov_len=0}, {iov_base="\n", iov_len=1}], 2
) = 1
close(1)                                = 0
close(2)                                = 0
exit_group(127)                         = ?
+++ exited with 127 +++
... those readlink calls getting failed doesn't seem like a problem. I guess chroot checks the path for symlinks. The tests failing indicate there's no symlink... That's how I read it.
Anyway. For the tests I've included every file musl package owns (qfile musl >> filelist). So I should have at least all the musl related dependencies there.

Any pointers?
Yes. My busybox and bash, etc aren't static. This same method has been working on my amd64/glibc/gcc boxes, so suspect llvm and/or musl bring something other to the table which I haven't noticed.
Last edited by Zucca on Sun Jun 01, 2025 7:55 am, edited 1 time in total.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
pingtoo
Advocate
Advocate
User avatar
Posts: 2180
Joined: Fri Sep 10, 2021 8:37 pm
Location: Richmond Hill, Canada

  • Quote

Post by pingtoo » Sun May 25, 2025 5:15 pm

If /bin/bb actually exist in the chroot dir. Then may be add "-ff" to strace to see if the child process will show why it complaint missing something.
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sun May 25, 2025 5:27 pm

Adding that doesn't produce any different results. I also tried with /bin/bash (which I added to the image because of this), but nope. It says no such file.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Hu
Administrator
Administrator
Posts: 24380
Joined: Tue Mar 06, 2007 5:38 am

  • Quote

Post by Hu » Sun May 25, 2025 5:55 pm

In my experience, the most common reason for ENOENT when trying to run a program that does exist is that the program specifies a program interpreter that does not exist. On an amd64 glibc-based system, the normal program interpreter for an ELF would be /lib64/ld-linux-x86-64.so.2. What does scanelf -i files show for the chroot's /bin/bash and /bin/bb? Does the shown interpreter exist in the chroot at the shown path?
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56075
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Sun May 25, 2025 6:26 pm

Zucca,

You need all the bits

Code: Select all

$ lddtree /bin/bash
/bin/bash (interpreter => /lib64/ld-linux-x86-64.so.2)
    libreadline.so.8 => /usr/lib64/libreadline.so.8
        libtinfow.so.6 => /lib64/libtinfow.so.6
    libtinfo.so.6 => /lib64/libtinfo.so.6
    libc.so.6 => /lib64/libc.so.6
or

Code: Select all

$ lddtree /bin/busybox 
/bin/busybox (interpreter => None)
busybox is static as it works when nothing else does.
Here bb is a symbolic link ... heh, so is busybox.
They both point to /ginit
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
zen_desu
Guru
Guru
Posts: 500
Joined: Fri Oct 25, 2024 3:14 pm
Location: your area

  • Quote

Post by zen_desu » Sun May 25, 2025 6:32 pm

Did you make sure to include /etc/ld-musl-{arch}.path?
µgRD dev
Wiki writer
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sun May 25, 2025 7:54 pm

Not a single error indicated I had something missing, but...

Code: Select all

qlist musl | grep '^/lib'
... returned nothing (strange...). So I manually added few essential files from /lib.
Also thanks zen_desu, I thought I had that file, but at some point I cleared my file list and forgot to re-add that.

Neddy, it seems my initramfs script needs some improvements. :) Indeed it failed to gather few dependencies. It uses ldd internally.
Since I now got busybox working, but bash fails to start. libreadline is missing some dependencies. Although I don't need bash there. busybox is enough.

I guess I need to add all the dependencies manually just to be sure.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Tue May 27, 2025 9:10 am

I think I've progressed a bit. I now have a somewhat working initramfs image.
But I'm bothered about one thing:

Code: Select all

# qlist musl | grep ^/lib
# equery f musl | grep ^/lib
# qfile /lib/libc.so
sys-libs/musl: /usr/lib/libc.so
# equery b /lib/libc.so
 * Searching for /lib/libc.so ... 
sys-libs/musl-1.2.5-r3 (/usr/lib/libc.so)
# file /lib/libc.so
/lib/libc.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
Now... there's something I don't understand how portage associates files to a package.
qfile and equery f only scan for database for the package. The files in /lib are not recorded to this database? Right? But are later hardlinked/reflinked/copied to /lib too for compability?

While my script doesn't use these portage tools (q and equery), this still might lead to why it didn't gather the required dependencies.

EDIT: Obviously /lib is a symlink to /usr/lib :facepalm:
Ok. Continuing... Nothing to see here. ':D
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sun Jun 01, 2025 7:53 am

So to conclude this:
  • I commonly use my own script to gather components to my initramfs image.
    It automatically pulls in libraries which ldd lists. However musl version of ldd does not display a header when processing more than one file. This header only consisted of the filename being processed.
    The solution to this was a simple

    Code: Select all

    xargs -n 1 ldd
    ... Not optimal but works.

    Also busybox awk segfaulted in the chroot for some reason. But not outside. My quick fix for it was to recompile busybox with very basic CFLAGS. This seemed strange...

    Lastly there was a bug in my gawk code which adds all the path components to the list in right order.
So now it "works" again. It still cannot magically pull in all the dependencies (like on case of, say shell scripts) as it solely relies on ldd, but that's just enough for me.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
zen_desu
Guru
Guru
Posts: 500
Joined: Fri Oct 25, 2024 3:14 pm
Location: your area

  • Quote

Post by zen_desu » Sun Jun 01, 2025 3:57 pm

Zucca wrote:So to conclude this:
  • I commonly use my own script to gather components to my initramfs image.
    It automatically pulls in libraries which ldd lists. However musl version of ldd does not display a header when processing more than one file. This header only consisted of the filename being processed.
    The solution to this was a simple

    Code: Select all

    xargs -n 1 ldd
    ... Not optimal but works.

    Also busybox awk segfaulted in the chroot for some reason. But not outside. My quick fix for it was to recompile busybox with very basic CFLAGS. This seemed strange...

    Lastly there was a bug in my gawk code which adds all the path components to the list in right order.
So now it "works" again. It still cannot magically pull in all the dependencies (like on case of, say shell scripts) as it solely relies on ldd, but that's just enough for me.
Does lddtree work better?
µgRD dev
Wiki writer
Top
Zucca
Moderator
Moderator
User avatar
Posts: 4681
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Sun Jun 01, 2025 8:14 pm

zen_desu wrote:Does lddtree work better?
The very first "pre-alpha" versions I developed tried to use lddtree. I cannot recall what was the problem with lddtree.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
Post Reply

11 posts • Page 1 of 1

Return to “Unsupported Software”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy