I would recommend looking at what gokrazy does: https://gokrazy.org/ I believe the entrypoint of their pid1 is this generated Go code: https://github.com/gokrazy/tools/blob/main/internal/packer/buildinit.go#L17 You might use that to see what kinds of initialization it does to cooperate with the kernel.
On Mon, 17 Feb 2025 at 19:52, 'Hannes Stauss' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Dear > I have an empty go program that I would like to run as pid1 from the > initramfs embedded into the kernel after the linux kernel booted (a real > init would for sure do more than just looping forever): > package main > > func main() { > for { > } > } > > > Any ideas where to follow to narrow down the issue? Many thanks in advance. > > I can get it running without panic when I call the go program from a c > program that first mounts dev filesystem: > int main() > { > // Mount the devtmpfs filesystem to /dev > mount("devtmpfs", "/dev", "devtmpfs", 0, NULL); > > // run the main program > execl("/main", "/main", (char *)NULL); > exit(EXIT_FAILURE); > } > > When calling the go program without first mounting dev filesystem I get > again a kernel panic. > > I seems the go runtime somehow needs a mounted dev filesystem in order to > initialize properly. > > My test platform is aarch64 running in qemu with following command: > qemu-system-aarch64 \ > -machine virt \ > -cpu cortex-a57 \ > -smp 2 -m 2048 \ > -kernel linux/arch/arm64/boot/Image \ > -append "console=ttyAMA0" \ > -nographic > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion visit > https://groups.google.com/d/msgid/golang-nuts/896b8411-77e5-4741-b283-5d401286e820n%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/896b8411-77e5-4741-b283-5d401286e820n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAEkBMfGN--1LJZ%3D1uODM1zVjUZdvJGGYR-GgnEvrO484KyXdeg%40mail.gmail.com.