landley / toybox

toybox
http://landley.net/toybox
BSD Zero Clause License
2.41k stars 335 forks source link

make root fails #302

Closed YKG closed 2 years ago

YKG commented 2 years ago

Hi, I want to build a minimal working Linux system, I followed the instruction, but make root fails.

log ```console ubuntu@vm:~/toybox$ make root scripts/mkroot.sh Building for host === toybox cleaned cc -o kconfig/conf kconfig/conf.c kconfig/zconf.tab.c -DKBUILD_NO_NLS=1 \ -DPROJECT_NAME=\"ToyBox\" In file included from kconfig/zconf.tab.c:2340: kconfig/confdata.c: In function 'conf_write': kconfig/confdata.c:435:20: warning: '.tmpconfig.' directive writing 11 bytes into a region of size between 1 and 128 [-Wformat-overflow=] 435 | sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); | ^~~~~~~~~~~~~~~~~ kconfig/confdata.c:435:3: note: 'sprintf' output between 13 and 150 bytes into a destination of size 128 435 | sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ scripts/genconfig.sh kconfig/conf -D /dev/fd/63 Config.in > /dev/null scripts/make.sh Generate headers from toys/*/*.c... generated/newtoys.h warning: using unfinished code from toys/pending Library probe.............. Make generated/config.h from .config. generated/flags.h generated/globals.h generated/tags.h generated/help.h Compile toybox.....................................toys/net/netstat.c: In function 'display_routes': toys/net/netstat.c:254:3: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result] 254 | fgets(toybuf, sizeof(toybuf), fp); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ toys/net/netstat.c: In function 'show_ip': toys/net/netstat.c:103:3: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result] 103 | fgets(toybuf, sizeof(toybuf), fp); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ toys/net/netstat.c: In function 'show_unix_sockets': toys/net/netstat.c:173:3: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result] 173 | fgets(toybuf, sizeof(toybuf), fp); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ......................................................................................toys/other/watchdog.c: In function 'watchdog_main': toys/other/watchdog.c:48:5: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result] 48 | write(TT.fd, "", 1); | ^~~~~~~~~~~~~~~~~~~ toys/other/watchdog.c: In function 'safe_shutdown': toys/other/watchdog.c:34:3: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result] 34 | write(TT.fd, "V", 1); | ^~~~~~~~~~~~~~~~~~~~ ........toys/pending/sh.c: In function 'pl2str': toys/pending/sh.c:974:7: warning: format not a string literal and no format arguments [-Wformat-security] 974 | len += snprintf(ss+len, ss ? INT_MAX : 0, s); | ^~~ ................................................toys/posix/tar.c: In function 'unpack_tar': toys/posix/tar.c:819:13: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result] 819 | (void)write(sefd, 0, 0); | ^~~~~~~~~~~~~~~~~ ............./usr/bin/ld: generated/obj/id.o: in function `do_id': id.c:(.text.do_id+0x133): warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_xwrap.o: in function `xsetuser': xwrap.c:(.text.xsetuser+0xf): warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_xwrap.o: in function `xgetgrgid': xwrap.c:(.text.xgetgrgid+0x8): warning: Using 'getgrgid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_xwrap.o: in function `xgetgid': xwrap.c:(.text.xgetgid+0x1e): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_lib.o: in function `bufgetgrgid': lib.c:(.text.bufgetgrgid+0x86): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_xwrap.o: in function `xgetuid': xwrap.c:(.text.xgetuid+0x1e): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_xwrap.o: in function `xgetpwuid': xwrap.c:(.text.xgetpwuid+0x8): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_lib.o: in function `bufgetpwuid': lib.c:(.text.bufgetpwuid+0x86): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/lib_net.o: in function `xgetaddrinfo': net.c:(.text.xgetaddrinfo+0x62): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/passwd.o: in function `passwd_main': passwd.c:(.text.passwd_main+0x80): warning: Using 'getspnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/route.o: in function `get_hostname.constprop.0': route.c:(.text.get_hostname.constprop.0+0x20): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/hostname.o: in function `hostname_main': hostname.c:(.text.hostname_main+0xca): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: generated/obj/netstat.o: in function `addr2str': netstat.c:(.text.addr2str+0x11c): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a(unwind-dw2.o): in function `uw_init_context_1': (.text+0x1f05): undefined reference to `pthread_once' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `__register_frame_info_bases.part.0': (.text+0x1698): undefined reference to `pthread_mutex_lock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `__register_frame_info_table_bases': (.text+0x17ac): undefined reference to `pthread_mutex_lock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `__deregister_frame_info_bases': (.text+0x1872): undefined reference to `pthread_mutex_lock' /usr/bin/ld: (.text+0x18ba): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: (.text+0x193d): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `_Unwind_Find_FDE': (.text+0x1a74): undefined reference to `pthread_mutex_lock' /usr/bin/ld: (.text+0x1b98): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: (.text+0x1bd9): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `__register_frame_info_bases.part.0': (.text+0x16cb): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/libgcc_eh.a(unwind-dw2-fde-dip.o): in function `__register_frame_info_table_bases': (.text+0x17df): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/librt.a(timer_create.o): in function `__timer_create_new': (.text+0x12f): undefined reference to `pthread_once' /usr/bin/ld: (.text+0x22e): undefined reference to `pthread_mutex_lock' /usr/bin/ld: (.text+0x24c): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/librt.a(timer_routines.o): in function `timer_helper_thread': (.text+0xa9): undefined reference to `pthread_exit' /usr/bin/ld: (.text+0x118): undefined reference to `pthread_mutex_lock' /usr/bin/ld: (.text+0x16e): undefined reference to `pthread_create' /usr/bin/ld: (.text+0x17a): undefined reference to `pthread_mutex_unlock' /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/librt.a(timer_routines.o): in function `__start_helper_thread': (.text+0x271): undefined reference to `__pthread_get_minstack' /usr/bin/ld: (.text+0x27c): undefined reference to `pthread_attr_setstacksize' /usr/bin/ld: (.text+0x2b9): undefined reference to `pthread_create' collect2: error: ld returned 1 exit status make: *** [Makefile:17: toybox] Error 1 make: *** [Makefile:80: root] Error 1 ubuntu@vm:~/toybox$ ```

