From 35f1e44087ae17e9fd8a77646adaf37046a5c8f0 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:09:58 +0100 Subject: [PATCH 01/17] Fix Schema to require a type in partition-table definition --- bootstrapvz/base/manifest-schema.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrapvz/base/manifest-schema.yml b/bootstrapvz/base/manifest-schema.yml index bf3bd899c..1e6f7a932 100644 --- a/bootstrapvz/base/manifest-schema.yml +++ b/bootstrapvz/base/manifest-schema.yml @@ -153,7 +153,7 @@ definitions: properties: root: {$ref: '#/definitions/partition'} type: {enum: [none]} - required: [root] + required: [type, root] additionalProperties: false partition: type: object @@ -178,7 +178,7 @@ definitions: size: {$ref: '#/definitions/bytes'} required: [size] type: {enum: [msdos, gpt]} - required: [root] + required: [type, root] additionalProperties: false path: type: string From e2606acbdc2d4c34247ce4bead02baea60f5c65b Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:10:37 +0100 Subject: [PATCH 02/17] Modify Schema to enable mountopts --- bootstrapvz/base/manifest-schema.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bootstrapvz/base/manifest-schema.yml b/bootstrapvz/base/manifest-schema.yml index 1e6f7a932..4fcd09eb0 100644 --- a/bootstrapvz/base/manifest-schema.yml +++ b/bootstrapvz/base/manifest-schema.yml @@ -164,6 +164,10 @@ definitions: items: {type: string} minItems: 1 type: array + mountopts: + items: {type: string} + minItems: 1 + type: array size: {$ref: '#/definitions/bytes'} required: [size, filesystem] additionalProperties: false From 0a5a3e153bb48885cb9c27aecb69c4dde09efdaf Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:11:38 +0100 Subject: [PATCH 03/17] Add pattern to enable definition of additional partitions --- bootstrapvz/base/manifest-schema.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bootstrapvz/base/manifest-schema.yml b/bootstrapvz/base/manifest-schema.yml index 4fcd09eb0..b056548be 100644 --- a/bootstrapvz/base/manifest-schema.yml +++ b/bootstrapvz/base/manifest-schema.yml @@ -173,6 +173,8 @@ definitions: additionalProperties: false partition_table: type: object + patternProperties: + ^(?!type|boot|root|swap).*: {$ref: '#/definitions/partition'} properties: boot: {$ref: '#/definitions/partition'} root: {$ref: '#/definitions/partition'} From 87707486cd157c7aa32699ea79468a8e5e301832 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:03:02 +0100 Subject: [PATCH 04/17] Add mountopts to classes and methods --- bootstrapvz/base/fs/partitionmaps/gpt.py | 4 ++-- bootstrapvz/base/fs/partitionmaps/msdos.py | 4 ++-- bootstrapvz/base/fs/partitions/abstract.py | 11 +++++++++-- bootstrapvz/base/fs/partitions/base.py | 4 ++-- bootstrapvz/base/fs/partitions/gpt.py | 4 ++-- bootstrapvz/base/fs/partitions/gpt_swap.py | 2 +- bootstrapvz/base/fs/partitions/msdos.py | 11 ++++++++++- bootstrapvz/base/fs/partitions/msdos_swap.py | 2 +- bootstrapvz/base/fs/partitions/unformatted.py | 2 +- bootstrapvz/common/tasks/filesystem.py | 5 ++++- 10 files changed, 34 insertions(+), 15 deletions(-) diff --git a/bootstrapvz/base/fs/partitionmaps/gpt.py b/bootstrapvz/base/fs/partitionmaps/gpt.py index c51571561..1243a3297 100644 --- a/bootstrapvz/base/fs/partitionmaps/gpt.py +++ b/bootstrapvz/base/fs/partitionmaps/gpt.py @@ -41,7 +41,7 @@ def last_partition(): if 'boot' in data: self.boot = GPTPartition(Sectors(data['boot']['size'], sector_size), data['boot']['filesystem'], data['boot'].get('format_command', None), - 'boot', last_partition()) + data['boot'].get('mountopts', None), 'boot', last_partition()) if self.boot.previous is not None: # No need to pad if this is the first partition self.boot.pad_start += partition_gap @@ -57,7 +57,7 @@ def last_partition(): self.root = GPTPartition(Sectors(data['root']['size'], sector_size), data['root']['filesystem'], data['root'].get('format_command', None), - 'root', last_partition()) + data['root'].get('mountopts', None), 'root', last_partition()) if self.root.previous is not None: self.root.pad_start += partition_gap self.root.size -= partition_gap diff --git a/bootstrapvz/base/fs/partitionmaps/msdos.py b/bootstrapvz/base/fs/partitionmaps/msdos.py index 22e53fd8a..74f88fa43 100644 --- a/bootstrapvz/base/fs/partitionmaps/msdos.py +++ b/bootstrapvz/base/fs/partitionmaps/msdos.py @@ -28,7 +28,7 @@ def last_partition(): if 'boot' in data: self.boot = MSDOSPartition(Sectors(data['boot']['size'], sector_size), data['boot']['filesystem'], data['boot'].get('format_command', None), - last_partition()) + data['boot'].get('mountopts', None), 'boot', last_partition()) self.partitions.append(self.boot) # Offset all partitions by 1 sector. @@ -46,7 +46,7 @@ def last_partition(): self.root = MSDOSPartition(Sectors(data['root']['size'], sector_size), data['root']['filesystem'], data['root'].get('format_command', None), - last_partition()) + data['root'].get('mountopts', None), 'root', last_partition()) if self.root.previous is not None: self.root.pad_start += partition_gap self.root.size -= partition_gap diff --git a/bootstrapvz/base/fs/partitions/abstract.py b/bootstrapvz/base/fs/partitions/abstract.py index d2f18cc35..cbbad80d7 100644 --- a/bootstrapvz/base/fs/partitions/abstract.py +++ b/bootstrapvz/base/fs/partitions/abstract.py @@ -19,7 +19,7 @@ class AbstractPartition(FSMProxy): {'name': 'unmount', 'src': 'mounted', 'dst': 'formatted'}, ] - def __init__(self, size, filesystem, format_command): + def __init__(self, size, filesystem, format_command, mountopts): """ :param Bytes size: Size of the partition :param str filesystem: Filesystem the partition should be formatted with @@ -28,6 +28,8 @@ def __init__(self, size, filesystem, format_command): self.size = size self.filesystem = filesystem self.format_command = format_command + # List of mount options + self.mountopts = mountopts # Initialize the start & end padding to 0 sectors, may be changed later self.pad_start = Sectors(0, size.sector_size) self.pad_end = Sectors(0, size.sector_size) @@ -80,7 +82,12 @@ def _before_format(self, e): def _before_mount(self, e): """Mount the partition """ - log_check_call(['mount', '--types', self.filesystem, self.device_path, e.destination]) + if self.mountopts is None: + mount_command = ['mount', '--types', self.filesystem, self.device_path, e.destination] + else: + mount_command = ['mount', '--options', ",".join(self.mountopts), '--types', self.filesystem, self.device_path, e.destination] + # Mount the partition + log_check_call(mount_command) self.mount_dir = e.destination def _after_mount(self, e): diff --git a/bootstrapvz/base/fs/partitions/base.py b/bootstrapvz/base/fs/partitions/base.py index 00d006368..76c8f3bcd 100644 --- a/bootstrapvz/base/fs/partitions/base.py +++ b/bootstrapvz/base/fs/partitions/base.py @@ -20,7 +20,7 @@ class BasePartition(AbstractPartition): {'name': 'unmap', 'src': 'mapped', 'dst': 'unmapped'}, ] - def __init__(self, size, filesystem, format_command, previous): + def __init__(self, size, filesystem, format_command, mountopts, previous): """ :param Bytes size: Size of the partition :param str filesystem: Filesystem the partition should be formatted with @@ -34,7 +34,7 @@ def __init__(self, size, filesystem, format_command, previous): self.flags = [] # Path to symlink in /dev/disk/by-uuid (manually maintained by this class) self.disk_by_uuid_path = None - super(BasePartition, self).__init__(size, filesystem, format_command) + super(BasePartition, self).__init__(size, filesystem, format_command, mountopts) def create(self, volume): """Creates the partition diff --git a/bootstrapvz/base/fs/partitions/gpt.py b/bootstrapvz/base/fs/partitions/gpt.py index c8b1f31a7..aa77b8ae4 100644 --- a/bootstrapvz/base/fs/partitions/gpt.py +++ b/bootstrapvz/base/fs/partitions/gpt.py @@ -6,7 +6,7 @@ class GPTPartition(BasePartition): """Represents a GPT partition """ - def __init__(self, size, filesystem, format_command, name, previous): + def __init__(self, size, filesystem, format_command, mountopts, name, previous): """ :param Bytes size: Size of the partition :param str filesystem: Filesystem the partition should be formatted with @@ -15,7 +15,7 @@ def __init__(self, size, filesystem, format_command, name, previous): :param BasePartition previous: The partition that preceeds this one """ self.name = name - super(GPTPartition, self).__init__(size, filesystem, format_command, previous) + super(GPTPartition, self).__init__(size, filesystem, format_command, mountopts, previous) def _before_create(self, e): # Create the partition and then set the name of the partition afterwards diff --git a/bootstrapvz/base/fs/partitions/gpt_swap.py b/bootstrapvz/base/fs/partitions/gpt_swap.py index 3dd2c5319..c7f7c28ed 100644 --- a/bootstrapvz/base/fs/partitions/gpt_swap.py +++ b/bootstrapvz/base/fs/partitions/gpt_swap.py @@ -11,7 +11,7 @@ def __init__(self, size, previous): :param Bytes size: Size of the partition :param BasePartition previous: The partition that preceeds this one """ - super(GPTSwapPartition, self).__init__(size, 'swap', None, 'swap', previous) + super(GPTSwapPartition, self).__init__(size, 'swap', None, None, 'swap', previous) def _before_format(self, e): log_check_call(['mkswap', self.device_path]) diff --git a/bootstrapvz/base/fs/partitions/msdos.py b/bootstrapvz/base/fs/partitions/msdos.py index ad1dd6d7f..90c0bf9f6 100644 --- a/bootstrapvz/base/fs/partitions/msdos.py +++ b/bootstrapvz/base/fs/partitions/msdos.py @@ -4,4 +4,13 @@ class MSDOSPartition(BasePartition): """Represents an MS-DOS partition """ - pass + def __init__(self, size, filesystem, format_command, mountopts, name, previous): + """ + :param Bytes size: Size of the partition + :param str filesystem: Filesystem the partition should be formatted with + :param list format_command: Optional format command, valid variables are fs, device_path and size + :param str name: The name of the partition + :param BasePartition previous: The partition that preceeds this one + """ + self.name = name + super(MSDOSPartition, self).__init__(size, filesystem, format_command, mountopts, previous) diff --git a/bootstrapvz/base/fs/partitions/msdos_swap.py b/bootstrapvz/base/fs/partitions/msdos_swap.py index 24c40d221..48afcfc37 100644 --- a/bootstrapvz/base/fs/partitions/msdos_swap.py +++ b/bootstrapvz/base/fs/partitions/msdos_swap.py @@ -11,7 +11,7 @@ def __init__(self, size, previous): :param Bytes size: Size of the partition :param BasePartition previous: The partition that preceeds this one """ - super(MSDOSSwapPartition, self).__init__(size, 'swap', None, previous) + super(MSDOSSwapPartition, self).__init__(size, 'swap', None, None, 'swap', previous) def _before_format(self, e): log_check_call(['mkswap', self.device_path]) diff --git a/bootstrapvz/base/fs/partitions/unformatted.py b/bootstrapvz/base/fs/partitions/unformatted.py index 73af32d1e..b71be9192 100644 --- a/bootstrapvz/base/fs/partitions/unformatted.py +++ b/bootstrapvz/base/fs/partitions/unformatted.py @@ -17,4 +17,4 @@ def __init__(self, size, previous): :param Bytes size: Size of the partition :param BasePartition previous: The partition that preceeds this one """ - super(UnformattedPartition, self).__init__(size, None, None, previous) + super(UnformattedPartition, self).__init__(size, None, None, None, previous) diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 014554f79..3e4c8215b 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -187,7 +187,10 @@ def run(cls, info): fstab_lines = [] for mount_point in mount_points: partition = mount_point['partition'] - mount_opts = ['defaults'] + if partition.mountopts is None: + mount_opts = ['defaults'] + else: + mount_opts = partition.mountopts fstab_lines.append('UUID={uuid} {mountpoint} {filesystem} {mount_opts} {dump} {pass_num}' .format(uuid=partition.get_uuid(), mountpoint=mount_point['path'], From 167a0af4ce73fcddd77f49db6e9f565f5af10415 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:03:44 +0100 Subject: [PATCH 05/17] Add handling for addtitional partitions --- bootstrapvz/base/fs/partitionmaps/gpt.py | 11 +++++++ bootstrapvz/base/fs/partitionmaps/msdos.py | 8 +++++ bootstrapvz/common/task_groups.py | 1 + bootstrapvz/common/tasks/filesystem.py | 38 +++++++++++++++++++++- 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/bootstrapvz/base/fs/partitionmaps/gpt.py b/bootstrapvz/base/fs/partitionmaps/gpt.py index 1243a3297..a41d0cc2b 100644 --- a/bootstrapvz/base/fs/partitionmaps/gpt.py +++ b/bootstrapvz/base/fs/partitionmaps/gpt.py @@ -63,6 +63,17 @@ def last_partition(): 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') diff --git a/bootstrapvz/base/fs/partitionmaps/msdos.py b/bootstrapvz/base/fs/partitionmaps/msdos.py index 74f88fa43..465f54658 100644 --- a/bootstrapvz/base/fs/partitionmaps/msdos.py +++ b/bootstrapvz/base/fs/partitionmaps/msdos.py @@ -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 @@ def last_partition(): 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') diff --git a/bootstrapvz/common/task_groups.py b/bootstrapvz/common/task_groups.py index e087d3373..89709dc5f 100644 --- a/bootstrapvz/common/task_groups.py +++ b/bootstrapvz/common/task_groups.py @@ -74,6 +74,7 @@ def get_base_group(manifest): mounting_group = [filesystem.CreateMountDir, filesystem.MountRoot, + filesystem.MountAdditional, filesystem.MountSpecials, filesystem.CopyMountTable, filesystem.RemoveMountTable, diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 3e4c8215b..6e342beaa 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -99,6 +99,33 @@ def run(cls, info): 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 @@ def run(cls, info): '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'] From d462c5ab8fa1270d4fd54ea1230bd87b51ca06ed Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:28:13 +0100 Subject: [PATCH 06/17] Fix NoPartitions class as AbstractPartition got mount_opts as additional parameter --- bootstrapvz/base/fs/partitionmaps/none.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrapvz/base/fs/partitionmaps/none.py b/bootstrapvz/base/fs/partitionmaps/none.py index e73495ba9..18346bc34 100644 --- a/bootstrapvz/base/fs/partitionmaps/none.py +++ b/bootstrapvz/base/fs/partitionmaps/none.py @@ -17,7 +17,7 @@ def __init__(self, data, sector_size, bootloader): # In the NoPartitions partitions map we only have a single 'partition' self.root = SinglePartition(Sectors(data['root']['size'], sector_size), - data['root']['filesystem'], data['root'].get('format_command', None)) + data['root']['filesystem'], data['root'].get('format_command', None), data['root'].get('mount_opts', None)) self.partitions = [self.root] def is_blocking(self): From b6bd3c7b1213cacd4caaef3d585fe9bc70c1b8ba Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:42:52 +0100 Subject: [PATCH 07/17] Add description for mount_opts with examples --- manifests/README.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/manifests/README.rst b/manifests/README.rst index d4dc26079..69064c46a 100644 --- a/manifests/README.rst +++ b/manifests/README.rst @@ -302,6 +302,15 @@ boot, root and swap. - ``{fs}``: The filesystem of the partition. - ``{device_path}``: The device path of the partition. - ``{size}``: The size of the partition. + - ``mount_opts``: Options to mount the partition with. This optional + setting overwrites the default option list bootstrap-vz would + normally use to mount the partiton (defaults). The List is specified + as a string array where each option/argument is an item in that array. + ``optional`` Here some examples: + - ``nodev`` + - ``nosuid`` + - ``noexec`` + - ``journal_ioprio=3`` The default command used by boostrap-vz is ``['mkfs.{fs}', '{device_path}']``. From 22d3d3e235280ec403c9c1ae61afb43675a422c6 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 16:45:40 +0100 Subject: [PATCH 08/17] Add new example for kvm virtio stretch version with granular partitions --- .../kvm/stretch-virtio-partitions.yml | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 manifests/examples/kvm/stretch-virtio-partitions.yml diff --git a/manifests/examples/kvm/stretch-virtio-partitions.yml b/manifests/examples/kvm/stretch-virtio-partitions.yml new file mode 100644 index 000000000..c5848d4ba --- /dev/null +++ b/manifests/examples/kvm/stretch-virtio-partitions.yml @@ -0,0 +1,41 @@ +--- +name: debian-{system.release}-{system.architecture}-{%Y}{%m}{%d} +provider: + name: kvm + virtio_modules: + - virtio_pci + - virtio_blk +bootstrapper: + workspace: /target +system: + release: jessie + architecture: amd64 + bootloader: grub + charmap: UTF-8 + locale: en_US + timezone: UTC +volume: + backing: raw + partitions: + type: gpt + root: + filesystem: ext4 + size: 8GiB + tmp: + mountopts: + - nodev + - noexec + - nosuid + - journal_ioprio=3 + filesystem: ext4 + size: 1GiB + var: + filesystem: ext4 + size: 1GiB + var/tmp: + filesystem: ext4 + size: 1GiB + +plugins: + root_password: + password: test From 02972e6b2775227f58ea4d187e26ab831d99a8b4 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 18:51:43 +0100 Subject: [PATCH 09/17] Fix to comply to code style --- bootstrapvz/base/fs/partitionmaps/gpt.py | 4 ++-- bootstrapvz/base/fs/partitionmaps/msdos.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bootstrapvz/base/fs/partitionmaps/gpt.py b/bootstrapvz/base/fs/partitionmaps/gpt.py index a41d0cc2b..1dbd943db 100644 --- a/bootstrapvz/base/fs/partitionmaps/gpt.py +++ b/bootstrapvz/base/fs/partitionmaps/gpt.py @@ -67,8 +67,8 @@ def last_partition(): 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()) + 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) diff --git a/bootstrapvz/base/fs/partitionmaps/msdos.py b/bootstrapvz/base/fs/partitionmaps/msdos.py index 465f54658..ebc04cc2e 100644 --- a/bootstrapvz/base/fs/partitionmaps/msdos.py +++ b/bootstrapvz/base/fs/partitionmaps/msdos.py @@ -54,8 +54,8 @@ def last_partition(): 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... + # 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") From 519ff5e60511dbf2763641325092615ff490599d Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 10 Dec 2016 20:09:35 +0100 Subject: [PATCH 10/17] Remove debug output --- bootstrapvz/common/tasks/filesystem.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 6e342beaa..767d73435 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -117,7 +117,6 @@ def run(cls, info): 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: From 3b0b8f2aeb958300fd0612f1a837db89c415df12 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Mon, 12 Dec 2016 20:01:39 +0100 Subject: [PATCH 11/17] switch to stretch release and add boot and swap parttition --- manifests/examples/kvm/stretch-virtio-partitions.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manifests/examples/kvm/stretch-virtio-partitions.yml b/manifests/examples/kvm/stretch-virtio-partitions.yml index c5848d4ba..49330cf98 100644 --- a/manifests/examples/kvm/stretch-virtio-partitions.yml +++ b/manifests/examples/kvm/stretch-virtio-partitions.yml @@ -8,7 +8,7 @@ provider: bootstrapper: workspace: /target system: - release: jessie + release: stretch architecture: amd64 bootloader: grub charmap: UTF-8 @@ -18,6 +18,11 @@ volume: backing: raw partitions: type: gpt + boot: + filesystem: ext2 + size: 1GiB + swap: + size: 128MiB root: filesystem: ext4 size: 8GiB From ff4918f1e08e04222b738c7959822d0a1779954a Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Tue, 31 Jan 2017 21:45:40 +0100 Subject: [PATCH 12/17] sort out UnformattedPartitions nicer --- bootstrapvz/common/tasks/filesystem.py | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 767d73435..ae490975a 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -109,15 +109,14 @@ 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): - partition = getattr(p_map, partition_name) + partitions = p_map.partitions; + is_additional = lambda partition: ( + not isinstance(partition, UnformattedPartition) + and partition.name not in ["boot", "swap", "root"] + ) + name_length = lambda partition: len(partition.name) + for partition in sorted(filter(is_additional, partitions), key=name_length): + 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) @@ -193,6 +192,7 @@ def run(cls, info): import os.path from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition p_map = info.volume.partition_map + partitions = p_map.partitions; mount_points = [{'path': '/', 'partition': p_map.root, 'dump': '1', @@ -210,15 +210,18 @@ def run(cls, info): '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', - }) + + is_additional = lambda partition: ( + not isinstance(partition, UnformattedPartition) + and partition.name not in ["boot", "swap", "root", "type"] + ) + name_length = lambda partition: len(partition.name) + for partition in sorted(filter(is_additional, partitions), key=name_length): + 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'] From c088e1afac0685fd5468f2d35c741788ea89f8df Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Tue, 31 Jan 2017 21:45:59 +0100 Subject: [PATCH 13/17] cleanup partitioning in schema --- bootstrapvz/base/manifest-schema.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bootstrapvz/base/manifest-schema.yml b/bootstrapvz/base/manifest-schema.yml index b056548be..170cc2ba0 100644 --- a/bootstrapvz/base/manifest-schema.yml +++ b/bootstrapvz/base/manifest-schema.yml @@ -174,10 +174,8 @@ definitions: partition_table: type: object patternProperties: - ^(?!type|boot|root|swap).*: {$ref: '#/definitions/partition'} + ^(?!type|swap).*: {$ref: '#/definitions/partition'} properties: - boot: {$ref: '#/definitions/partition'} - root: {$ref: '#/definitions/partition'} swap: type: object properties: From 029fc221a1b86eebb754dff989d80cc867a7ce6d Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Tue, 31 Jan 2017 21:54:10 +0100 Subject: [PATCH 14/17] add additional partitions to docs --- manifests/README.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/manifests/README.rst b/manifests/README.rst index 69064c46a..ce3973c44 100644 --- a/manifests/README.rst +++ b/manifests/README.rst @@ -302,7 +302,7 @@ boot, root and swap. - ``{fs}``: The filesystem of the partition. - ``{device_path}``: The device path of the partition. - ``{size}``: The size of the partition. - - ``mount_opts``: Options to mount the partition with. This optional + - ``{mount_opts}``: Options to mount the partition with. This optional setting overwrites the default option list bootstrap-vz would normally use to mount the partiton (defaults). The List is specified as a string array where each option/argument is an item in that array. @@ -315,13 +315,16 @@ boot, root and swap. The default command used by boostrap-vz is ``['mkfs.{fs}', '{device_path}']``. - - ``boot``: Configuration of the boot partition. The three - settings equal those of the root partition. + - ``boot``: Configuration of the boot partition. All settings equal + those of the root partition. ``optional`` - ``swap``: Configuration of the swap partition. Since the swap partition has its own filesystem you can only specify the size for this partition. ``optional`` + - ``additional_path``: Configuration of additional partitions. (e.g. /var/tmp) + All settings equal those of the root partition. + Example: From 5a4719c236a4870fe81b00dc2ee2d4516daec485 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Wed, 1 Feb 2017 18:38:37 +0100 Subject: [PATCH 15/17] remove semicolons.. :-/ --- bootstrapvz/common/tasks/filesystem.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index ae490975a..9c464593f 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -109,7 +109,7 @@ def run(cls, info): import os from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition p_map = info.volume.partition_map - partitions = p_map.partitions; + partitions = p_map.partitions is_additional = lambda partition: ( not isinstance(partition, UnformattedPartition) and partition.name not in ["boot", "swap", "root"] @@ -192,7 +192,7 @@ def run(cls, info): import os.path from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition p_map = info.volume.partition_map - partitions = p_map.partitions; + partitions = p_map.partitions mount_points = [{'path': '/', 'partition': p_map.root, 'dump': '1', From 64e1020e6ded0010caded171215e907a778b6ff4 Mon Sep 17 00:00:00 2001 From: Stefan Date: Wed, 1 Feb 2017 20:16:23 +0100 Subject: [PATCH 16/17] fix pep8 --- bootstrapvz/common/tasks/filesystem.py | 28 +++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 9c464593f..4230a5ab1 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -108,14 +108,16 @@ class MountAdditional(Task): def run(cls, info): import os from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition + + def is_additional(partition): + return (not isinstance(partition, UnformattedPartition) and + partition.name not in ["boot", "swap", "root"]) + p_map = info.volume.partition_map partitions = p_map.partitions - is_additional = lambda partition: ( - not isinstance(partition, UnformattedPartition) - and partition.name not in ["boot", "swap", "root"] - ) - name_length = lambda partition: len(partition.name) - for partition in sorted(filter(is_additional, partitions), key=name_length): + for partition in sorted( + filter(is_additional, partitions), + key=lambda partition: len(partition.name)): partition = getattr(p_map, partition.name) os.makedirs(os.path.join(info.root, partition.name)) if partition.mountopts is None: @@ -191,6 +193,11 @@ class FStab(Task): def run(cls, info): import os.path from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition + + def is_additional(partition): + return (not isinstance(partition, UnformattedPartition) and + partition.name not in ["boot", "swap", "root", "type"]) + p_map = info.volume.partition_map partitions = p_map.partitions mount_points = [{'path': '/', @@ -211,12 +218,9 @@ def run(cls, info): 'pass_num': '0', }) - is_additional = lambda partition: ( - not isinstance(partition, UnformattedPartition) - and partition.name not in ["boot", "swap", "root", "type"] - ) - name_length = lambda partition: len(partition.name) - for partition in sorted(filter(is_additional, partitions), key=name_length): + for partition in sorted( + filter(is_additional, partitions), + key=lambda partition: len(partition.name)): mount_points.append({'path': "/" + partition.name, 'partition': getattr(p_map, partition.name), 'dump': '1', From 4eb90a544e7f488b1d6c0679c227d7ed2ccfe323 Mon Sep 17 00:00:00 2001 From: Michael Gerlach Date: Sat, 4 Feb 2017 16:15:24 +0100 Subject: [PATCH 17/17] type is never going to be a partition --- bootstrapvz/common/tasks/filesystem.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 4230a5ab1..4fb73931a 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -196,7 +196,7 @@ def run(cls, info): def is_additional(partition): return (not isinstance(partition, UnformattedPartition) and - partition.name not in ["boot", "swap", "root", "type"]) + partition.name not in ["boot", "swap", "root"]) p_map = info.volume.partition_map partitions = p_map.partitions