Adjust partition alignment for GPT and curtin sgdisk

Curtin uses sgdisk to create partitions.  To avoid sgdisk
fixing alignment issues we ensure that all partitions are
1M aligned.

GPT partitions also require space at the end, reserve the
same number of sectors (1K, 2048 512b sectors) at the
start and end of the disk.

Signed-off-by: Ryan Harper <ryan.harper@canonical.com>
This commit is contained in:
Ryan Harper 2015-09-01 17:01:07 -05:00
parent 7ff3f549c2
commit fbb8eb09fb
2 changed files with 25 additions and 8 deletions

View File

@ -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,6 +96,7 @@ class FilesystemController(ControllerPolicy):
if current_disk.parttype == 'gpt' and \
len(current_disk.disk.partitions) == 0:
log.debug('Adding grub_bios gpt partition first')
size_added = \
current_disk.add_partition(partnum=1,
size=BIOS_GRUB_SIZE_BYTES,
fstype=None,
@ -104,7 +104,10 @@ class FilesystemController(ControllerPolicy):
# 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"]:

View File

@ -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: