NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.9k stars 13.95k forks source link

grub segfault on x86-64 host when installing EFI for aarch64 target #346487

Open n8henrie opened 2 weeks ago

n8henrie commented 2 weeks ago

Describe the bug

This is a rehash of the issue I banged my head against last year: https://discourse.nixos.org/t/nixos-install-and-nixos-enter-chroot-failed-to-run-command-nix-var-nix-profiles-system-activate-no-such-file-or-directory/32071

In short, grub2 from an x86_64 nixos host segfaults when trying to install an EFI bootloader to a aarch64-linux system.

Steps To Reproduce

Steps to reproduce the behavior:

I initially encountered when trying to nixos-install from an arch linux x86_64 host, but I thought the segfault might be due to a problem with binfmt_misc on Arch, so I tried with NixOS but ran into a similar crash. I think easiest to reproduce:

$ nix-shell -p 'let pkgs = import <nixpkgs> { system = "aarch64-linux"; }; in pkgs.grub2.override { zfsSupport = true; inherit (pkgs) zfs; }'
[nix-shell]$ sudo grub-install --efi-directory /mnt/zfs-root/boot/efi --boot-directory /mnt/zfs-root/boot --target arm64-efi --recheck --removable
Installing for arm64-efi platform.
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault

Expected behavior

Grub installation succeeds

Additional context

As linked above, I've had a super painful time trying to fix bootloaders on arm64 systems from x86 nixos hosts.

Notify maintainers

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.52, NixOS, 24.11 (Vicuna), 24.11.20240929.6fcc384`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.8`
 - channels(root): `""`
 - nixpkgs: `/nix/store/x2qbrd60nz1y86ha15k7mkc2i1d7xb37-source`

Add a :+1: reaction to issues you find important.

n8henrie commented 1 week ago

Replicated on NixOS after https://github.com/NixOS/nixpkgs/issues/346504

# NIXOS_INSTALL_BOOTLOADER=1 ./result/bin/switch-to-configuration boot
updating GRUB 2 menu...
installing the GRUB 2 boot loader into /boot/efi...
Installing for arm64-efi platform.
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
/nix/store/45ivfj6b8zn64imilvvfg8s52kvc0afq-install-grub.pl: installation of GRUB EFI into /boot/efi failed:
 No such file or directory
Failed to install bootloader