diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 8b26dba6..b4a8f093 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -16,7 +16,6 @@ import logging from subiquity.controller import ControllerPolicy from subiquity.models import FilesystemModel -from subiquity.models.blockdev import FIRST_PARTITION_OFFSET from subiquity.ui.views import (DiskPartitionView, AddPartitionView, FilesystemView) from subiquity.ui.dummy import DummyView @@ -97,14 +96,18 @@ class FilesystemController(ControllerPolicy): if current_disk.parttype == 'gpt' and \ len(current_disk.disk.partitions) == 0: log.debug('Adding grub_bios gpt partition first') - current_disk.add_partition(partnum=1, - size=BIOS_GRUB_SIZE_BYTES, - fstype=None, - flag='bios_grub') + size_added = \ + current_disk.add_partition(partnum=1, + size=BIOS_GRUB_SIZE_BYTES, + fstype=None, + flag='bios_grub') # adjust downward the partition size to accommodate # the offset and bios/grub partition - spec['bytes'] -= FIRST_PARTITION_OFFSET + BIOS_GRUB_SIZE_BYTES + log.debug("Adjusting request down:" + + "{} - {} = {}".format(spec['bytes'], size_added, + spec['bytes'] - size_added)) + spec['bytes'] -= size_added spec['partnum'] = 2 if spec["fstype"] in ["swap"]: diff --git a/subiquity/models/blockdev.py b/subiquity/models/blockdev.py index 4fc14e29..fad466e0 100644 --- a/subiquity/models/blockdev.py +++ b/subiquity/models/blockdev.py @@ -29,6 +29,7 @@ from .actions import ( log = logging.getLogger("subiquity.filesystem.blockdev") FIRST_PARTITION_OFFSET = 1 << 20 # 1K offset/aligned +GPT_END_RESERVE = 1 << 20 # save room at the end for GPT # TODO: Bcachepart class @@ -215,12 +216,23 @@ class Blockdev(): if fstype in ["swap"]: fstype = "linux-swap(v1)" + # round up length by 1M + def _align_up(size, block_size=1 << 30): + return size + (block_size - (size % block_size)) + if len(self.disk.partitions) == 0: offset = FIRST_PARTITION_OFFSET else: offset = 0 - log.debug('requested start: {} length: {}'.format(offset, size)) + log.debug('Aligning start and length on 1M boundaries') + new_size = _align_up(size + offset) + if new_size > self.freespace - GPT_END_RESERVE: + new_size = self.freespace - GPT_END_RESERVE + log.debug('Old size: {} New size: {}'.format(size, new_size)) + + log.debug('requested start: {} length: {}'.format(offset, + new_size - offset)) valid_flags = [ "boot", "lvm", @@ -232,7 +244,8 @@ class Blockdev(): # create partition and add part_action = PartitionAction(self.baseaction, partnum, - offset, size, flag) + offset, new_size - offset, flag) + log.debug('PartitionAction:\n{}'.format(part_action.get())) self.disk.partitions.update({partnum: part_action}) @@ -250,6 +263,7 @@ class Blockdev(): self._mounts[partpath] = mountpoint log.debug('Partition Added') + return new_size def is_mounted(self): with open('/proc/mounts') as pm: