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:
parent
7ff3f549c2
commit
fbb8eb09fb
|
@ -16,7 +16,6 @@
|
||||||
import logging
|
import logging
|
||||||
from subiquity.controller import ControllerPolicy
|
from subiquity.controller import ControllerPolicy
|
||||||
from subiquity.models import FilesystemModel
|
from subiquity.models import FilesystemModel
|
||||||
from subiquity.models.blockdev import FIRST_PARTITION_OFFSET
|
|
||||||
from subiquity.ui.views import (DiskPartitionView, AddPartitionView,
|
from subiquity.ui.views import (DiskPartitionView, AddPartitionView,
|
||||||
FilesystemView)
|
FilesystemView)
|
||||||
from subiquity.ui.dummy import DummyView
|
from subiquity.ui.dummy import DummyView
|
||||||
|
@ -97,14 +96,18 @@ class FilesystemController(ControllerPolicy):
|
||||||
if current_disk.parttype == 'gpt' and \
|
if current_disk.parttype == 'gpt' and \
|
||||||
len(current_disk.disk.partitions) == 0:
|
len(current_disk.disk.partitions) == 0:
|
||||||
log.debug('Adding grub_bios gpt partition first')
|
log.debug('Adding grub_bios gpt partition first')
|
||||||
current_disk.add_partition(partnum=1,
|
size_added = \
|
||||||
size=BIOS_GRUB_SIZE_BYTES,
|
current_disk.add_partition(partnum=1,
|
||||||
fstype=None,
|
size=BIOS_GRUB_SIZE_BYTES,
|
||||||
flag='bios_grub')
|
fstype=None,
|
||||||
|
flag='bios_grub')
|
||||||
|
|
||||||
# adjust downward the partition size to accommodate
|
# adjust downward the partition size to accommodate
|
||||||
# the offset and bios/grub partition
|
# 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
|
spec['partnum'] = 2
|
||||||
|
|
||||||
if spec["fstype"] in ["swap"]:
|
if spec["fstype"] in ["swap"]:
|
||||||
|
|
|
@ -29,6 +29,7 @@ from .actions import (
|
||||||
|
|
||||||
log = logging.getLogger("subiquity.filesystem.blockdev")
|
log = logging.getLogger("subiquity.filesystem.blockdev")
|
||||||
FIRST_PARTITION_OFFSET = 1 << 20 # 1K offset/aligned
|
FIRST_PARTITION_OFFSET = 1 << 20 # 1K offset/aligned
|
||||||
|
GPT_END_RESERVE = 1 << 20 # save room at the end for GPT
|
||||||
|
|
||||||
|
|
||||||
# TODO: Bcachepart class
|
# TODO: Bcachepart class
|
||||||
|
@ -215,12 +216,23 @@ class Blockdev():
|
||||||
if fstype in ["swap"]:
|
if fstype in ["swap"]:
|
||||||
fstype = "linux-swap(v1)"
|
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:
|
if len(self.disk.partitions) == 0:
|
||||||
offset = FIRST_PARTITION_OFFSET
|
offset = FIRST_PARTITION_OFFSET
|
||||||
else:
|
else:
|
||||||
offset = 0
|
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 = [
|
valid_flags = [
|
||||||
"boot",
|
"boot",
|
||||||
"lvm",
|
"lvm",
|
||||||
|
@ -232,7 +244,8 @@ class Blockdev():
|
||||||
|
|
||||||
# create partition and add
|
# create partition and add
|
||||||
part_action = PartitionAction(self.baseaction, partnum,
|
part_action = PartitionAction(self.baseaction, partnum,
|
||||||
offset, size, flag)
|
offset, new_size - offset, flag)
|
||||||
|
|
||||||
log.debug('PartitionAction:\n{}'.format(part_action.get()))
|
log.debug('PartitionAction:\n{}'.format(part_action.get()))
|
||||||
|
|
||||||
self.disk.partitions.update({partnum: part_action})
|
self.disk.partitions.update({partnum: part_action})
|
||||||
|
@ -250,6 +263,7 @@ class Blockdev():
|
||||||
self._mounts[partpath] = mountpoint
|
self._mounts[partpath] = mountpoint
|
||||||
|
|
||||||
log.debug('Partition Added')
|
log.debug('Partition Added')
|
||||||
|
return new_size
|
||||||
|
|
||||||
def is_mounted(self):
|
def is_mounted(self):
|
||||||
with open('/proc/mounts') as pm:
|
with open('/proc/mounts') as pm:
|
||||||
|
|
Loading…
Reference in New Issue