Waiting for device /dev/disk/by-label/NIXOS_SD to appear

Hey y’all. Just realized NixOS has “support” for the RPi 4, and have devised a plan as to what my board’s fate will be - nixification.

Until, of course, it didn’t work.

I followed the configuration.nix on the RPi4 wiki page, but am now given the following error:

Waiting for device /dev/disk/by-label/NIXOS_SD to appear...
* lots of irrelevant logs here about xhci_hcd and usb 1-1.3 *
Timed out waiting for device /dev/disk/by-label/NIXOS_SD, trying to mount anyway.

An error occured in stage 1 of the boot process, which must mount the
root filesystem on `/mnt-root` and then start stage 2. Press one
of the following keys:

  r) to reboot immediately
  *) to ignore the error and continue

After some research, it seems like others have had a similar error even on non-RPi devices - but a lot of the time, they get a few more options: namely, to enter an interactive shell, in which you can just mount /mnt-root yourself and carry on with your day/boot process/evil plan for your nixification.

Unfortunately, I don’t have these options. What makes this even funnier is that when I do try to press r for reboot, nothing happens at all - the key isn’t echoed into stdout, and the device stays exactly how it is. A few seconds ago I was typing away with this keyboard plugged directly into the Pi, but now it seems to not see it.

Thanks for the help in advance, I’d really like to proceed with my evil plan of Pi nixification.

Cheers,

Bob.

1 Like

The missing shell option is because boot.kernelParams doesn’t contain "boot.shell_on_fail". You can see all supported kernelParams here https://github.com/NixOS/nixpkgs/blob/91b77fe6942fe999b1efbe906dc98024d1917c0d/nixos/modules/system/boot/stage-1-init.sh#L137

As for the boot problem it seems like the media you are booting from isn’t configured how the configuration.nix you are using is expecting. Or the kernel is having problems finding the media. Is it on USB or SD?

I am curious how you got here. Am I correct in this sequence of events?

  1. You booted the raspberry pi 4 special image
  2. You copied the configuration.nix from the wiki and ran nixos-rebuild switch
  3. The reboot after that failed

Because if that is the case there are only two possible causes.

  1. The special image does not contain a partition with label NIXOS_SD and you need to adjust the configuration.nix
  2. There is a problem with the media. Like the kernel can’t find it which might mean that it is bad or there is some difference in the kernel of special image and the one used by configuration.nix
1 Like

Hi Griff,

Thank you for your response!

Re: missing shell option: Perfect. Booted up, reverted to before the broken rebuild, added to my configuration.nix and rebuilt. Time for some juicy answers.

Re: sequence of events: yes precisely. RPi 4 special built image from Hydra, grabbed the configuration.nix from the RPi 4 wiki page, and switched. If I tried to use sudo, I’d get something along the lines of “User is not in the password database”. A quick logout and login would fix it, and it makes sense why. Sadly, a reboot after this came up with this error.

Now, I added these params to my config and rebuilt - now I have two more options!

 i) to launch an interactive shell
 f) to start an interactive shell having pid 1 (needed if you want to
    start stage 2's init manually)
 r) ... the usual options ...

The problem is, the system doesn’t seem to be handling my input - no matter what letters I press, nothing happens.

Above the error there are some dmesg-like logs along the lines of:

[      2.xxxxxx] xhci_hcd error: unexpected setup context command completion code 0x11.
[      2.yyyyyy] usb 1-1.1: hub failed to enable device, error -22
... the same error a few times ...
 [     4.zzzzzz] usb 1-1-port1: unable to enumerate USB device
... Timed out waiting for device /dev/disk/by-label/NIXOS_SD on /mnt-root/ failed ...

If I unplug and re-plug in my USB receiver, the same log is spat out.

Once I get input and am able to get to a shell, I’ll just ls /dev/disk/by-label and work our way from there.

Any ideas on what the problem is now?

Cheers!

1 Like

I am having the exact same problem.
I would like to add that /dev/disk/by-label/NIXOS_SD exists while in the initial system. The error does not occur when on the initial system state, but only after running nixos-rebuild switch for the first time.
Replacing the by-label path with by-uuid or even /dev/mmcblk0p2 does not work either.
It seems like the system cannot even see the devices at that boot stage.
I have also tried adding the /dev/disk/by-label/FIRMWARE partition to my config, but that does not change anything.

Fortunately it is possible to revert to the initial system config using u-boot.

I have also previously tried flashing the image to a usb stick, but it failed in u-boot.

1 Like

I have now successfully installed nixos on my pi. Here is what I did:
(some of these steps may not be necessary)

  1. install raspberry pi os (I installed the 2021-01-11 release)
  2. upgrade the system (sudo apt update and sudo apt upgrade)
  3. run rpi-eeprom-update -d -a
  4. Run sudo raspi-config
    • goto advanced/boot-configuration
    • select the option which boots from usb first and from sd if no usb stick was found
    • save changes and reboot
  5. remove the sd card from the raspberry pi
  6. flash a usb stick with the temporary nixos arm image from hydra
  7. insert the usb stick into the pi and wait for nixos to boot
  8. insert the sd card into the pi
  9. format the sd card according to the manual for efi and use gpt
    • I created 3 partitions, all labeled accordingly
      • 512mb efi system partition with fat32 fs mounted to /boot
      • 4gb swap partition
      • linux partition with ext4 for the remaining space
  10. run sudo nixos-generate-hardware-config --root /mnt
  11. delete all default contents from /etc/nixos/configuration.nix
  12. copy the relevant parts from the config file posted to the wiki (see below)
  13. add the unstable nixpkgs channel
    • nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs
    • nix-channel --update
  14. run sudo nixos-install
  15. reboot
  16. profit
  17. re-add the unstable nixpkgs channel (for future rebuilds)

My configuration file looks like this:

{ config, pkgs, ... }:

{
  imports = [
    ./hardware-configuration.nix
  ];

  boot = {
    kernelPackages = pkgs.linuxPackages_rpi4;
    tmpOnTmpfs = true;
    initrd.availableKernelModules = [ "usbhid" "usb_storage" ];
    # ttyAMA0 is the serial console broken out to the GPIO
    kernelParams = [
      "8250.nr_uarts=1"
      "console=ttyAMA0,115200"
      "console=tty1"
      # Some gui programs need this
      "cma=128M"
    ];

    loader = {
      raspberryPi = {
        enable = true;
        version = 4;
      };
      grub.enable = false;
      generic-extlinux-compatible.enable = false;
    };
  };

  hardware.enableRedistributableFirmware = true;
  powerManagement.cpuFreqGovernor = "ondemand";

  networking = {
    hostName = "nixpi";
    interfaces = {
      eth0.useDHCP = true;
    };
    firewall = {
      enable = true;
    };
  };

  nixpkgs.config = {
    allowUnfree = true;
  };

  users.users = {
    root = {
      password = "changeme";
    };
    nixos = {
      isNormalUser = true;
      password = "changeme";
      extraGroups = [ "wheel" ];
    };
  };

  services = {
    openssh = {
      enable = true;
    };
  };

  system.stateVersion = "21.03";
}

I hope this is helpful.

2 Likes

Please note that the line "console=ttyAMA0,115200" in the above config does not enable getty on the gpio serial port because in Raspberry Pi 4 those get the device /dev/ttyS0. (/dev/ttyAMA0 is now something bluetooth related)
Do not enable the kernel console on that device if you want to use it for something else.

1 Like

Doesn’t work for me :weary:

Tried this three times now :). Seems fairly similar to the bootstrapping process we used in Gentoo, so I understand the concept. However, I do have a question: how does the first partition get its boot files?

Basically, I followed through the process, but when I unplug my USB and leave my SD in and turn her on, the screen stays blank, and the red light is solid on (green light flashes for a quarter of a second). After some Googling advanced research, it seems like this is because boot can’t be found.

I’m no RPi master, but it seems like we created /dev/mmcblk0p1 but didn’t populate it with boot files? :thinking:

Oh gosh, I wish this were simpler, I came to Nix so that everything could be done for me, but instead I have to do everything by hand :).

Did you set the boot flag for the efi partition? I always thought that it wouldn’t be necessary for efi types, but I cannot remember if I did it or not.
Sorry, I forgot that in the original post.

Can confirm this happens in hardware other than RPi too.

i had the same issue.
After 2 days of trying differ things, but then i notice that in the configuration.nix from the wiki page (NixOS on ARM/Raspberry Pi 4 - NixOS Wiki) there is no import of the hardware-configuration.nix like

  imports = [
    ./hardware-configuration.nix
  ];

so removed the import of hardware-configuration.nix and the pi is booting successfully :slight_smile:

1 Like