Here is my environment:

ubuntu@vm:~/toybox$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.2 LTS (Focal Fossa)"
...
ubuntu@vm:~/toybox$ gcc --version
gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
...

ubuntu@vm:~/toybox$ /usr/lib/x86_64-linux-gnu/libc.so.6
GNU C Library (Ubuntu GLIBC 2.31-0ubuntu9.2) stable release version 2.31.
...
ubuntu@vm:~/toybox$
landley commented 2 years ago

Huh, the new ubuntu's glibc is so broken that A) it can't use getpwnam() in a static application (it needs a shared library to read /etc/passed), B) it's using libpthread code from libgcc_eh.a and thus literally can't build "hello world" without -lpthread. That's new levels of broken even for glibc.

landley commented 2 years ago

I've confirmed that yes, ubuntu 20.04 trying to build "LDFLAGS=--static make distclean defconfig toybox" does indeed inexplicably attempt to link it against libpthread. (But building a static "hello world" doesn't.) Trying to track down why...

landley commented 2 years ago

Doesn't do it for allnoconfig. Bit of a hunt, I'll see what I can track down. Thanks for the heads up.

landley commented 2 years ago

The timeout command is pulling in libgcc_eh.a which is pulling in libpthread. What the...

YKG commented 2 years ago

@landley Thanks for your information! I just tried to build it in Ubuntu 14.04 LTS, it still fails.

