Add handling for addtitional partitions

This commit is contained in:
Michael Gerlach 2016-12-10 16:03:44 +01:00
parent 87707486cd
commit 167a0af4ce
4 changed files with 57 additions and 1 deletions

View file

@ -63,6 +63,17 @@ class GPTPartitionMap(AbstractPartitionMap):
self.root.size -= partition_gap
self.partitions.append(self.root)
# Create all additional partitions
for partition in data:
if partition not in ["boot", "swap", "root", "type"] and not None:
part_tmp = GPTPartition(Sectors(data[partition]['size'], sector_size),
data[partition]['filesystem'], data[partition].get('format_command', None),
data[partition].get('mountopts', None), partition, last_partition())
part_tmp.pad_start += partition_gap
part_tmp.size -= partition_gap
setattr(self, partition, part_tmp)
self.partitions.append(part_tmp)
if hasattr(self, 'grub_boot'):
# Mark the grub partition as a bios_grub partition
self.grub_boot.flags.append('bios_grub')

View file

@ -1,4 +1,5 @@
from abstract import AbstractPartitionMap
from ..exceptions import PartitionError
from ..partitions.msdos import MSDOSPartition
from ..partitions.msdos_swap import MSDOSSwapPartition
from bootstrapvz.common.tools import log_check_call
@ -52,6 +53,13 @@ class MSDOSPartitionMap(AbstractPartitionMap):
self.root.size -= partition_gap
self.partitions.append(self.root)
# Raise exception while trying to create additional partitions
# as its hard to calculate the actual size of the extended partition ATM
# And anyhow - we should go with GPT...
for partition in data:
if partition not in ["boot", "swap", "root", "type"]:
raise PartitionError("If you want to have additional partitions please use GPT partition scheme")
# Mark boot as the boot partition, or root, if boot does not exist
getattr(self, 'boot', self.root).flags.append('boot')

View file

@ -74,6 +74,7 @@ boot_partition_group = [filesystem.CreateBootMountDir,
mounting_group = [filesystem.CreateMountDir,
filesystem.MountRoot,
filesystem.MountAdditional,
filesystem.MountSpecials,
filesystem.CopyMountTable,
filesystem.RemoveMountTable,

View file

@ -99,6 +99,33 @@ class MountBoot(Task):
p_map.root.add_mount(p_map.boot, 'boot')
class MountAdditional(Task):
description = 'Mounting additional partitions'
phase = phases.volume_mounting
predecessors = [MountRoot]
@classmethod
def run(cls, info):
import os
from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition
p_map = info.volume.partition_map
partitions = []
# we need to get rid of UnformattedPartition and sort the list of additional partitons in order to mount them correctly
for partition in info.volume.partition_map.partitions:
if isinstance(partition, UnformattedPartition):
continue
if partition.name not in ["boot", "swap", "root"]:
partitions.append(partition.name)
for partition_name in sorted(partitions, key=len, reverse=False):
print partition_name
partition = getattr(p_map, partition_name)
os.makedirs(os.path.join(info.root, partition.name))
if partition.mountopts is None:
p_map.root.add_mount(getattr(p_map, partition.name), partition.name)
else:
p_map.root.add_mount(getattr(p_map, partition.name), partition.name, ['--options'] + partition.mountopts)
class MountSpecials(Task):
description = 'Mounting special block devices'
phase = phases.os_installation
@ -165,6 +192,7 @@ class FStab(Task):
@classmethod
def run(cls, info):
import os.path
from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition
p_map = info.volume.partition_map
mount_points = [{'path': '/',
'partition': p_map.root,
@ -183,7 +211,15 @@ class FStab(Task):
'dump': '1',
'pass_num': '0',
})
for partition in info.volume.partition_map.partitions:
if isinstance(partition, UnformattedPartition):
continue
if partition.name not in ["boot", "swap", "root", "type"]:
mount_points.append({'path': "/" + partition.name,
'partition': getattr(p_map, partition.name),
'dump': '1',
'pass_num': '2',
})
fstab_lines = []
for mount_point in mount_points:
partition = mount_point['partition']