NixOS failing to boot from SD card on Raspberry Pi 4B 2GB

Hi,

my first time posting here, so I’m sorry if this is the wrong place for that.

I’m having an issue when trying to do the first boot/install of NixOS using an SD card into my Raspberry Pi 4B 2GB. This only happens with the SD card, I successfully installed NixOS from a USB stick.

I’m basically following this tutorial.

I’ve tried using two different SD cards:

Same result with both.

The error message says it didn’t manage to mount the NIXOS_SD partition, and this is all I could understand from the error messages.


I also have tried many different versions of the NixOS for aarch64 from Hydra. Again, all gave me the same error.

There is also the possibility that my Raspberry Pi has a hardware problem, it would be good to validate that possibility without buying another Raspberry Pi.

I would appreciate any suggestions on how to solve this problem.

EDIT: I managed to install another Linux distro using the SD card.

1 Like

Hey @afaelcgs10! I’m having the exact same issue and was also able to boot Raspbian on my Raspberry Pi 4. I also had an easy time installing NixOS on a Raspberry Pi 3 so I was a little surprised by this. I’ll follow up with any ideas or solutions I may encounter.

cc: @samueldr @jonringer Jon, didn’t you fix this?

I just followed NixOS on ARM - NixOS Wiki and didn’t have much of an issue.

@samueldr is definitely the one to ask

Did you try updating the firmware?

## Updating the bootloader using Raspberry Pi Imager
# Raspberry Pi Imager provides a GUI for updating the bootloader and selecting the boot mode.
Install package: rpi-imager
Launch the application: rpi-imager
Insert a spare sd-card. The contents will get overwritten!
Choose OS > Misc utility images > Bootloader
Boot-mode: SD (recommended), USB or Network.
Choose Storage: Select the sd-card
WRITE
Boot the Raspberry Pi with the new image and wait for at least 10 seconds.
The green activity LED will blink with a steady pattern and the HDMI display will be green on success.
Power off the Raspberry Pi and remove the sd-card.

note: Sometimes a command seems to be finished, but is still writing to storage. You might have disconnected the sd-card too soon?

Yes, I did update the firmware. I think this procedure was completed fine, I waited way more than 10 seconds.

I don’t know if this helps, but when I update the firmware from NixOS I do this:

[nix-shell:~]# mount /dev/disk/by-label/FIRMWARE /mnt

[nix-shell:~]# BOOTFS=/mnt FIRMWARE_RELEASE_STATUS=stable rpi-eeprom-update -d -a
BCM2711 detected
VL805 firmware in bootloader EEPROM
Checking for updates in /nix/store/fvpchpwlsaip0j4swbi7q9l5yj1xv61i-raspberrypi-eeprom-2021-03-18/share/rpi-eeprom/stable
Use raspi-config to select either the default-production release or latest update.
BOOTLOADER: up-to-date
CURRENT: qui 29 abr 2021 16:11:25 UTC (1619712685)
 LATEST: qui 18 mar 2021 08:54:11 UTC (1616057651)
RELEASE: stable
VL805: up-to-date
CURRENT: 000138a1
 LATEST: 000138a1

Which image did you use?

I tried different images of 21.05 and 21.11. E.g.: Hydra - Build 142828023 of job nixos:trunk-combined:nixos.sd_image_new_kernel.aarch64-linux

Oh I meant @jonringer :slight_smile: I used the same image as you and had the same issue :smiley:

I probably created my own image, as I think I just re-used my desktop’s configuration.nix with a few tweaks

I thought there was a somewhat recent fix that added the SDHC module to the initrd kernel modules to specifically fix this scenario of / not mounting from SD?

(Now that I’ve tried to look in git history, though, I can’t find a supporting commit.)

There is repo which automates the building process via docker-compose. With the repo I managed to build a working image.
Maybe it helps you too:

I did this a few days ago. This went easier than the docker one…

I used an usb3 connected ssd, it should work for sd-cards.


# # # # # # # # # # # # # # # # # # # # # # # # #
#  #  #  #  #   SELF-BUILD  IMAGE   #  #  #  #  #
# # # # # # # # # # # # # # # # # # # # # # # # #


### Add to configuration.nix on build machine.
# {
#   boot.binfmt.emulatedSystems = [ "aarch64-linux" ];
# }

# CLONE nixpkg
git clone https://github.com/NixOS/nixpkgs ~/

cd ~/nixpkgs
# MODIFY IT
vim ~/nixpkgs/nixos/modules/installer/sd-card/sd-image-aarch64-new-kernel.nix
  ########################################################
  # # When running from USB device without SD card present, kernel spams log about missing SD card, workaround for this is to set:
  # boot.loader.raspberryPi.firmwareConfig = "dtparam=sd_poll_once=on";
  #
  # environment.systemPackages = with pkgs; [ git neovim cryptsetup rsync silver-searcher raspberrypi-eeprom ];
  #
  # nix = {
  #     package = pkgs.nixUnstable;
  #     extraOptions = ''
  #       experimental-features = nix-command flakes
  #     '';
  # };
  #
  # console = {
  #   colors = [
  #     "f8f8f8"
  #     "a60000"
  #     "005e00"
  #     "813e00"
  #     "0031a9"
  #     "721045"
  #     "00538b"
  #     "282828"
  #     "ffffff"
  #     "972500"
  #     "315b00"
  #     "70480f"
  #     "2544bb"
  #     "8f0075"
  #     "30517f"
  #     "000000"
  #   ];
  #   font = "Lat2-Terminus16";
  #   # keyMap = "us";
  #   keyMap = "colemak/colemak";
  # };
  #
  # i18n = {
  #   defaultLocale = "en_IE.UTF-8";
  #   # defaultLocale = "en_US.UTF-8";
  #   extraLocaleSettings = {
  #     LC_TIME = "en_GB.UTF-8";
  #   };
  # };
  ########################################################

# MAKE IT
nix-build -A sd_image_new_kernel.aarch64-linux nixos/release.nix
## COPY the image to ~/downloads/images/
sudo cp /nix/store/8v0f2iq4jwbh704ym6wpvdinwnrdd9c3-nixos-sd-image-21.11pre130979.gfedcba-aarch64-linux.img/sd-image/nixos-sd-image-21.11pre130979.gfedcba-aarch64-linux.img.zst ~/downloads/images/
## Decompress File
unzstd -d ~/downloads/images/nixos-sd-image-21.11pre130979.gfedcba-aarch64-linux.img.zst

# WRITE TO SSD
lsblk
sudo dd bs=4M if=~/downloads/images/nixos-sd-image-21.11pre130979.gfedcba-aarch64-linux.img of=/dev/sdX status=progress oflag=sync

# BOOT rpi4 WITH SSD

Yes, I confirm this works and is a workaround to the problem.
However, I still think that keeping this thread is relevant because this problem shouldn’t happen with images from hydra, right?
What do you people think?

I can confirm the very same issue with generic image!

However, it works without problems by using the new kernel image.