mirror of
https://github.com/nix-community/disko.git
synced 2024-09-11 06:25:33 +03:00
Merge pull request #595 from nix-community/idempotent_gpt
idempotent gpt
This commit is contained in:
commit
9e0bf2fe7f
@ -153,40 +153,42 @@ in
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = ''
|
default = ''
|
||||||
if ! blkid "${config.device}" >/dev/null; then
|
if ! blkid "${config.device}" >&2; then
|
||||||
${lib.concatStrings (map (partition: ''
|
sgdisk --clear ${config.device}
|
||||||
if sgdisk \
|
|
||||||
--info=${toString partition._index} \
|
|
||||||
${config.device} > /dev/null 2>&1
|
|
||||||
then
|
|
||||||
sgdisk \
|
|
||||||
--align-end \
|
|
||||||
--new=${toString partition._index}:${partition.start}:${partition.end} \
|
|
||||||
--change-name=${toString partition._index}:${partition.label} \
|
|
||||||
--typecode=${toString partition._index}:${partition.type} \
|
|
||||||
${config.device}
|
|
||||||
# ensure /dev/disk/by-path/..-partN exists before continuing
|
|
||||||
partprobe ${config.device}
|
|
||||||
udevadm trigger --subsystem-match=block
|
|
||||||
udevadm settle
|
|
||||||
fi
|
|
||||||
'') 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
|
|
||||||
}
|
|
||||||
fi
|
fi
|
||||||
|
${lib.concatStrings (map (partition: ''
|
||||||
|
# try to create the partition, if it fails, try to change the type and name
|
||||||
|
if ! sgdisk \
|
||||||
|
--align-end \
|
||||||
|
--new=${toString partition._index}:${partition.start}:${partition.end} \
|
||||||
|
--change-name=${toString partition._index}:${partition.label} \
|
||||||
|
--typecode=${toString partition._index}:${partition.type} \
|
||||||
|
${config.device}
|
||||||
|
then sgdisk \
|
||||||
|
--change-name=${toString partition._index}:${partition.label} \
|
||||||
|
--typecode=${toString partition._index}:${partition.type} \
|
||||||
|
${config.device}
|
||||||
|
fi
|
||||||
|
# ensure /dev/disk/by-path/..-partN exists before continuing
|
||||||
|
partprobe ${config.device} || : # sometimes partprobe fails, but the partitions are still up2date
|
||||||
|
udevadm trigger --subsystem-match=block
|
||||||
|
udevadm settle
|
||||||
|
'') 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
|
||||||
|
}
|
||||||
|
|
||||||
${lib.concatStrings (map (partition: ''
|
${lib.concatStrings (map (partition: ''
|
||||||
${lib.optionalString (partition.content != null) partition.content._create}
|
${lib.optionalString (partition.content != null) partition.content._create}
|
||||||
|
@ -8,6 +8,7 @@ diskoLib.makeDiskImages {
|
|||||||
({ config, ... }: {
|
({ config, ... }: {
|
||||||
documentation.enable = false;
|
documentation.enable = false;
|
||||||
system.stateVersion = config.system.nixos.version;
|
system.stateVersion = config.system.nixos.version;
|
||||||
|
disko.memSize = 2048;
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user