@@ -152,36 +152,48 @@ def parse_arg(cls, disk_config: _DiskLayoutConfigurationSerialization) -> DiskLa
152
152
using_gpt = SysInfo .has_uefi ()
153
153
154
154
for dev_mod in device_modifications :
155
- partitions = sorted ( dev_mod .partitions , key = lambda p : p . start )
155
+ dev_mod .partitions . sort ( key = lambda p : ( not p . is_delete (), p . start ) )
156
156
157
- for i , current_partition in enumerate (partitions [1 :], start = 1 ):
158
- previous_partition = partitions [i - 1 ]
157
+ non_delete_partitions = [
158
+ part_mod for part_mod in dev_mod .partitions
159
+ if not part_mod .is_delete ()
160
+ ]
161
+
162
+ if not non_delete_partitions :
163
+ continue
164
+
165
+ first = non_delete_partitions [0 ]
166
+ if first .status == ModificationStatus .Create and not first .start .is_valid_start ():
167
+ raise ValueError ('First partition must start at no less than 1 MiB' )
168
+
169
+ for i , current_partition in enumerate (non_delete_partitions [1 :], start = 1 ):
170
+ previous_partition = non_delete_partitions [i - 1 ]
159
171
if (
160
172
current_partition .status == ModificationStatus .Create
161
173
and current_partition .start < previous_partition .end
162
174
):
163
175
raise ValueError ('Partitions overlap' )
164
176
165
- partitions = [
166
- part_mod for part_mod in dev_mod . partitions
177
+ create_partitions = [
178
+ part_mod for part_mod in non_delete_partitions
167
179
if part_mod .status == ModificationStatus .Create
168
180
]
169
181
170
- if not partitions :
182
+ if not create_partitions :
171
183
continue
172
184
173
- for part in partitions :
185
+ for part in create_partitions :
174
186
if (
175
187
part .start != part .start .align ()
176
188
or part .length != part .length .align ()
177
189
):
178
190
raise ValueError ('Partition is misaligned' )
179
191
192
+ last = create_partitions [- 1 ]
180
193
total_size = dev_mod .device .device_info .total_size
181
-
182
- if using_gpt and partitions [- 1 ].end > total_size .gpt_end ():
194
+ if using_gpt and last .end > total_size .gpt_end ():
183
195
raise ValueError ('Partition overlaps backup GPT header' )
184
- elif partitions [ - 1 ] .end > total_size .align ():
196
+ elif last .end > total_size .align ():
185
197
raise ValueError ('Partition too large for device' )
186
198
187
199
# Parse LVM configuration from settings
@@ -391,6 +403,9 @@ def format_highest(self, include_unit: bool = True, units: Units = Units.BINARY)
391
403
else :
392
404
return self .si_unit_highest (include_unit )
393
405
406
+ def is_valid_start (self ) -> bool :
407
+ return self >= Size (1 , Unit .MiB , self .sector_size )
408
+
394
409
def align (self ) -> Size :
395
410
align_norm = Size (1 , Unit .MiB , self .sector_size )._normalize ()
396
411
src_norm = self ._normalize ()
0 commit comments