Skip to content

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

Merged
nh2 merged 5 commits intoNixOS:masterfrom
nh2:qemu-vm-fix-useBootLoader
Jul 6, 2020
Merged

qemu-vm: Fix useBootLoader, remove /boot read-only restriction#92122
nh2 merged 5 commits intoNixOS:masterfrom
nh2:qemu-vm-fix-useBootLoader

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

@nh2 nh2 added 0.kind: bug Something is broken 0.kind: enhancement Add something new or improve an existing system. 8.has: clean-up This PR removes packages or removes other cruft labels Jul 3, 2020
@nh2 nh2 requested a review from srhb July 3, 2020 02:40
@nh2 nh2 self-assigned this Jul 3, 2020
@ofborg ofborg bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jul 3, 2020
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.

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.

@ofborg ofborg bot added 8.has: documentation This PR adds or changes documentation 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux. and removed 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Jul 4, 2020
@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

Labels

0.kind: bug Something is broken 0.kind: enhancement Add something new or improve an existing system. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: clean-up This PR removes packages or removes other cruft 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 10.rebuild-linux: 1 This PR causes 1 package to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants