My goal is to run NixOS on Raspberry Pi 4B, but with the ability to run the environment on my laptop in addition to the RPi hardware. Having the ability to run it on my laptop would make it more convenient to prepare the rootfs, as well as to quickly and easily recover from a bad SD card.
So, I am trying to boot an ARM image of NixOS in QEMU on my MacBook Air M1, but I have not been able to so far. I’ve done a lot of research but haven’t found the root cause. I’d love some help.
I downloaded a AArch64 installer image from Hydra (nixos-sd-image-21.11pre302501.b59c06dc92f-aarch64-linux.img
). Then I ran into the challenge of finding a suitable QEMU kernel. I believe this needs to be a UBoot build prepared for QEMU. I followed the instructions on NixOS on ARM/QEMU page and downloaded uboot.bin
from Hydra - Job nixpkgs:trunk:ubootQemuAarch64.aarch64-linux (specifically from this build). Lastly, here’s the qemu command I used:
qemu-system-arm -machine virt,highmem=off \
-bios u-boot.bin \
-drive if=none,file=nixos-sd-image-21.11pre302501.b59c06dc92f-aarch64-linux.qcow2,id=mydisk \
-device ich9-ahci,id=ahci \
-device ide-hd,drive=mydisk,bus=ahci.0 \
-netdev user,id=net0 \
-device virtio-net-pci,netdev=net0 \
-nographic -smp 4 -m 2G
When I ran it on my MBA M1, the output was a screenful of qemu-system-arm: qemu_mprotect__osdep: mprotect failed: Permission denied
, then nothing. QEMU was using 100% of one core, but seemingly not doing anything. I had to kill it.
Curiously, I tried another build of the UBoot kernel, this time from the FreeBSD project: u-boot-qemu-arm-2021.07.txz FreeBSD 13 Download, and got farther with it! QEMU again gave me a screenful of those same errors as above, but proceeded:
qemu-system-arm: qemu_mprotect__osdep: mprotect failed: Permission denied
qemu-system-arm: qemu_mprotect__osdep: mprotect failed: Permission denied
U-Boot 2021.07 (Jul 09 2021 - 06:28:36 +0000)
DRAM: 2 GiB
Flash: 64 MiB
Loading Environment from Flash... *** Warning - bad CRC, using default environment
In: pl011@9000000
Out: pl011@9000000
Err: pl011@9000000
Net: eth0: virtio-net#32
Hit any key to stop autoboot: 0
starting USB...
No working controllers found
USB is stopped. Please issue 'usb start' first.
scanning bus for devices...
Target spinup took 0 ms.
SATA link 1 timeout.
SATA link 2 timeout.
SATA link 3 timeout.
SATA link 4 timeout.
SATA link 5 timeout.
AHCI 0001.0000 32 slots 6 ports 1.5 Gbps 0x3f impl SATA mode
flags: 64bit ncq only
Device 0: (0:0) Vendor: ATA Prod.: QEMU HARDDISK Rev: 2.5+
Type: Hard Disk
Capacity: 8474.5 MB = 8.2 GB (17355920 x 512)
Device 0: (0:0) Vendor: ATA Prod.: QEMU HARDDISK Rev: 2.5+
Type: Hard Disk
Capacity: 8474.5 MB = 8.2 GB (17355920 x 512)
... is now current device
Scanning scsi 0:2...
Found /boot/extlinux/extlinux.conf
Retrieving file: /boot/extlinux/extlinux.conf
693 bytes read in 8 ms (84 KiB/s)
1: NixOS - Default
Retrieving file: /boot/extlinux/../nixos/s4xxbl5sxyra3r5mxv7kgs621f6hn2s6-initrd-linux-5.13.2-initrd
8208653 bytes read in 137 ms (57.1 MiB/s)
Retrieving file: /boot/extlinux/../nixos/20cjn0dgyfmjcvwknza51wp64g026n5m-linux-5.13.2-Image
45042176 bytes read in 701 ms (61.3 MiB/s)
append: init=/nix/store/q7lwsafqwi7gk2f1qi8jcki8r003dvqc-nixos-system-nixos-21.11pre302501.b59c06dc92f/init console=ttyS0,115200n8 console=ttyAMA0,115200n8 console=tty0 loglevel=7
zimage: Bad magic!
SCRIPT FAILED: continuing...
Scanning disk ahci_scsi.id0lun0...
Found 3 disks
Missing RNG device for EFI_RNG_PROTOCOL
No EFI system partition
BootOrder not defined
EFI boot manager: Cannot load any image
Device 0: unknown device
starting USB...
No working controllers found
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (2 ms)
Using virtio-net#32 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x40200000
Loading: *
TFTP error: 'Access violation' (2)
Not retrying...
BOOTP broadcast 1
DHCP client bound to address 10.0.2.15 (0 ms)
Using virtio-net#32 device
TFTP from server 10.0.2.2; our IP address is 10.0.2.15
Filename 'boot.scr.uimg'.
Load address: 0x40400000
Loading: *
TFTP error: 'Access violation' (2)
Not retrying...
=>
Now I’ve reached a stopping point. I am not sure what the issue is. QEMU doesn’t seem to like either of the two UBoot kernels. Why does the NixOS-provided UBoot kernel do nothing at all? Why does the FreeBSD-provided UBoot kernel give a zimage: Bad magic!
error?
Does anyone have advice on how to proceed with my goal of running a Raspberry Pi NixOS in QEMU on my Mac?