From 41bfc2df9ee9872748a5ef60b568fbc861e2bbb2 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sat, 8 Jul 2023 23:18:57 +0200 Subject: [PATCH] Refactor structure of DerGeret's disk --- profiles/DerGeret/Windows/Setup.ps1 | 32 +++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/profiles/DerGeret/Windows/Setup.ps1 b/profiles/DerGeret/Windows/Setup.ps1 index 72a41787..af302337 100644 --- a/profiles/DerGeret/Windows/Setup.ps1 +++ b/profiles/DerGeret/Windows/Setup.ps1 @@ -11,28 +11,44 @@ $Global:SetupConfigPostprocessor = { $diskConfig = $setupComponent.SelectSingleNode("./ua:DiskConfiguration/ua:Disk", $namespace); $installationPartition = $setupComponent.SelectSingleNode("./ua:ImageInstall/ua:OSImage/ua:InstallTo/ua:PartitionID", $namespace); - $newIndex = [int]$installationPartition.InnerText; + $newIndex = 2; $installationPartition.InnerText = "$($newIndex + 1)"; $partitionCreations = $diskConfig.SelectSingleNode("./ua:CreatePartitions", $namespace); - $newPartition = $partitionCreations.SelectNodes("./ua:CreatePartition", $namespace)[0].CloneNode($true); + $winPartition = ($partitionCreations.SelectNodes("./ua:CreatePartition", $namespace) | Select-Object -Last)[0]; + $newPartition = $winPartition.CloneNode($true); $offset = 0; for ($i = 0; $i -lt $partitionCreations.ChildNodes.Count; $i++) { $partition = $partitionCreations.ChildNodes[$i]; $order = [int]$partition.SelectSingleNode("./ua:Order", $namespace).InnerText; + $offset += [int]$partition.SelectSingleNode("./ua:Size", $namespace).InnerText; + $newOrder = $order; - if ($order -ge $newIndex) { - $partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$($order + 1)"; + if ($order -eq 2) { + $newOrder--; } else { - $offset += [int]$partition.SelectSingleNode("./ua:Size", $namespace).InnerText; + if ($order -ge $newIndex) { + $newOrder++; + } + + if ($order -lt 2) { + $newOrder++; + } + } + + if ($order -ne $newOrder) { + $partition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newOrder"; } } - # Add 1 TB space before Windows installation... wha-!? For Linux, ofc! I use Arch Linux, btw. - $newPartition.SelectSingleNode("./ua:Size", $namespace).InnerText = "$((64 * 1024) - $offset)"; - $newPartition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex"; + # Add space before Windows installation... wha-!? For Linux, ofc! I use Arch Linux, btw. + $size = $winPartition.OwnerDocument.CreateElement("Size"); + $size.InnerText = "$((1 * 1024 * 1024) - $offset)"; + $winPartition.RemoveChild($winPartition.SelectSingleNode("./Extend")); + $winPartition.AppendChild($size); + $newPartition.SelectSingleNode("./ua:Order", $namespace).InnerText = "$newIndex"; $null = $partitionCreations.AppendChild($newPartition); $partitionModifications = $diskConfig.SelectSingleNode("./ua:ModifyPartitions", $namespace);