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: remove bootDisk, refactor using make-disk-image with better EFI support #203641

Closed
Closed
5 changes: 1 addition & 4 deletions nixos/lib/make-disk-image.nix
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ let format' = format; in let
${optionalString (fsType == "ext4" && deterministic) ''
tune2fs -T now ${optionalString deterministic "-U ${rootFSUID}"} -c 0 -i 0 $rootDisk
''}

# make systemd-boot find ESP without udev
mkdir /dev/block
ln -s /dev/vda1 /dev/block/254:1
Expand Down Expand Up @@ -492,10 +493,6 @@ let format' = format; in let
${optionalString (config.boot.loader.grub.device != "/dev/vda") ''
ln -s /dev/vda ${config.boot.loader.grub.device}
''}
# TODO: needed?
# For GRUB 0.97 compatibility
mkdir -p /mnt/boot/grub
echo '(hd0) /dev/vda' > /mnt/boot/grub/device.map

# Set up core system link, bootloader (sd-boot, GRUB, uboot, etc.), etc.
NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root $mountPoint -- /nix/var/nix/profiles/system/bin/switch-to-configuration boot
Expand Down
30 changes: 24 additions & 6 deletions nixos/modules/virtualisation/qemu-vm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,34 @@ in
'';
};

virtualisation.bootPartition =
Copy link
Member

Choose a reason for hiding this comment

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

Was the legacy boot broken before or broken by your changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Broken by my changes

mkOption {
type = types.nullOr types.path;
default = if cfg.useEFIBoot then "${cfg.bootDevice}1" else null;
defaultText = literalExpression ''if cfg.useEFIBoot then "''${cfg.bootDevice}1" else null;'';
example = "/dev/vda1";
description =
lib.mdDoc ''
The boot partition to be used to mount /boot filesystem.
In legacy boots, this should be null.
By default, in EFI boot, it is the first partition of the boot device.
'';
};

virtualisation.rootDevice =
mkOption {
type = types.path;
default =
if (cfg.useBootLoader && cfg.bootDevice == options.virtualisation.bootDevice.default)
if (cfg.useBootLoader && cfg.useEFIBoot && cfg.useDefaultFilesystems)
then "${cfg.bootDevice}2"
else
if !cfg.useBootLoader then cfg.bootDevice else null;
(
if (cfg.useBootLoader && !cfg.useEFIBoot && cfg.useDefaultFilesystems)
then
"${cfg.bootDevice}1"
else
null
);
defaultText = ''if (cfg.useBootLoader && !hasPrefix "/dev/mapper/" ''${cfg.bootDevice}) then "''${cfg.bootDevice}2" else cfg.bootDevice;'';
example = "/dev/vda2";
description =
Expand Down Expand Up @@ -897,8 +917,6 @@ in
optional cfg.writableStore "overlay"
++ optional (cfg.qemu.diskInterface == "scsi") "sym53c8xx";

# TODO: needed? virtualisation.bootDevice = mkDefault (driveDeviceName 1);

virtualisation.additionalPaths = [ config.system.build.toplevel ];

virtualisation.sharedDirectories = {
Expand Down Expand Up @@ -1042,10 +1060,10 @@ in
neededForBoot = true;
};
} //
optionalAttrs cfg.useBootLoader {
optionalAttrs (cfg.useBootLoader && cfg.bootPartition != null) {
# see note [Disk layout with `useBootLoader`]
"/boot" = {
device = "${lookupDriveDeviceName "root" cfg.qemu.drives}1"; # 1 for e.g. `vda1`, as created in `systemImage`
device = cfg.bootPartition; # 1 for e.g. `vda1`, as created in `systemImage`
fsType = "vfat";
noCheck = true; # fsck fails on a r/o filesystem
};
Expand Down