173
173
def get_partition_number(self):
174
174
"""Return the partition number in the table."""
176
from maasserver.models.partitiontable import GPT_REQUIRED_SIZE
175
177
# Sort manually instead of with `order_by`, this will prevent django
176
178
# from making a query if the partitions are already cached.
177
179
partitions_in_table = self.partition_table.partitions.all()
178
180
partitions_in_table = sorted(partitions_in_table, key=attrgetter('id'))
179
181
idx = partitions_in_table.index(self)
180
182
if self.partition_table.table_type == PARTITION_TABLE_TYPE.GPT:
181
# ppc64el machines get part1 skipped when this partition is on
182
# the boot disk. This is because the prep partition is part1 and
183
# is added when the preseed for storage is generated.
183
# In some instances the first partition is skipped because it
184
# is used by the machine architecture for a specific reason.
185
# * ppc64el - reserved for prep partition
186
# * amd64 (disk >= 2TiB) - reserved for bios_grub partition
184
187
node = self.get_node()
185
188
arch, _ = node.split_arch()
186
189
boot_disk = node.get_boot_disk()
190
bios_boot_method = node.get_bios_boot_method()
187
191
if (arch == "ppc64el" and
188
192
self.partition_table.block_device.id == boot_disk.id):
194
elif (arch == "amd64" and
195
self.partition_table.block_device.id == boot_disk.id and
196
bios_boot_method != "uefi" and
197
boot_disk.size >= GPT_REQUIRED_SIZE):
192
201
elif self.partition_table.table_type == PARTITION_TABLE_TYPE.MBR: