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 40 This partition layout is unsuitable for UEFI. 41 42 #### `legacy+gpt` 43 44 This partition table type uses GPT and: ··· 106 additionalSpace ? "512M", 107 108 # size of the boot partition, is only used if partitionTableType is 109 - # either "efi" or "hybrid" 110 # This will be undersized slightly, as this is actually the offset of 111 # the end of the partition. Generally it will be 1MiB smaller. 112 bootSize ? "256M", ··· 197 assert ( 198 lib.assertOneOf "partitionTableType" partitionTableType [ 199 "legacy" 200 "legacy+gpt" 201 "efi" 202 "efixbootldr" ··· 260 { 261 # switch-case 262 legacy = "1"; 263 "legacy+gpt" = "2"; 264 efi = "2"; 265 efixbootldr = "3"; ··· 276 mkpart primary ext4 1MiB 100% \ 277 print 278 ''; 279 "legacy+gpt" = '' 280 parted --script $diskImage -- \ 281 mklabel gpt \ ··· 540 # Add the 1MiB aligned reserved space (includes MBR) 541 reservedSpace=$(( mebibyte )) 542 '' 543 else 544 '' 545 reservedSpace=0 ··· 693 mount /dev/vda2 /mnt/boot 694 695 ${lib.optionalString touchEFIVars "mount -t efivarfs efivarfs /sys/firmware/efi/efivars"} 696 ''} 697 698 # Install a configuration.nix
··· 39 40 This partition layout is unsuitable for UEFI. 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 + 50 #### `legacy+gpt` 51 52 This partition table type uses GPT and: ··· 114 additionalSpace ? "512M", 115 116 # size of the boot partition, is only used if partitionTableType is 117 + # either "efi", "hybrid", or "legacy+boot" 118 # This will be undersized slightly, as this is actually the offset of 119 # the end of the partition. Generally it will be 1MiB smaller. 120 bootSize ? "256M", ··· 205 assert ( 206 lib.assertOneOf "partitionTableType" partitionTableType [ 207 "legacy" 208 + "legacy+boot" 209 "legacy+gpt" 210 "efi" 211 "efixbootldr" ··· 269 { 270 # switch-case 271 legacy = "1"; 272 + "legacy+boot" = "2"; 273 "legacy+gpt" = "2"; 274 efi = "2"; 275 efixbootldr = "3"; ··· 286 mkpart primary ext4 1MiB 100% \ 287 print 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 + ''; 297 "legacy+gpt" = '' 298 parted --script $diskImage -- \ 299 mklabel gpt \ ··· 558 # Add the 1MiB aligned reserved space (includes MBR) 559 reservedSpace=$(( mebibyte )) 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 + '' 567 else 568 '' 569 reservedSpace=0 ··· 717 mount /dev/vda2 /mnt/boot 718 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 725 ''} 726 727 # Install a configuration.nix