nixos/qemu-vm: add option for a separate boot partition on BIOS

This patch adds the option `virtualisation.useBootPartition` which
creates a separate boot partition on BIOS systems using the new
`legacy+boot` partition layout type in `nixos/lib/make-disk-image.nix`.

authored by

sanana and committed by
Masum Reza
95355b4d 11ed9936

+36 -5
+36 -5
nixos/modules/virtualisation/qemu-vm.nix
··· 62 62 }; 63 63 64 64 selectPartitionTableLayout = 65 - { useEFIBoot, useDefaultFilesystems }: 66 - if useDefaultFilesystems then if useEFIBoot then "efi" else "legacy" else "none"; 65 + { 66 + useEFIBoot, 67 + useDefaultFilesystems, 68 + useBootPartition, 69 + }: 70 + if useDefaultFilesystems then 71 + if useEFIBoot then 72 + "efi" 73 + else if useBootPartition then 74 + "legacy+boot" 75 + else 76 + "legacy" 77 + else 78 + "none"; 67 79 68 80 driveCmdline = 69 81 idx: ··· 337 349 format = "qcow2"; 338 350 onlyNixStore = false; 339 351 label = rootFilesystemLabel; 340 - partitionTableType = selectPartitionTableLayout { inherit (cfg) useDefaultFilesystems useEFIBoot; }; 352 + partitionTableType = selectPartitionTableLayout { 353 + inherit (cfg) useBootPartition useDefaultFilesystems useEFIBoot; 354 + }; 341 355 installBootLoader = cfg.installBootLoader; 342 356 touchEFIVars = cfg.useEFIBoot; 343 357 diskSize = "auto"; ··· 431 445 432 446 virtualisation.bootPartition = mkOption { 433 447 type = types.nullOr types.path; 434 - default = if cfg.useEFIBoot then "/dev/disk/by-label/${espFilesystemLabel}" else null; 435 - defaultText = literalExpression ''if cfg.useEFIBoot then "/dev/disk/by-label/${espFilesystemLabel}" else null''; 448 + default = 449 + if cfg.useEFIBoot then 450 + "/dev/disk/by-label/${espFilesystemLabel}" 451 + else if cfg.useBootPartition then 452 + "/dev/disk/by-label/BOOT" 453 + else 454 + null; 455 + defaultText = literalExpression '' 456 + if cfg.useEFIBoot then "/dev/disk/by-label/${espFilesystemLabel}" 457 + else if cfg.useBootPartition then "/dev/disk/by-label/BOOT" 458 + else null''; 436 459 example = "/dev/disk/by-label/esp"; 437 460 description = '' 438 461 The path (inside the VM) to the device containing the EFI System Partition (ESP). ··· 926 949 927 950 This is best-effort and may break with unconventional partition setups. 928 951 Use `virtualisation.useDefaultFilesystems` for a known-working configuration. 952 + ''; 953 + }; 954 + 955 + virtualisation.useBootPartition = mkEnableOption null // { 956 + description = '' 957 + If enabled for legacy MBR VMs, the VM image will have a separate boot 958 + partition mounted at /boot. 959 + useBootPartition is ignored if useEFIBoot == true. 929 960 ''; 930 961 }; 931 962