def add_partition(self, size=None, bootable=False, uuid=None): """Adds a partition to this partition table, returns the added partition. If size is omitted, the partition will extend to the end of the device. All partition sizes will be aligned down to PARTITION_ALIGNMENT_SIZE. """ if size is None: size = self.get_available_size() if self.table_type == PARTITION_TABLE_TYPE.MBR: size = min( size, Partition._get_mbr_max_for_block_device(self.block_device)) size = round_size_to_nearest_block(size, PARTITION_ALIGNMENT_SIZE, False) return Partition.objects.create(partition_table=self, size=size, uuid=uuid, bootable=bootable)
def create_basic_layout(self, boot_size=None): """Create the basic layout that is similar for all layout types. :return: The created root partition. """ # Circular imports. from maasserver.models.filesystem import Filesystem from maasserver.models.partitiontable import PartitionTable boot_partition_table = PartitionTable.objects.create( block_device=self.boot_disk) bios_boot_method = self.node.get_bios_boot_method() node_arch, _ = self.node.split_arch() if (boot_partition_table.table_type == PARTITION_TABLE_TYPE.GPT and bios_boot_method == "uefi" and node_arch != "ppc64el"): # Add EFI partition only if booting UEFI and not a ppc64el # architecture. efi_partition = boot_partition_table.add_partition( size=EFI_PARTITION_SIZE, bootable=True) Filesystem.objects.create( partition=efi_partition, fstype=FILESYSTEM_TYPE.FAT32, label="efi", mount_point="/boot/efi") elif (bios_boot_method != "uefi" and node_arch == "arm64" and boot_size is None): # Add boot partition only if booting an arm64 architecture and # not UEFI and boot_size is None. boot_partition = boot_partition_table.add_partition( size=MIN_BOOT_PARTITION_SIZE, bootable=True) Filesystem.objects.create( partition=boot_partition, fstype=FILESYSTEM_TYPE.EXT4, label="boot", mount_point="/boot") if boot_size is None: boot_size = self.get_boot_size() if boot_size > 0: boot_partition = boot_partition_table.add_partition( size=boot_size, bootable=True) Filesystem.objects.create( partition=boot_partition, fstype=FILESYSTEM_TYPE.EXT4, label="boot", mount_point="/boot") root_device = self.get_root_device() root_size = self.get_root_size() if root_device is None or root_device == self.boot_disk: # Fix the maximum root_size for MBR. max_mbr_size = Partition._get_mbr_max_for_block_device( self.boot_disk) if (boot_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and root_size is not None and root_size > max_mbr_size): root_size = max_mbr_size root_partition = boot_partition_table.add_partition( size=root_size) return root_partition, boot_partition_table else: root_partition_table = PartitionTable.objects.create( block_device=root_device) # Fix the maximum root_size for MBR. max_mbr_size = Partition._get_mbr_max_for_block_device( root_device) if (root_partition_table.table_type == PARTITION_TABLE_TYPE.MBR and root_size is not None and root_size > max_mbr_size): root_size = max_mbr_size root_partition = root_partition_table.add_partition( size=root_size) return root_partition, root_partition_table