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/qemu-vm: refactor bootDisk using make-disk-image #207039

Merged
merged 5 commits into from
Apr 21, 2023

Conversation

RaitoBezarius
Copy link
Member

@RaitoBezarius RaitoBezarius commented Dec 20, 2022

Description of changes

Depends on #207038.

A small cover letter on the changes:

We remove the bootDisk ad-hoc generation and rewire it up with make-disk-image, this unlocks various features:

  • perform bootloader operations that have an impact on EFI variables (SecureBoot, etc.)
  • factorization (everything is controlled by make-disk-image)
  • clarification of the "current" boot configuration: https://github.com/NixOS/nixpkgs/pull/207039/files#diff-5f468553a33ed484ce0a34ef2f404fb7f37bd981ba95fa5ec666bcbdaeb3d6d9R253-R263 -- we have various mode of operations and this module is becoming confusing on what bunch of booleans realizes a specific configuration, pushing for an explicit string makes the code more maintainable and readable.
  • exposes rootDevice, bootDevice and bootPartition which clarify further the different roles of the disk in the VM world we use, to cater for legacy (disk-level) and UEFI (partition-level) needs.
  • undo persistBootDevice introduced in 678eed3

Testing is done on https://hydra.nixos.org/jobset/nixos/python-test-refactoring on a recent enough: nixos-unstable-small and treewide cleanups are done.

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.05 Release Notes (or backporting 22.11 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
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@Mic92 Mic92 requested a review from Lassulus December 26, 2022 11:21
@blitz
Copy link
Contributor

blitz commented Jan 10, 2023

@RaitoBezarius The comments sound like you still want to work on this. What's the status here?

@RaitoBezarius
Copy link
Member Author

@RaitoBezarius The comments sound like you still want to work on this. What's the status here?

Didn't have time to fix my own comments yet, but it's open to additional comments.

@RaitoBezarius
Copy link
Member Author

Latest evaluation: https://hydra.nixos.org/eval/1793584?compare=-172800&full=0#tabs-now-fail
From there, it seems like there are only few problematic jobs remaining.

@RaitoBezarius RaitoBezarius force-pushed the qemu-boot-disk-using-make-disk-image branch 2 times, most recently from fd8d369 to 5724827 Compare April 15, 2023 17:46
Copy link
Member

@lilyinstarlight lilyinstarlight left a comment

Choose a reason for hiding this comment

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

I'm not the most knowledgeable about the qemu-vm test stuff, but this change feels sane to me

Since it changes some semantics it could have some fallout for downstream users, but I don't imagine there are many and it should hopefully be easy for them to understand and update

nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
@nixos-discourse
Copy link

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

https://discourse.nixos.org/t/prs-ready-for-review/3032/2090

@RaitoBezarius RaitoBezarius force-pushed the qemu-boot-disk-using-make-disk-image branch from 5724827 to 792fd0a Compare April 16, 2023 20:47
@lilyinstarlight
Copy link
Member

It looks like nixosTests.bootspec.grub is failing with this PR with this log snippet:

nixos-disk-image> installing the GRUB 2 boot loader on /dev/vda...
nixos-disk-image> Installing for i386-pc platform.
nixos-disk-image> /nix/store/07bws5lfvgz0a6psxbyhzzz0sbrnqdab-grub-2.06/sbin/grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
nixos-disk-image> /nix/store/07bws5lfvgz0a6psxbyhzzz0sbrnqdab-grub-2.06/sbin/grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
nixos-disk-image> /nix/store/07bws5lfvgz0a6psxbyhzzz0sbrnqdab-grub-2.06/sbin/grub-install: error: will not proceed with blocklists.
nixos-disk-image> /nix/store/nj03jkzbac12apslfmhhmss8qrlvx7wg-install-grub.pl: installation of GRUB on /dev/vda failed: No such file or directory

@RaitoBezarius
Copy link
Member Author

It looks like nixosTests.bootspec.grub is failing with this PR with this log snippet:

nixos-disk-image> installing the GRUB 2 boot loader on /dev/vda...
nixos-disk-image> Installing for i386-pc platform.
nixos-disk-image> /nix/store/07bws5lfvgz0a6psxbyhzzz0sbrnqdab-grub-2.06/sbin/grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
nixos-disk-image> /nix/store/07bws5lfvgz0a6psxbyhzzz0sbrnqdab-grub-2.06/sbin/grub-install: warning: Embedding is not possible.  GRUB can only be installed in this setup by using blocklists.  However, blocklists are UNRELIABLE and their use is discouraged..
nixos-disk-image> /nix/store/07bws5lfvgz0a6psxbyhzzz0sbrnqdab-grub-2.06/sbin/grub-install: error: will not proceed with blocklists.
nixos-disk-image> /nix/store/nj03jkzbac12apslfmhhmss8qrlvx7wg-install-grub.pl: installation of GRUB on /dev/vda failed: No such file or directory

If I remember well, the failure is alas unrelated. It's because GRUB tries to install legacy for a UEFI only target.
I implemented the fix somewhere and lost it :D.

@lilyinstarlight
Copy link
Member

If I remember well, the failure is alas unrelated. It's because GRUB tries to install legacy for a UEFI only target.

Yeah the error message sounded like that was the issue

It looks like the NixOS GRUB module assumes that it needs to install legacy unless boot.loader.grub.device = "nodev" is set (in which case if I'm following this Perl right (ugh) then it will assume it needs to do an EFI-only install)

@RaitoBezarius
Copy link
Member Author

If I remember well, the failure is alas unrelated. It's because GRUB tries to install legacy for a UEFI only target.

Yeah the error message sounded like that was the issue

It looks like the NixOS GRUB module assumes that it needs to install legacy unless boot.loader.grub.device = "nodev" is set (in which case if I'm following this Perl right (ugh) then it will assume it needs to do an EFI-only install)

Thank you for going in the rabbit hole, I rediscover this each time. :)

@lilyinstarlight
Copy link
Member

Thank you for going in the rabbit hole, I rediscover this each time. :)

So I don't know if this is "correct" necessarily, but this diff on top of this PR does allow a number of grub tests to pass again (those which currently pass on master and fail on this PR):

diff --git a/nixos/modules/virtualisation/qemu-vm.nix b/nixos/modules/virtualisation/qemu-vm.nix
index f85567c42f2..fa928a1ba2f 100644
--- a/nixos/modules/virtualisation/qemu-vm.nix
+++ b/nixos/modules/virtualisation/qemu-vm.nix
@@ -849,7 +849,7 @@ in
             ${opt.writableStore} = false;
         '';
 
-    boot.loader.grub.device = mkVMOverride cfg.bootLoaderDevice;
+    boot.loader.grub.device = mkVMOverride (if cfg.useEFIBoot then "nodev" else cfg.bootLoaderDevice);
     boot.loader.grub.gfxmodeBios = with cfg.resolution; "${toString x}x${toString y}";
     virtualisation.rootDevice = mkDefault suggestedRootDevice;
 

@RaitoBezarius RaitoBezarius force-pushed the qemu-boot-disk-using-make-disk-image branch from 792fd0a to 07f5a70 Compare April 17, 2023 09:52
@RaitoBezarius
Copy link
Member Author

@lilyinstarlight Adressed and latest evaluation shows that it fixes the GRUB tests: https://hydra.nixos.org/eval/1793709

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 change. The comments and descriptions could use some more editing. Most of my comments are either nitpicks or revolve around naming. Although I think naming is very important, I think it is more important to get this PR across the finish line. We can still improve the naming later.

nixos/tests/bootspec.nix Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
nixos/tests/bootspec.nix Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Outdated Show resolved Hide resolved
nixos/modules/virtualisation/qemu-vm.nix Show resolved Hide resolved
@RaitoBezarius RaitoBezarius force-pushed the qemu-boot-disk-using-make-disk-image branch 2 times, most recently from 318c68b to 58f7c4e Compare April 19, 2023 23:49
@RaitoBezarius
Copy link
Member Author

Started a new evaluation here: https://hydra.nixos.org/jobset/nixos/python-test-refactoring

@RaitoBezarius RaitoBezarius force-pushed the qemu-boot-disk-using-make-disk-image branch from 58f7c4e to e81f8d2 Compare April 20, 2023 00:02
This option has been introduced in 678eed3 without realizing there was this
PR inflight, unfortunately, it collide with what this PR does and make
it irrelevant.

Therefore, I remove it here.
I do a lot of work on QEMU VM and make-disk-image and I was bitten by an
unnotified change recently, so I want to chime in the future changes of
this file.
@RaitoBezarius RaitoBezarius force-pushed the qemu-boot-disk-using-make-disk-image branch from e81f8d2 to 76f1b63 Compare April 21, 2023 11:00
@RaitoBezarius
Copy link
Member Author

Finally, this will be merged once ofborg CI passes.

@RaitoBezarius RaitoBezarius merged commit 4b4e4c3 into master Apr 21, 2023
5 checks passed
@RaitoBezarius
Copy link
Member Author

Thanks to everyone involved in this journey. :)

@alyssais alyssais deleted the qemu-boot-disk-using-make-disk-image branch April 28, 2023 13:27
@alyssais
Copy link
Member

This PR broke nixosTests.kexec. It seems like the final Hydra eval had that test as broken, so maybe it's worth a look to see if any other tests were found to be broken during that eval and overlooked?

@RaitoBezarius
Copy link
Member Author

RaitoBezarius commented May 20, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants