|
13 | 13 |
|
14 | 14 | from ..exceptions import DiskError, SysCallError |
15 | 15 | from ..general import SysCommand |
| 16 | +from ..hardware import SysInfo |
16 | 17 | from ..output import debug |
17 | 18 | from ..storage import storage |
18 | 19 |
|
@@ -148,6 +149,43 @@ def parse_arg(cls, disk_config: _DiskLayoutConfigurationSerialization) -> DiskLa |
148 | 149 | device_modification.partitions = device_partitions |
149 | 150 | device_modifications.append(device_modification) |
150 | 151 |
|
| 152 | + using_gpt = SysInfo.has_uefi() |
| 153 | + |
| 154 | + for dev_mod in device_modifications: |
| 155 | + partitions = sorted(dev_mod.partitions, key=lambda p: p.start) |
| 156 | + |
| 157 | + for i, current_partition in enumerate(partitions[1:], start=1): |
| 158 | + previous_partition = partitions[i - 1] |
| 159 | + if ( |
| 160 | + current_partition.status == ModificationStatus.Create |
| 161 | + and current_partition.start < previous_partition.end |
| 162 | + ): |
| 163 | + raise ValueError('Partitions overlap') |
| 164 | + |
| 165 | + partitions = [ |
| 166 | + part_mod for part_mod in dev_mod.partitions |
| 167 | + if part_mod.status == ModificationStatus.Create |
| 168 | + ] |
| 169 | + |
| 170 | + if not partitions: |
| 171 | + continue |
| 172 | + |
| 173 | + for part in partitions: |
| 174 | + if ( |
| 175 | + part.start != part.start.align() |
| 176 | + or part.length != part.length.align() |
| 177 | + ): |
| 178 | + raise ValueError('Partition is misaligned') |
| 179 | + |
| 180 | + total_size = dev_mod.device.device_info.total_size |
| 181 | + |
| 182 | + if using_gpt: |
| 183 | + if partitions[-1].end > total_size.gpt_end(): |
| 184 | + raise ValueError('Partition overlaps backup GPT header') |
| 185 | + else: |
| 186 | + if partitions[-1].end > total_size.align(): |
| 187 | + raise ValueError('Partition too large for device') |
| 188 | + |
151 | 189 | # Parse LVM configuration from settings |
152 | 190 | if (lvm_arg := disk_config.get('lvm_config', None)) is not None: |
153 | 191 | config.lvm_config = LvmConfiguration.parse_arg(lvm_arg, config) |
|
0 commit comments