headblockhead / rpicluster

A cluster of RPIs running NixOS, booted over TFTP netboot
0 stars 0 forks source link

How your PXE boot with nixos work for raspberry pi #1

Open gungun974 opened 2 months ago

gungun974 commented 2 months ago

Hoi !

Sorry to bother you, but I'm trying to boot NixOS without any SD card on my Raspberry Pi 4.

I tried to search on the Internet for some information, but nobody has written anything about booting a Raspberry Pi with Nix using PXE. However, I found this repo.

I tried to replicate your setup using dnsmasq as described in your dotfiles repo, but I encountered some issues with the boot process of my Pi. Note: I don't use dnsmasq as DHCP; I use my firewall opnsense for that.

A lot of times, my Raspberry Pi just waits for the FTPD server, and sometimes it just instantly boots. Sometimes, during U-Boot, the Pi never finds the Pixiecore config...

In some rare cases, the Pi boots the first stage of NixOS but fails to continue and crashes because the squashfs is missing, making the Nix store unavailable.

I don't understand why I'm getting these results. Do you think there's something I forgot to configure in my DHCP? Do you think it's a network issue?

I'm trying to debug this, but all of these boot processes with ARM are unknown to me.

Here are the latest logs from my dnsmasq:

Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/bootcfg.txt not found for 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: failed sending /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/u-boot-rpi4.bin to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: failed sending /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/u-boot-rpi4.bin to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: failed sending /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/bcm2711-rpi-4-b.dtb to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/bcm2711-rpi-4-b.dtb to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/overlays/overlay_map.dtb not found for 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/config.txt to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/config.txt to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/cmdline.txt not found for 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/armstub8-gic.bin to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/armstub8-gic.bin to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/armstub8-gic.bin to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/armstub8-gic.bin to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: error 0 Early terminate received from 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: failed sending /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/u-boot-rpi4.bin to 192.168.1.128
Jul 22 23:58:43 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/u-boot-rpi4.bin to 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/C0A8018 not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/C0A801 not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/C0A80 not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/C0A8 not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/C0A not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/C0 not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/C not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/default-arm-bcm283x-rpi not found for 192.168.1.128
Jul 23 00:00:51 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/default-arm-bcm283x not found for 192.168.1.128
Jul 23 00:00:52 Artemis dnsmasq-tftp[2010907]: file /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/default-arm not found for 192.168.1.128
Jul 23 00:00:52 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/pxelinux.cfg/default to 192.168.1.128
Jul 23 00:00:56 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/rpi-aurora-01/Image to 192.168.1.128
Jul 23 00:01:04 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/rpi-aurora-01/initrd to 192.168.1.128
Jul 23 00:01:04 Artemis dnsmasq-tftp[2010907]: sent /nix/store/p5g4ks56wyjniklch5bpww27lnx6vqfs-rpiTFTP/dtb/broadcom/bcm2711-rpi-4-b.dtb to 192.168.1.128

Here is a picture of the boot error with the squashfs:

IMG_3973

My TFTP server is at 192.168.1.52, as shown in my logs.

Anyway, even if I haven't succeeded yet, your work has been a great help, so thank you.

headblockhead commented 2 months ago

Hello! Sorry for the delayed reply, I'm glad someone else is interested in this project!

I'm not sure about the other errors you are having, maybe I can help resolve those later, however I have encountered the squashfs error before!

The issue you are running into is that NixOS requires a copy of its store to boot (of course), but it tries to read it from a file on the netbooted image by default, where it is not included.

When netbooting, NixOS uses a rw-store (usually in RAM) for things like nix-shell and other runtime nix store changes, and a ro-store (usually a disk image or network directory) for everything in the initial configuration.

The default configuration for netbooting stores the ro-store image as a nix-store.squashfs contained inside the Image file, however the Image file + other bootloader items must fit into ~1GB of RAM (for compatibility + maybe other reasons) while running on the Pi.

Usually the kernel etc. would fit into ~1GB, however if a too many things are in the nix store image, sometimes it does not fit and crashes weirdly, therefore I don't enable it by default.

See my other repo where I mount the ro-store over network instead. (you can use NFSFolder to generate an SD image that contains the full /nix/store)

However, If you want to run without a network share it is possible, but keep in mind the 1GB limit! You might have funky errors from U-Boot if you go over.

Try building the netbootRamdisk target after (if you haven't already) including nixos/modules/installer/netboot/netboot.nix in your modules. That should include the nix-store.squashfs file.

Anyway here's some places you might want to look over for guidance: Where the ro-store is defined where the squashfs is defined building an Image that includes the squashfs

Please send me any more info you have, I'd love to help out.