log ```console ubuntu@vm:~/toybox$ make root scripts/mkroot.sh Building for host === toybox cleaned cc -o kconfig/conf kconfig/conf.c kconfig/zconf.tab.c -DKBUILD_NO_NLS=1 \ -DPROJECT_NAME=\"ToyBox\" scripts/genconfig.sh yes '' | kconfig/conf -o Config.in > /dev/null scripts/make.sh Generate headers from toys/*/*.c... generated/newtoys.h Library probe.............. Make generated/config.h from .config. generated/flags.h generated/globals.h generated/tags.h generated/help.h Compile toybox..................................toys/net/netstat.c: In function 'display_routes': toys/net/netstat.c:254:8: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result] fgets(toybuf, sizeof(toybuf), fp); ^ toys/net/netstat.c: In function 'show_ip': toys/net/netstat.c:103:8: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result] fgets(toybuf, sizeof(toybuf), fp); ^ toys/net/netstat.c: In function 'show_unix_sockets': toys/net/netstat.c:173:8: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result] fgets(toybuf, sizeof(toybuf), fp); ^ .......................................................................................toys/other/watchdog.c: In function 'watchdog_main': toys/other/watchdog.c:48:10: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result] write(TT.fd, "", 1); ^ toys/other/watchdog.c: In function 'safe_shutdown': toys/other/watchdog.c:34:8: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result] write(TT.fd, "V", 1); ^ .......................................................toys/posix/tar.c: In function 'unpack_tar': toys/posix/tar.c:819:7: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result] (void)write(sefd, 0, 0); ^ ..............generated/obj/id.o: In function `do_id': id.c:(.text.do_id+0x11a): warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_xwrap.o: In function `xsetuser': xwrap.c:(.text.xsetuser+0xb): warning: Using 'initgroups' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_xwrap.o: In function `xgetgrgid': xwrap.c:(.text.xgetgrgid+0x4): warning: Using 'getgrgid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_xwrap.o: In function `xgetgid': xwrap.c:(.text.xgetgid+0xa): warning: Using 'getgrnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_lib.o: In function `bufgetgrgid': lib.c:(.text.bufgetgrgid+0x68): warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_xwrap.o: In function `xgetuid': xwrap.c:(.text.xgetuid+0xa): warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_xwrap.o: In function `xgetpwuid': xwrap.c:(.text.xgetpwuid+0x4): warning: Using 'getpwuid' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_lib.o: In function `bufgetpwuid': lib.c:(.text.bufgetpwuid+0x68): warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/lib_net.o: In function `xgetaddrinfo': net.c:(.text.xgetaddrinfo+0x50): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/passwd.o: In function `passwd_main': passwd.c:(.text.passwd_main+0x79): warning: Using 'getspnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/hostname.o: In function `hostname_main': hostname.c:(.text.hostname_main+0xb9): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking generated/obj/netstat.o: In function `addr2str': netstat.c:(.text.addr2str+0x12b): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new': (.text+0xcd): undefined reference to `pthread_once' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new': (.text+0x126): undefined reference to `pthread_attr_init' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new': (.text+0x168): undefined reference to `pthread_attr_setdetachstate' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new': (.text+0x1bb): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_create.o): In function `__timer_create_new': (.text+0x1d7): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `timer_helper_thread': (.text+0x95): undefined reference to `pthread_exit' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `timer_helper_thread': (.text+0xae): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `timer_helper_thread': (.text+0xfe): undefined reference to `pthread_create' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `timer_helper_thread': (.text+0x108): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x18d): undefined reference to `pthread_attr_init' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x197): undefined reference to `__pthread_get_minstack' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x1a4): undefined reference to `pthread_attr_setstacksize' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x1eb): undefined reference to `pthread_create' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x225): undefined reference to `pthread_attr_destroy' /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x233): undefined reference to `pthread_atfork' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1': (.text+0x211a): undefined reference to `pthread_once' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `__register_frame_info_bases': (.text+0x1787): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `__register_frame_info_table_bases': (.text+0x183b): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `__deregister_frame_info_bases': (.text+0x18de): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `__deregister_frame_info_bases': (.text+0x1966): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `_Unwind_Find_FDE': (.text+0x1a36): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `_Unwind_Find_FDE': (.text+0x1a86): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `__register_frame_info_bases': (.text+0x17a6): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-linux-gnu/4.8/libgcc_eh.a(unwind-dw2-fde-dip.o): In function `__register_frame_info_table_bases': (.text+0x185a): undefined reference to `pthread_mutex_unlock' collect2: error: ld returned 1 exit status make: *** [toybox] Error 1 make: *** [root] Error 1 ubuntu@vm:~/toybox$ ```

Env:

ubuntu@vm:~/toybox$ cat /etc/os-release
NAME="Ubuntu"
VERSION="14.04.6 LTS, Trusty Tahr"
...
ubuntu@vm:~/toybox$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4
...
ubuntu@vm:~/toybox$ /lib/x86_64-linux-gnu/libc-2.19.so
GNU C Library (Ubuntu EGLIBC 2.19-0ubuntu6.15) stable release version 2.19, by Roland McGrath et al.
...
ubuntu@vm:~/toybox$
landley commented 2 years ago

Try pulling current toybox git and building there, commits b0e204b33d77 and 1b8fa91f836c have workarounds for this. (It built for me in the ubuntu 20.04 with those changes).

YKG commented 2 years ago

@landley You rock!

I forgot to pull the latest code. make root works now.

But I still got error when I run the next commond.

ubuntu@hk:~/toybox$ sudo chroot root/host/fs /init
chroot: failed to run command ‘/init’: No such file or directory
ubuntu@hk:~/toybox$ head -5 root/host/fs/init
#!/bin/sh

export HOME=/home PATH=/bin:/sbin

