diff --git a/disk-deactivate/disk-deactivate.jq b/disk-deactivate/disk-deactivate.jq index 632bf8d..8ac9abf 100644 --- a/disk-deactivate/disk-deactivate.jq +++ b/disk-deactivate/disk-deactivate.jq @@ -24,7 +24,7 @@ def remove: ; def deactivate: - if .type == "disk" then + if .type == "disk" or .type == "loop" then [ # If this disk is a member of raid, stop that raid "md_dev=$(lsblk \(.path) -l -p -o type,name | awk 'match($1,\"raid.*\") {print $2}')", @@ -54,7 +54,7 @@ def deactivate: "mdadm --stop \(.name)" ] else - [] + ["echo Warning: unknown type '\(.type)'. Consider handling this in https://github.com/nix-community/disko/blob/master/disk-deactivate/disk-deactivate.jq"] end ; diff --git a/example/hybrid-mbr.nix b/example/hybrid-mbr.nix new file mode 100644 index 0000000..cf5f11f --- /dev/null +++ b/example/hybrid-mbr.nix @@ -0,0 +1,47 @@ +{disks ? ["/dev/sda"], ...}: { + disko.devices = { + disk = { + main = { + type = "disk"; + device = builtins.elemAt disks 0; + content = { + type = "gpt"; + efiGptPartitionFirst = false; + partitions = { + TOW-BOOT-FI = { + priority = 1; + type = "EF00"; + size = "32M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = null; + }; + hybrid = { + mbrPartitionType = "0x0c"; + mbrBootableFlag = false; + }; + }; + ESP = { + type = "EF00"; + size = "512M"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + root = { + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; + }; +} diff --git a/lib/default.nix b/lib/default.nix index 9cd2239..43a30b9 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -84,9 +84,11 @@ let "${dev}${toString index}" # /dev/md/raid1 style else if match "/dev/mapper/.+" dev != null then "${dev}${toString index}" # /dev/mapper/vg-lv1 style + else if match "/dev/loop[[:digit:]]+" dev != null + then "${dev}p${toString index}" # /dev/mapper/vg-lv1 style else abort '' - ${dev} seems not to be a supported disk format. Please add this to disko in https://github.com/nix-community/disko/blob/master/types/default.nix + ${dev} seems not to be a supported disk format. Please add this to disko in https://github.com/nix-community/disko/blob/master/lib/default.nix ''; /* get the index an item in a list diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index f830544..6dc7e7c 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -1,6 +1,7 @@ { config, options, lib, diskoLib, parent, device, ... }: let sortedPartitions = lib.sort (x: y: x.priority < y.priority) (lib.attrValues config.partitions); + sortedHybridPartitions = lib.filter (p: p.hybrid != null) sortedPartitions; in { options = { @@ -80,6 +81,35 @@ in ''; }; content = diskoLib.partitionType { parent = config; device = partition.config.device; }; + hybrid = lib.mkOption { + type = lib.types.nullOr (lib.types.submodule ({name, ...} @ hp: { + options = { + mbrPartitionType = lib.mkOption { + type = lib.types.nullOr lib.types.str; + default = null; + description = "MBR type code"; + }; + mbrBootableFlag = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Set the bootable flag (aka the active flag) on any or all of your hybridized partitions"; + }; + _create = diskoLib.mkCreateOption { + inherit config options; + default = '' + ${lib.optionalString (hp.config.mbrPartitionType != null) '' + sfdisk --label-nested dos --part-type ${parent.device} ${(toString partition.config._index)} ${hp.config.mbrPartitionType} + ''} + ${lib.optionalString hp.config.mbrBootableFlag '' + sfdisk --label-nested dos --activate ${parent.device} ${(toString partition.config._index)} + ''} + ''; + }; + }; + })); + default = null; + description = "Entry to add to the Hybrid MBR table"; + }; _index = lib.mkOption { internal = true; default = diskoLib.indexOf (x: x.name == partition.config.name) sortedPartitions 0; @@ -89,6 +119,11 @@ in default = { }; description = "Attrs of partitions to add to the partition table"; }; + efiGptPartitionFirst = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Place EFI GPT (0xEE) partition first in MBR (good for GRUB)"; + }; _parent = lib.mkOption { internal = true; default = parent; @@ -122,6 +157,20 @@ in ${lib.optionalString (partition.content != null) partition.content._create} '') sortedPartitions)} + ${ + lib.optionalString (sortedHybridPartitions != []) + ("sgdisk -h " + + (lib.concatStringsSep ":" (map (p: (toString p._index)) sortedHybridPartitions)) + + ( + lib.optionalString (!config.efiGptPartitionFirst) ":EE " + ) + + parent.device) + } + ${lib.concatMapStrings (p: + p.hybrid._create + ) + sortedHybridPartitions} + ''; }; _mount = diskoLib.mkMountOption { diff --git a/tests/hybrid-mbr.nix b/tests/hybrid-mbr.nix new file mode 100644 index 0000000..de68b26 --- /dev/null +++ b/tests/hybrid-mbr.nix @@ -0,0 +1,11 @@ +{ pkgs ? import { } +, diskoLib ? pkgs.callPackage ../lib { } +}: +diskoLib.testLib.makeDiskoTest { + inherit pkgs; + name = "hybrid-mbr"; + disko-config = ../example/hybrid-mbr.nix; + extraTestScript = '' + machine.succeed("mountpoint /"); + ''; +}