From adb0341064b6100265adbb56ee83000e3b35c38a Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 31 Jan 2018 10:56:57 +1100 Subject: [PATCH] Add block-device defaults This moves the block-device default out of the "vm" element and into a selection of other elements. There's "mbr" which retains the status quo. There's an EFI version that has the boot/grub partitions as required. In between there's the GPT only version, which is useful for architectures like power without EFI, but still want possible larger disks using GPT. Change-Id: I4a566a97d073fc0dda0ab2494ac988fe015800a9 --- .../elements/block-device-efi/README.rst | 11 ++++ .../block-device-default.yaml | 30 +++++++++++ .../block-device-efi/element-provides | 1 + .../elements/block-device-gpt/README.rst | 8 +-- .../block-device-ppc64el.yaml | 32 +++++++++++ .../block-device-gpt/element-provides | 1 + .../elements/block-device-mbr/README.rst | 7 +++ .../block-device-default.yaml | 0 .../block-device-ppc64el.yaml | 0 .../block-device-mbr/element-provides | 1 + .../xenial-build-succeeds/element-deps | 1 + .../xenial-build-succeeds/element-deps | 2 + diskimage_builder/elements/vm/element-deps | 1 + diskimage_builder/lib/common-functions | 43 +++++++++++++++ doc/source/user_guide/building_an_image.rst | 54 +++++-------------- 15 files changed, 146 insertions(+), 46 deletions(-) create mode 100644 diskimage_builder/elements/block-device-efi/README.rst create mode 100644 diskimage_builder/elements/block-device-efi/block-device-default.yaml create mode 100644 diskimage_builder/elements/block-device-efi/element-provides create mode 100644 diskimage_builder/elements/block-device-gpt/block-device-ppc64el.yaml create mode 100644 diskimage_builder/elements/block-device-gpt/element-provides create mode 100644 diskimage_builder/elements/block-device-mbr/README.rst rename diskimage_builder/elements/{vm => block-device-mbr}/block-device-default.yaml (100%) rename diskimage_builder/elements/{vm => block-device-mbr}/block-device-ppc64el.yaml (100%) create mode 100644 diskimage_builder/elements/block-device-mbr/element-provides diff --git a/diskimage_builder/elements/block-device-efi/README.rst b/diskimage_builder/elements/block-device-efi/README.rst new file mode 100644 index 00000000..804f713d --- /dev/null +++ b/diskimage_builder/elements/block-device-efi/README.rst @@ -0,0 +1,11 @@ +================ +Block Device EFI +================ + +This provides a block-device configuration for the ``vm`` element to +get a single-partition disk suitable for EFI booting. + +Note on x86 this provides the extra `BIOS boot partition +`__ and a EFI boot +partition for maximum compatability. + diff --git a/diskimage_builder/elements/block-device-efi/block-device-default.yaml b/diskimage_builder/elements/block-device-efi/block-device-default.yaml new file mode 100644 index 00000000..4f79c8b8 --- /dev/null +++ b/diskimage_builder/elements/block-device-efi/block-device-default.yaml @@ -0,0 +1,30 @@ +- local_loop: + name: image0 + +- partitioning: + base: image0 + label: gpt + partitions: + - name: ESP + type: 'EF00' + size: 8MiB + mkfs: + type: vfat + mount: + mount_point: /boot/efi + fstab: + options: "defaults" + fsck-passno: 1 + - name: BSP + type: 'EF02' + size: 8MiB + - name: root + type: '8300' + size: 100% + mkfs: + type: ext4 + mount: + mount_point: / + fstab: + options: "defaults" + fsck-passno: 1 diff --git a/diskimage_builder/elements/block-device-efi/element-provides b/diskimage_builder/elements/block-device-efi/element-provides new file mode 100644 index 00000000..c0180a2c --- /dev/null +++ b/diskimage_builder/elements/block-device-efi/element-provides @@ -0,0 +1 @@ +block-device \ No newline at end of file diff --git a/diskimage_builder/elements/block-device-gpt/README.rst b/diskimage_builder/elements/block-device-gpt/README.rst index 64d0ffbd..920ce93c 100644 --- a/diskimage_builder/elements/block-device-gpt/README.rst +++ b/diskimage_builder/elements/block-device-gpt/README.rst @@ -2,10 +2,10 @@ Block Device GPT ================ -This is an override for the default block-device configuration -provided in the ``vm`` element to get a GPT based single-partition -disk, rather than the default MBR. +This provides a block-device configuration for the ``vm`` element to +get a GPT based single-partition disk. -Note this provides the extra `BIOS boot partition +Note on x86 this provides the extra `BIOS boot partition `__ as required for non-EFI boot environments. + diff --git a/diskimage_builder/elements/block-device-gpt/block-device-ppc64el.yaml b/diskimage_builder/elements/block-device-gpt/block-device-ppc64el.yaml new file mode 100644 index 00000000..0f6874fd --- /dev/null +++ b/diskimage_builder/elements/block-device-gpt/block-device-ppc64el.yaml @@ -0,0 +1,32 @@ +# Default GPT block device setup for PPC +# -------------------------------------- +# +# Details (extracted from [1]) +# +# Power Firmware (OFW) scans chosen (nvram value boot-device) device, +# for either PReP* partition or vfat. +# +# PReP is raw and small (8M max) partition which caries only stage1 +# binary. +# +# [1] https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/W51a7ffcf4dfd_4b40_9d82_446ebc23c550/page/PowerLinux%20Boot%20howto + +- local_loop: + name: image0 + +- partitioning: + base: image0 + label: gpt + partitions: + - name: boot + type: '0x4100' + size: 8MiB + - name: root + size: 100% + mkfs: + type: ext4 + mount: + mount_point: / + fstab: + options: "defaults" + fsck-passno: 1 diff --git a/diskimage_builder/elements/block-device-gpt/element-provides b/diskimage_builder/elements/block-device-gpt/element-provides new file mode 100644 index 00000000..c0180a2c --- /dev/null +++ b/diskimage_builder/elements/block-device-gpt/element-provides @@ -0,0 +1 @@ +block-device \ No newline at end of file diff --git a/diskimage_builder/elements/block-device-mbr/README.rst b/diskimage_builder/elements/block-device-mbr/README.rst new file mode 100644 index 00000000..d1d051b1 --- /dev/null +++ b/diskimage_builder/elements/block-device-mbr/README.rst @@ -0,0 +1,7 @@ +================ +Block Device MBR +================ + +This provides the default legacy block-device configuration for the +"vm" element. This configures a single partition and is suitable for +a MBR based bootloader. diff --git a/diskimage_builder/elements/vm/block-device-default.yaml b/diskimage_builder/elements/block-device-mbr/block-device-default.yaml similarity index 100% rename from diskimage_builder/elements/vm/block-device-default.yaml rename to diskimage_builder/elements/block-device-mbr/block-device-default.yaml diff --git a/diskimage_builder/elements/vm/block-device-ppc64el.yaml b/diskimage_builder/elements/block-device-mbr/block-device-ppc64el.yaml similarity index 100% rename from diskimage_builder/elements/vm/block-device-ppc64el.yaml rename to diskimage_builder/elements/block-device-mbr/block-device-ppc64el.yaml diff --git a/diskimage_builder/elements/block-device-mbr/element-provides b/diskimage_builder/elements/block-device-mbr/element-provides new file mode 100644 index 00000000..c0180a2c --- /dev/null +++ b/diskimage_builder/elements/block-device-mbr/element-provides @@ -0,0 +1 @@ +block-device \ No newline at end of file diff --git a/diskimage_builder/elements/ubuntu-minimal/test-elements/xenial-build-succeeds/element-deps b/diskimage_builder/elements/ubuntu-minimal/test-elements/xenial-build-succeeds/element-deps index 4be9e9fe..9c94dfd6 100644 --- a/diskimage_builder/elements/ubuntu-minimal/test-elements/xenial-build-succeeds/element-deps +++ b/diskimage_builder/elements/ubuntu-minimal/test-elements/xenial-build-succeeds/element-deps @@ -1,2 +1,3 @@ +block-device-mbr openstack-ci-mirrors vm diff --git a/diskimage_builder/elements/ubuntu/test-elements/xenial-build-succeeds/element-deps b/diskimage_builder/elements/ubuntu/test-elements/xenial-build-succeeds/element-deps index 4be9e9fe..ccdc4107 100644 --- a/diskimage_builder/elements/ubuntu/test-elements/xenial-build-succeeds/element-deps +++ b/diskimage_builder/elements/ubuntu/test-elements/xenial-build-succeeds/element-deps @@ -1,2 +1,4 @@ +block-device-mbr openstack-ci-mirrors vm + diff --git a/diskimage_builder/elements/vm/element-deps b/diskimage_builder/elements/vm/element-deps index 54960172..3b70d4b7 100644 --- a/diskimage_builder/elements/vm/element-deps +++ b/diskimage_builder/elements/vm/element-deps @@ -1 +1,2 @@ +block-device bootloader diff --git a/diskimage_builder/lib/common-functions b/diskimage_builder/lib/common-functions index 2244de83..5088f86b 100644 --- a/diskimage_builder/lib/common-functions +++ b/diskimage_builder/lib/common-functions @@ -239,9 +239,52 @@ function run_d() { check_break after-$1 bash } +function _arg_defaults_hack() { + # The block-device configuration looks in all elements for a + # "block-device-default.yaml" file. The "vm" element used to + # provide the default block-device, which was fine when there was + # only one option; but now we have mbr, gpt & efi versions. + # + # So now the vm element has a dependency on the block-device + # element, which several different elements can provide. However, + # for backwards compatability we need to ensure you can still + # build without specifying it. Thus if we see the vm element, but + # no block-device-* element, we will automatically add the old + # default MBR. + # + # Note that you can still override this by setting + # DIB_BLOCK_DEVICE_CONFIG; any value there will be taken over the + # element defaults. In this case you'd have "block-device-mbr" as + # an element, but it wouldn't actually be used for configuration. + # + # XXX: if this is becoming a common problem, we could have some + # sort of "element-defaults" that maps a "element-deps" entry to a + # default. + local vm_seen + local blockdev_seen + local elements + + for arg do + if [[ "$arg" =~ "vm" ]]; then + vm_seen=1 + elif [[ "$arg" =~ "block-device-" ]]; then + blockdev_seen=1 + fi + elements="$elements $arg" + done + + if [[ -n "${vm_seen}" && -z "${blockdev_seen}" ]]; then + elements="$elements block-device-mbr" + fi + + echo $elements +} + function arg_to_elements() { for arg do IMAGE_ELEMENT="$IMAGE_ELEMENT $arg" ; done + IMAGE_ELEMENT="$(_arg_defaults_hack $IMAGE_ELEMENT)" + if [ "$SKIP_BASE" != "1" ]; then IMAGE_ELEMENT="base $IMAGE_ELEMENT" fi diff --git a/doc/source/user_guide/building_an_image.rst b/doc/source/user_guide/building_an_image.rst index 720240cd..449cd115 100644 --- a/doc/source/user_guide/building_an_image.rst +++ b/doc/source/user_guide/building_an_image.rst @@ -67,54 +67,24 @@ on. There are currently two defaults: -* When using the `vm` element a MBR based partition layout is created - with exactly one partition that fills up the whole disk and used as - root device. -* When not using the `vm` element a plain filesystem image, without +* When using the ``vm`` element, an element that provides + ``block-device`` should be included. Available ``block-device-*`` + elements cover the common case of a single partition that fills up + the whole disk and used as root device. Currently there are MBR, + GPT and EFI versions. For example, to use a GPT disk you could + build with :: + + disk-image-create -o output.qcow vm block-device-gpt ubuntu-minimal + +* When not using the ``vm`` element a plain filesystem image, without any partitioning, is created. -The user can overwrite the default handling by setting the environment +If you wish to customise the top-level ``block-device-default.yaml`` +file from one of the ``block-device-*`` elements, set the environment variable `DIB_BLOCK_DEVICE_CONFIG`. This variable must hold YAML structured configuration data or be a ``file://`` URL reference to a on-disk configuration file. -The default when using the `vm` element is: - -.. code-block:: yaml - - DIB_BLOCK_DEVICE_CONFIG=' - - local_loop: - name: image0 - - - partitioning: - base: image0 - label: mbr - partitions: - - name: root - flags: [ boot, primary ] - size: 100% - mkfs: - mount: - mount_point: / - fstab: - options: "defaults" - fsck-passno: 1' - -The default when not using the `vm` element is: - -.. code-block:: yaml - - DIB_BLOCK_DEVICE_CONFIG=' - - local_loop: - name: image0 - mkfs: - name: mkfs_root - mount: - mount_point: / - fstab: - options: "defaults" - fsck-passno: 1' - There are a lot of different options for the different levels. The following sections describe each level in detail.