if ! mountpoint -q dev; then
ubuntu@hk:~/toybox$ ls root/host/fs/bin/sh
ls: cannot access 'root/host/fs/bin/sh': No such file or directory
ubuntu@hk:~/toybox$ find root/host/fs/ | grep sh
root/host/fs/usr/bin/sha224sum
root/host/fs/usr/bin/shred
root/host/fs/usr/bin/sha512sum
root/host/fs/usr/bin/sha3sum
root/host/fs/usr/bin/unshare
root/host/fs/usr/bin/sha256sum
root/host/fs/usr/bin/sha1sum
root/host/fs/usr/bin/sha384sum
ubuntu@hk:~/toybox$
ubuntu@hk:~/toybox$ sudo chroot root/host/fs /bin/toybox
[ acpi arch ascii base32 base64 basename blkdiscard blkid blockdev bunzip2 bzcat cal cat catv chattr chgrp chmod chown
chroot chrt chvt cksum clear cmp comm count cp cpio crc32 cut date devmem df dirname dmesg dnsdomainname dos2unix du
echo egrep eject env expand factor fallocate false fgrep file find flock fmt free freeramdisk fsfreeze fstype fsync ftpget
ftpput getconf grep groups gunzip halt head help hexedit hostname hwclock i2cdetect i2cdump i2cget i2cset iconv id ifconfig
inotifyd insmod install ionice iorenice iotop kill killall killall5 link linux32 ln logger login logname losetup ls lsattr
lsmod lspci lsusb makedevs mcookie md5sum microcom mix mkdir mkfifo mknod mkpasswd mkswap mktemp modinfo mount mountpoint
mv nbd-client nc netcat netstat nice nl nohup nproc nsenter od oneit partprobe passwd paste patch pgrep pidof ping ping6
pivot_root pkill pmap poweroff printenv printf prlimit ps pwd pwdx pwgen readahead readelf readlink realpath reboot renice
reset rev rfkill rm rmdir rmmod rtcwake sed seq setfattr setsid sha1sum sha224sum sha256sum sha384sum sha3sum sha512sum
shred sleep sntp sort split stat strings su swapoff swapon switch_root sync sysctl tac tail tar taskset tee test time
timeout top touch true truncate tty tunctl ulimit umount uname unicode uniq unix2dos unlink unshare uptime usleep uudecode
uuencode uuidgen vconfig vmstat w watch watchdog wc which who whoami xargs xxd yes zcat
ubuntu@hk:~/toybox$ sudo chroot root/host/fs /bin/toybox echo hi
hi
ubuntu@hk:~/toybox$

It looks like the /bin/sh was missing.

YKG commented 2 years ago

Here is the log when I run qemu-x86_64.sh

ubuntu@vm:~/toybox/root/host$ ./qemu-x86_64.sh
...
clocksource: Switched to clocksource refined-jiffies
e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 52:54:00:12:34:56
e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
NET: Registered PF_INET6 protocol family
Segment Routing with IPv6
NET: Registered PF_PACKET protocol family
printk: console [netcon0] enabled
netconsole: network logging started
Freeing unused kernel image (initmem) memory: 576K
Write protecting the kernel read-only data: 10240k
Freeing unused kernel image (text/rodata gap) memory: 2044K
Freeing unused kernel image (rodata/data gap) memory: 1128K
Run /init as init process
Failed to execute /init (error -2)
Run /sbin/init as init process
Run /etc/init as init process
Run /bin/init as init process
Run /bin/sh as init process
Kernel panic - not syncing: No working init found.  Try passing init= option to kernel. See Linux Documentation/admin-guide/init.rst for guidan.
CPU: 0 PID: 1 Comm: swapper Not tainted 5.14.15 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014
Call Trace:
 dump_stack_lvl+0x1a/0x1e
 dump_stack+0x10/0x12
 panic+0xde/0x25b
 ? rest_init+0x90/0x90
 kernel_init+0xf7/0x100
 ret_from_fork+0x1f/0x30
Kernel Offset: disabled
Rebooting in 1 seconds..

ubuntu@vm:~/toybox/root/host$

looks like /init still in trouble.

landley commented 2 years ago

On 11/4/21 2:22 AM, Kaige Ye wrote:

@landley https://github.com/landley You rock!

I forgot to pull the latest code. |make root| works now.

But I still got error when I run the next commond.

@.***:~/toybox$ sudo chroot root/host/fs /init chroot: failed to run command ‘/init’: No such file or directory

You have to enable "route" and "sh" under "pending" in your toybox .config.

If there's no .config (you deleted it or ran "make distclean"), it'll create one with both enabled, but if you have an existing one it'll use it. (I need to finish both commands and promote them out of pending.)

It looks like the |/bin/sh| was missing.

Yup, it's switched off in defconfig because it's still in toys/pending. It's about 2/3 finished. (Works for this, but doesn't do everything yet.)

Rob

YKG commented 2 years ago

Thank you so much! All works!