Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/iso-image: extract GRUB EFI boot logic and offer systemd-boot as an alternative #246441

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RaitoBezarius
Copy link
Member

@RaitoBezarius RaitoBezarius commented Jul 31, 2023

Description of changes

We do this to prepare eviction of GRUB from the ISO image and show we can have systemd-boot.

Please adopt this PR and take over it if you want it faster.

TODO:

  • expose GRUB enable option properly
  • factor out the EFI image build for efi.img somewhere
  • Improve the menu generation for systemd-boot and ordering
  • tests? yes please tests.

Utility to test:

function uefi_iso_run()
{
  local OVMF="$(nix-build '<nixpkgs>' -A pkgs.OVMF.fd)"
  local ARCH_STRING="${ARCH:-x86_64}"
  nix-shell -p qemu --run "qemu-system-$ARCH_STRING -s -global isa-debugcon.iobase=0x402 -debugcon file:uefi.log -bios \"$OVMF/FV/OVMF.fd\" -net none -nographic -boot d -cdrom $*"
}

Obligatory: https://www.youtube.com/watch?v=NyP49XSA50g for those who knows.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

We do this to prepare eviction of GRUB from the ISO image.
No guarantee on the fancy stuff: ordering, titles, etc. Adopt this PR if you like it.
@chasecaleb
Copy link
Contributor

As I commented on #245915, this makes UEFI bootable for me. I can't boot the latest nixos-unstable minimal ISO (https://releases.nixos.org/nixos/unstable/nixos-23.11pre509514.9e1960bc196b/nixos-minimal-23.11pre509514.9e1960bc196b-x86_64-linux.iso) on VMware Workstation with UEFI, which has been an ongoing issue for roughly a month or so. The ISO @RaitoBezarius built from this PR (https://files.lahfa.xyz/nixos/nixos-minimal-23.11pre130979.gfedcba-x86_64-linux.iso) works, so nice job.

I'd love to see this merged as soon as possible because of the impact of this bug. I'm not a nixpkgs maintainer, but if there's anything that I can do to help make it happen please ping me.

Copy link
Contributor

@nikstur nikstur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

let
efiArch = pkgs.stdenv.hostPlatform.efiArch;

mkLoaderEntry = { title, version, linux ? null, initrd ? null, options ? null }@attrs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a lovely addition to pkgs/build-support/trivial-builders/

Comment on lines +92 to +102
# Round up to the nearest multiple of 1MB, for more deterministic du output
usage_size=$(( $(du -s --block-size=1M --apparent-size . | tr -cd '[:digit:]') * 1024 * 1024 ))
# Make the image 110% as big as the files need to make up for FAT overhead
image_size=$(( ($usage_size * 110) / 100 ))
# Make the image fit blocks of 1M
block_size=$((1024*1024))
image_size=$(( ($image_size / $block_size + 1) * $block_size ))
echo "Usage size: $usage_size"
echo "Image size: $image_size"
truncate --size=$image_size "$out"
mkfs.vfat --invariant -i 12345678 -n EFIBOOT "$out"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mention, it would be nice to factor this into a reusable function. https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/sd-card/sd-image.nix does something very similar. It could also be used here.

@RaitoBezarius
Copy link
Member Author

Good news for the test.

I'd love to see this merged as soon as possible because of the impact of this bug. I'm not a nixpkgs maintainer, but if there's anything that I can do to help make it happen please ping me.

It will take some time because I will not be able to work further on that PR as I have more urgency, this was more a Proof of Concept on how to get systemd-boot in our ISO image and can serve as a debug ISO for a lot of folks out there.

Anyone is free to take over this PR and bring it to achieve by ticking all the remaining TODO and working with the reviewers (which I can provide too.)

Otherwise, I will go back to it in ~2-3 weeks.

@chasecaleb
Copy link
Contributor

It will take some time because I will not be able to work further on that PR as I have more urgency, this was more a Proof of Concept on how to get systemd-boot in our ISO image and can serve as a debug ISO for a lot of folks out there.

@RaitoBezarius Totally understandable! I'm not quite ambitious enough to finish up this PR at the moment, but I'm happy to assist with testing, brainstorming, or anything else along those lines when you get back to it.

@anpin
Copy link
Contributor

anpin commented Aug 15, 2023

Hi, I'm encountering this issue #245915 and I've tried to fix it with this PR and now I'm able to boot, however it gives me getting following [1] error on startup (in both qemu and actual machine booted from usb).

The config I'm trying to build is basically a copy of drduh/YubiKey-Guide#nixos adapted for flakes and could be found in this gist and it is using this branch with this PR merged into it. I'm out of my depth here and would appreciate any pointers, thanks in advance.

[1]
image

@ghost
Copy link

ghost commented Aug 22, 2023

I'm experiencing the same issue as anpin, as the init gets stuck on failing to process stage 1.

@RaitoBezarius
Copy link
Member Author

Based on what I read, I can imagine that the nixos-generators module for ISO is overriding this one module, unfortunately, you are composing things which were not built to be composable.

I believe that #249218 PR is better suited for this usecase. I will build an ISO there and post it for people to test if needed.

@nixos-discourse
Copy link

This pull request has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/pi4-broken-on-23-11-uefi-zfs-root/36375/4

@wegank wegank added 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 2.status: merge conflict labels Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants