Skip to content

Commit 700294f

Browse files
authored
disk: validate first partition start (#3096)
1 parent ad01503 commit 700294f

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

archinstall/lib/disk/device_model.py

+25-10
Original file line numberDiff line numberDiff line change
@@ -152,36 +152,48 @@ def parse_arg(cls, disk_config: _DiskLayoutConfigurationSerialization) -> DiskLa
152152
using_gpt = SysInfo.has_uefi()
153153

154154
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))
156156

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]
159171
if (
160172
current_partition.status == ModificationStatus.Create
161173
and current_partition.start < previous_partition.end
162174
):
163175
raise ValueError('Partitions overlap')
164176

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
167179
if part_mod.status == ModificationStatus.Create
168180
]
169181

170-
if not partitions:
182+
if not create_partitions:
171183
continue
172184

173-
for part in partitions:
185+
for part in create_partitions:
174186
if (
175187
part.start != part.start.align()
176188
or part.length != part.length.align()
177189
):
178190
raise ValueError('Partition is misaligned')
179191

192+
last = create_partitions[-1]
180193
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():
183195
raise ValueError('Partition overlaps backup GPT header')
184-
elif partitions[-1].end > total_size.align():
196+
elif last.end > total_size.align():
185197
raise ValueError('Partition too large for device')
186198

187199
# Parse LVM configuration from settings
@@ -391,6 +403,9 @@ def format_highest(self, include_unit: bool = True, units: Units = Units.BINARY)
391403
else:
392404
return self.si_unit_highest(include_unit)
393405

406+
def is_valid_start(self) -> bool:
407+
return self >= Size(1, Unit.MiB, self.sector_size)
408+
394409
def align(self) -> Size:
395410
align_norm = Size(1, Unit.MiB, self.sector_size)._normalize()
396411
src_norm = self._normalize()

0 commit comments

Comments
 (0)