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

qemu-vm: Fix useBootLoader, remove /boot read-only restriction #92122

Merged
merged 5 commits into from Jul 6, 2020

Conversation

nh2
Copy link
Contributor

@nh2 nh2 commented Jul 3, 2020

TODO
Motivation for this change
  • Do not mount /boot read-only, because it is not necessary and only forbids useful things.
  • Fix device name hardcodes on useBootLoader.

See commit messages for details.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

I've tested it via the grub-test-vm in https://github.com/nh2/nixos-vm-examples/tree/0b29937fcb23424b95aa98121c94db02fd9b920d

Copy link
Contributor

@srhb srhb left a comment

Choose a reason for hiding this comment

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

LGTM but I very rarely use this -- someone else might have a more educated opinion 😄

@nh2
Copy link
Contributor Author

nh2 commented Jul 3, 2020

Also FYI @edolstra that this removes the ro mount of /boot in the VM (the commit that added that is very old, since the beginning of the VM stuff).

CCing also the reviewers I put on #85895, @OmnipotentEntity, @Mic92, @symphorien, @emilazy.

@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/212

@chkno chkno mentioned this pull request Jul 3, 2020
7 tasks
Copy link
Member

@chkno chkno left a comment

Choose a reason for hiding this comment

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

Can you add a test that verifies useBootLoader? This both keeps it from breaking again and also really helps other folks working in here to make changes with confidence that they're not breaking stuff.

@@ -528,6 +567,8 @@ in

virtualisation.qemu.drives = mkMerge [
(mkIf cfg.useBootLoader [
# The order of this list determines the device names, see
Copy link
Member

Choose a reason for hiding this comment

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

I fixed this brittle order-determining-device-names thing as part of #72354. Sorry that I didn't aggressively enough pursue reviewers to get that merged to make this change easier. I've split out the cleanup and refactor parts into the separate PR #92205 that can hopefully be reviewed and merged faster.

I think it'd be great if we could have fewer "/dev/..." strings flying around in here, and just one diskInterface == "scsi" test about device names.

Consider reviewing #92205? (Rebasing this atop #92205 would be an excellent way to review #92205!)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, currently testing the rebase.

Copy link
Contributor Author

@nh2 nh2 Jul 4, 2020

Choose a reason for hiding this comment

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

@chkno With #92205 (comment) fixed, this PR rebased on top of yours passes the VM based test I wrote for #85895.

So this is all looking very good, thanks!

@danielfullmer
Copy link
Contributor

Just adding a note here that I also need a writable boot partition for testing systemd-boot's boot counters. These counters are state which is contained in the filenames of the boot entries under /boot/loader/entries.

If this change is accepted, we should remove this statement from the nixos-rebuild manpage, however:

partition, which is mounted read-only in the VM.

@nh2 nh2 force-pushed the qemu-vm-fix-useBootLoader branch from 1b496d4 to e599834 Compare July 4, 2020 01:27
@nh2
Copy link
Contributor Author

nh2 commented Jul 4, 2020

If this change is accepted, we should remove this statement from the nixos-rebuild manpage, however:

Great point, I've added that to the commit.

@nh2 nh2 force-pushed the qemu-vm-fix-useBootLoader branch 2 times, most recently from 010aa57 to 8d5ba86 Compare July 4, 2020 12:37
nh2 added 2 commits July 4, 2020 14:44
There does not seem to be a good reason to do this, and it breaks running
`nixos-rebuild boot --install-bootloader` inside the VM.
boot.loader.grub.device` was hardcoded to `bootDevice`, which is
wrong, because that's the device for `/`, and with `useBootLoader`
the boot loader is not on that device.

This bug probably came into existence because of bad naming;
`virtualisation.bootDevice` has description
"The disk to be used for the root filesystem", which is very confusing;
it should be `.rootDevice` then!
Unfortunately, the description is right and the attribute name is wrong,
so it is not easy to change this without deprecation.

This commit ensures that even if you use `useBootLoader` and
`diskInterface == "scsi"`, the created VM can boot through, and can run
`nixos-rebuild afterwards.

It also adds extra commentary to explain what's going on in this module
in general in relation to `useBootLoader`.
@nh2 nh2 force-pushed the qemu-vm-fix-useBootLoader branch from 8d5ba86 to 5b16d4c Compare July 4, 2020 12:48
@nh2 nh2 requested a review from chkno July 4, 2020 13:08
@nh2
Copy link
Contributor Author

nh2 commented Jul 4, 2020

I've addressed all feedback and re-tested, will probably merge tomorrow.

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