nixos/make-disk-image: support partition layout `"legacy+boot"`

This patch adds a new partition layout type `"legacy+boot` which will
produce MBR images with a separate FAT32 boot partition. This is
necessary for adding a NixOS test for Limine on BIOS systems, as Limine
can't read ext4 partitions.

authored by

sanana and committed by
Masum Reza
11ed9936 2c80b78e

+30 -1
+30 -1
nixos/lib/make-disk-image.nix
··· 39 39 40 40 This partition layout is unsuitable for UEFI. 41 41 42 + #### `legacy+boot` 43 + 44 + The image is partitioned using MBR and: 45 + - creates a FAT32 BOOT partition from 1MiB to specified `bootSize` parameter (256MiB by default), set it bootable ; 46 + - creates a primary ext4 partition starting after the boot partition and extending to the full disk image 47 + 48 + This partition layout is unsuitable for UEFI. 49 + 42 50 #### `legacy+gpt` 43 51 44 52 This partition table type uses GPT and: ··· 106 114 additionalSpace ? "512M", 107 115 108 116 # size of the boot partition, is only used if partitionTableType is 109 - # either "efi" or "hybrid" 117 + # either "efi", "hybrid", or "legacy+boot" 110 118 # This will be undersized slightly, as this is actually the offset of 111 119 # the end of the partition. Generally it will be 1MiB smaller. 112 120 bootSize ? "256M", ··· 197 205 assert ( 198 206 lib.assertOneOf "partitionTableType" partitionTableType [ 199 207 "legacy" 208 + "legacy+boot" 200 209 "legacy+gpt" 201 210 "efi" 202 211 "efixbootldr" ··· 260 269 { 261 270 # switch-case 262 271 legacy = "1"; 272 + "legacy+boot" = "2"; 263 273 "legacy+gpt" = "2"; 264 274 efi = "2"; 265 275 efixbootldr = "3"; ··· 276 286 mkpart primary ext4 1MiB 100% \ 277 287 print 278 288 ''; 289 + "legacy+boot" = '' 290 + parted --script $diskImage -- \ 291 + mklabel msdos \ 292 + mkpart primary fat32 1MiB $bootSizeMiB \ 293 + set 1 boot on \ 294 + mkpart primary ext4 $bootSizeMiB 100% \ 295 + print 296 + ''; 279 297 "legacy+gpt" = '' 280 298 parted --script $diskImage -- \ 281 299 mklabel gpt \ ··· 540 558 # Add the 1MiB aligned reserved space (includes MBR) 541 559 reservedSpace=$(( mebibyte )) 542 560 '' 561 + else if partitionTableType == "legacy+boot" then 562 + '' 563 + # The explanation from the above "efi" case applies here too, 564 + # but gptSpace is not needed without a GPT. 565 + reservedSpace=$(( bootSize )) 566 + '' 543 567 else 544 568 '' 545 569 reservedSpace=0 ··· 693 717 mount /dev/vda2 /mnt/boot 694 718 695 719 ${lib.optionalString touchEFIVars "mount -t efivarfs efivarfs /sys/firmware/efi/efivars"} 720 + ''} 721 + ${lib.optionalString (partitionTableType == "legacy+boot") '' 722 + mkdir -p /mnt/boot 723 + mkfs.vfat -n BOOT /dev/vda1 724 + mount /dev/vda1 /mnt/boot 696 725 ''} 697 726 698 727 # Install a configuration.nix