mirror of
https://github.com/nix-community/disko
synced 2024-11-10 06:14:14 +00:00
Rework Hybrid MBR https://github.com/nix-community/disko/pull/168 (#508)
Add hybrid MBR functionality to the gpt type
This commit is contained in:
parent
c12719812d
commit
f7424625dc
5 changed files with 112 additions and 3 deletions
|
@ -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
|
||||
;
|
||||
|
||||
|
|
47
example/hybrid-mbr.nix
Normal file
47
example/hybrid-mbr.nix
Normal file
|
@ -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 = "/";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
11
tests/hybrid-mbr.nix
Normal file
11
tests/hybrid-mbr.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
{ pkgs ? import <nixpkgs> { }
|
||||
, diskoLib ? pkgs.callPackage ../lib { }
|
||||
}:
|
||||
diskoLib.testLib.makeDiskoTest {
|
||||
inherit pkgs;
|
||||
name = "hybrid-mbr";
|
||||
disko-config = ../example/hybrid-mbr.nix;
|
||||
extraTestScript = ''
|
||||
machine.succeed("mountpoint /");
|
||||
'';
|
||||
}
|
Loading…
Reference in a new issue