Tiny Core Linux

Tiny Core Base => TCB Talk => Topic started by: cparke on May 10, 2025, 03:15:09 AM

Title: binfmt_misc
Post by: cparke on May 10, 2025, 03:15:09 AM
I want to use TinyCore (x86) to chroot into the TC Raspberry Pi rootfs via qemu-arm. 

To do this requires binfmt_misc, which appears to be entirely missing from TinyCore's kernel and the extensions library (I think this feature needs to be either compiled directly into the kernel with the CONFIG_BINFMT_MISC option flag, or maybe can be installed as a kernel module?)

Any suggestions on how I could enable binfmt_misc in TC 16?
Title: Re: binfmt_misc
Post by: Juanito on May 10, 2025, 04:03:00 AM
If you look here:

http://tinycorelinux.net/16.x/x86/release/src/kernel/config-6.12.11-tinycore

# CONFIG_BINFMT_MISC is not set

..so you would need to recompile the tinycore kernel.

That being said, the last time I tried to use qemu with PiCore, it didn't work very well.
Title: Re: binfmt_misc
Post by: cparke on May 10, 2025, 10:15:43 AM
That seems pretty involved, as described in this Wiki page:
https://wiki.tinycorelinux.net/doku.php?id=wiki:custom_kernel (https://wiki.tinycorelinux.net/doku.php?id=wiki:custom_kernel)

Is it that expensive to set the option CONFIG_BINFMT_MISC=m so this could be a simpler process of just compiling the desired kernel module, or even so a .tcem (do those still exist?) could be offered to install this feature seemlessly?

To make such a build compatible with the rest of Tinycore 16 and its tcem's, I need to pull the exact same version of the kernel from kernel.org and apply all of the TC patches?
Title: Re: binfmt_misc
Post by: Juanito on May 10, 2025, 11:14:10 AM
You can use the config and the patched source from here:

http://tinycorelinux.net/16.x/x86/release/src/kernel/

Sometimes you can use a new kernel module without changing anything else (i.e. you can make an extension of it) and sometimes a new vmlinuz is needed.
Title: Re: binfmt_misc
Post by: cparke on May 10, 2025, 01:23:38 PM
Was the TC 16.0 kernel built under TC 15.0 environment or some other distro?

Do I rename the 'config-6.12.11-tinycore' to '.config' and then run 'make oldconfig' to initially transfer over all the TC options?

Do I have to re-apply the patches, or have they already been applied and just there for reference?
Title: Re: binfmt_misc
Post by: Juanito on May 10, 2025, 02:02:48 PM
Was the TC 16.0 kernel built under TC 15.0 environment or some other distro?
tc-15

Quote
Do I rename the 'config-6.12.11-tinycore' to '.config' and then run 'make oldconfig' to initially transfer over all the TC options?
Affirmative

Quote
Do I have to re-apply the patches, or have they already been applied and just there for reference?
They’ve been applied
Title: Re: binfmt_misc
Post by: cparke on May 10, 2025, 02:45:51 PM
Great, so it sounds like TC 16.0 kernel is pretty good to go for build under TC 15.0.

One more question, sorry, how do I install the newly built kernel modules in order for the new kernel to actually work?  They don't appear to reside on the rootfs in /tce/boot/core.gz, but somehow get extracted from vmlinuz, yet as I understand it the Linux kernel build produces these separately as bzImage and *.ko files?
Title: Re: binfmt_misc
Post by: Juanito on May 10, 2025, 03:52:10 PM
If you first try setting binfmt_misc as a module you can copy it somewhere under /usr/local/lib/modules and make an extension of it to test if it works.
Title: Re: binfmt_misc
Post by: cparke on May 10, 2025, 04:37:44 PM
That is how I wish TC had built the kernel in the first place. Even changing it now that way could technically cause a change in the Kernel data structure offsets and require all the kernel modules to be updated.  Is there a process to update core.gz with new *.ko.gz kernel modules?
Title: Re: binfmt_misc
Post by: Juanito on May 11, 2025, 04:41:38 AM
core.gz is actually a concatenated rootfs.gz + modules.gz - see:

http://tinycorelinux.net/16.x/x86/release/distribution_files/

The kernel modules included in the base are in modules.gz

The kernel modules included in extensions are named *-6.12.11-tinycore.tcz

The tce-load script takes care of depmod for extensions containing modules, which is why I said that it would be easier for you to create an extension with your module in it.

Since all that is required to enable your module is:
Code: [Select]
make menuconfig

Executable file formats ---> Kernel support for MISC binaries ---> m

..I'm guessing all you need is the new module
Title: Re: binfmt_misc
Post by: Juanito on May 11, 2025, 11:51:17 AM
In the end I gave it a go...

Building binfmt_misc as a module gave missing symbol errors even though it had no deps as per modinfo.

Building binfmt_misc into the kernel seems to work:
Code: [Select]
sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc..but I didn't try anything but this.

Code: [Select]
tce-load -i compiletc perl5 bash bc ncursesw-dev elfutils-dev

wget http://tinycorelinux.net/16.x/x86/release/src/kernel/linux-6.12.11-patched.tar.xz
wget http://tinycorelinux.net/16.x/x86/release/src/kernel/config-6.12.11-tinycore

tar xf linux-6.12.11-patched.tar.xz

cd linux-6.12.11

make mrproper

cp ../config-6.12.11-tinycore ./.config
make oldconfig

make menuconfig

Executable file formats ---> Kernel support for MISC binaries ---> *

make bzImage [38m 53.87s]
Title: Re: binfmt_misc
Post by: Juanito on May 12, 2025, 08:20:12 AM
If you'd like to test, download this: http://tinycorelinux.net/16.x/x86/release/distribution_files/binfmt_misc/bzImage

..and temporarily replace vmlinuz in your bootloader config with bzImage