Merge "New elements replace-partition(-redhat)"

This commit is contained in:
Zuul 2024-09-05 18:26:57 +00:00 committed by Gerrit Code Review
commit 6632aaa80e
10 changed files with 131 additions and 0 deletions

View File

@ -27,6 +27,7 @@ uuid-runtime [platform:dpkg]
debootstrap [platform:dpkg]
zstd [platform:dpkg]
procps [platform:dpkg]
libguestfs-tools [platform:dpkg]
# Version/distro specific items
python-lzma [platform:ubuntu-bionic platform:debian-buster]
yum-utils [platform:ubuntu-bionic platform:debian-buster]
@ -34,6 +35,7 @@ dnf [platform:dpkg !platform:debian-buster !platform:ubuntu-trusty !platform:ubu
# centos/fedora
qemu-img [platform:redhat]
libguestfs [platform:redhat]
policycoreutils-python [platform:rhel-7 platform:centos-7]
policycoreutils-python-utils [platform:fedora platform:rhel-8 platform:centos-8]
procps-ng [platform:redhat]

View File

@ -0,0 +1,22 @@
========================
replace-partition-redhat
========================
A redhat family specific version of the ``replace-partition`` element.
A standalone element which consumes a base image which was created with
``diskimage-builder`` and rebuilds it without making any packaging changes.
Example
=======
The following will use ``./my-dib-image.qcow2`` as the base image and create a
new image ``my-dib-image-custom.qcow2`` with the partition layout defined in
``./block-device-custom.yaml``:
.. code-block:: bash
export DISTRO_NAME=rhel
export DIB_BLOCK_DEVICE_CONFIG=file://./block-device-custom.yaml
export DIB_LOCAL_IMAGE=./my-dib-image.qcow2
disk-image-create -x -a x86_64 -o my-dib-image-custom.qcow2 --image-size 6GiB replace-partition-redhat

View File

@ -0,0 +1,2 @@
replace-partition
selinux-fixfiles-restore

View File

@ -0,0 +1,12 @@
if [ -z "${DISTRO_NAME:-}" ]; then
echo "DISTRO_NAME is not set! Can not continue"
exit 1
fi
export DIB_RELEASE=${DIB_RELEASE:-9}
if [[ $DISTRO_NAME =~ "rhel" ]]; then
export EFI_BOOT_DIR="EFI/redhat"
else
export EFI_BOOT_DIR="EFI/$DISTRO_NAME"
fi
export DIB_BLOCK_DEVICE=efi
export DIB_INIT_SYSTEM=systemd

View File

@ -0,0 +1,31 @@
=================
replace-partition
=================
A standalone element which consumes a base image which was created with
``diskimage-builder`` and rebuilds it without making any packaging changes. This
allows the image contents to be copied to a new block device layout. Use cases
for this element include:
* Rebuilding a whole-disk image with a different partition layout by setting
``DIB_BLOCK_DEVICE_CONFIG``
* Rebuilding a whole-disk image with the same partitions but with the sector
size increased to 4096 bytes
See element ``replace-partition-redhat`` for a full example of how to use this element
Arguments
=========
The following arguments are mandatory and should be set to the correct values as
for other distro elements:
* ``DISTRO_NAME``
* ``DIB_RELEASE``
* ``EFI_BOOT_DIR``
* ``DIB_INIT_SYSTEM``
* ``DIB_BLOCK_DEVICE``
* ``DIB_LOCAL_IMAGE``
``DIB_SOURCE_BLOCK_SIZE`` can be set to 4096 if the base image
``DIB_LOCAL_IMAGE`` was created with a 4096 byte sector size.

View File

@ -0,0 +1 @@
bootloader

View File

@ -0,0 +1 @@
operating-system

View File

@ -0,0 +1,25 @@
if [ -z "${DISTRO_NAME:-}" ]; then
echo "DISTRO_NAME is not set! Can not continue"
exit 1
fi
if [ -z "${DIB_RELEASE:-}" ]; then
echo "DIB_RELEASE is not set! Can not continue"
exit 1
fi
if [ -z "${EFI_BOOT_DIR:-}" ]; then
echo "EFI_BOOT_DIR is not set! Can not continue"
exit 1
fi
if [ -z "${DIB_INIT_SYSTEM:-}" ]; then
echo "DIB_INIT_SYSTEM is not set! Can not continue"
exit 1
fi
if [ -z "${DIB_BLOCK_DEVICE:-}" ]; then
echo "DIB_BLOCK_DEVICE is not set! Can not continue"
exit 1
fi
export DIB_SKIP_GRUB_PACKAGE_INSTALL=True
export DIB_SKIP_BASE_PACKAGE_INSTALL=1
export DIB_AVOID_PACKAGES_UPDATE=1
export DIB_IMAGE_EXTRACT_GUESTFISH=True
export DIB_SOURCE_BLOCK_SIZE=512

View File

@ -0,0 +1,26 @@
#!/bin/bash
if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then
set -x
fi
set -eu
set -o pipefail
[ -n "$TARGET_ROOT" ]
DIB_LOCAL_IMAGE=${DIB_LOCAL_IMAGE:-""}
if [ -n "$DIB_LOCAL_IMAGE" ]; then
IMAGE_LOCATION=$DIB_LOCAL_IMAGE
# No need to copy a local image into the cache directory, so just specify
# the cached path as the original path.
CACHED_IMAGE=$IMAGE_LOCATION
else
echo "DIB_LOCAL_IMAGE is required"
exit 1
fi
guestfish -v -x -i --blocksize=$DIB_SOURCE_BLOCK_SIZE -a $CACHED_IMAGE <<EOF
tar-out / - numericowner:true xattrs:true | sudo tar -C $TARGET_ROOT --numeric-owner --xattrs --xattrs-include='*' --xattrs-exclude='security.selinux' -xf -
EOF

View File

@ -0,0 +1,9 @@
---
features:
- |
The new element ``replace-partition`` has been added which allows a
diskimage-builder built image to be used as the base image so that it can be
copied to a new partition layout. This allows the content to be copied from
one image to a new one without making any package changes. The element
``replace-partition-redhat`` has a documented example for redhat family
images.