From a4648872ba5c70e76121de8cfa1816b033addeef Mon Sep 17 00:00:00 2001 From: Hoang Trung Hieu Date: Fri, 9 Feb 2018 15:05:33 +0700 Subject: [PATCH] Add iscsi-boot element for CentOS images This patch adds an element that handles the configuration for creating a disk capable of being a remote root filesystem through iSCSI on CentOS images. Tested on Fujitsu Server and boot with BIOS and UEFI mode successfully. - Tested Boot-From-Volume + EFI for centos7 with following elements: "centos7 vm devuser cloud-init-datasources dhcp-all-interfaces iscsi-boot dracut-regenerate block-device-efi" Co-authored-By: Nguyen Van Trung Change-Id: Ia1f23d722dced6f254fd7aee86abe8066a72fa42 --- .../elements/iscsi-boot/README.rst | 17 ++++++++++++----- .../iscsi-boot/environment.d/open-iscsi-config | 14 ++++++++++++++ .../iscsi-boot/finalise.d/51-open-iscsi-config | 13 +++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 diskimage_builder/elements/iscsi-boot/environment.d/open-iscsi-config create mode 100755 diskimage_builder/elements/iscsi-boot/finalise.d/51-open-iscsi-config diff --git a/diskimage_builder/elements/iscsi-boot/README.rst b/diskimage_builder/elements/iscsi-boot/README.rst index 70a674e1b..fa867a05c 100644 --- a/diskimage_builder/elements/iscsi-boot/README.rst +++ b/diskimage_builder/elements/iscsi-boot/README.rst @@ -3,11 +3,18 @@ iscsi-boot ========== Handles configuration for the disk to be capable of serving as a remote root filesystem through iSCSI. Currently, this element -only configures Ubuntu/Debian images. +can configure Ubuntu/Debian images and CentOS7 images. It performs the following actions: -* Installs the ``open-iscsi`` package. -* Creates the ``etc/iscsi/iscsi.initramfs`` configuration file and sets - ``ISCSI_AUTO=true`` within it. -* Updates the initramfs to apply the changes. +For Ubuntu/Debian images: + * Installs the ``open-iscsi`` package. + * Creates the ``etc/iscsi/iscsi.initramfs`` configuration file and sets + ``ISCSI_AUTO=true`` within it. + * Updates the initramfs to apply the changes. + +For CentOS7 images: + * Required ``dracut-regenerate`` element when performs ``disk-image-create``. + * Updates ``network`` and ``iscsi`` into ``dracut-regenerate`` during + pre-installs. + * Updates ``GRUB_CMDLINE_LINUX_DEFAULT`` into ``/etc/default/grub``. diff --git a/diskimage_builder/elements/iscsi-boot/environment.d/open-iscsi-config b/diskimage_builder/elements/iscsi-boot/environment.d/open-iscsi-config new file mode 100644 index 000000000..52b815c41 --- /dev/null +++ b/diskimage_builder/elements/iscsi-boot/environment.d/open-iscsi-config @@ -0,0 +1,14 @@ +if [[ $DISTRO_NAME = "centos7" ]]; then + eval declare -A image_elements=($(get_image_element_array)) + found=0 + for i in "${!image_elements[@]}"; do + [ "$i" = "dracut-regenerate" ] && found=1 + done + [ "$found" = 0 ] && echo "The dracut-regenerate element is required!" && exit 1 + + DIB_DRACUT_ENABLED_MODULES+=" +- name: network +- name: iscsi + " + export DIB_DRACUT_ENABLED_MODULES +fi diff --git a/diskimage_builder/elements/iscsi-boot/finalise.d/51-open-iscsi-config b/diskimage_builder/elements/iscsi-boot/finalise.d/51-open-iscsi-config new file mode 100755 index 000000000..239dc407a --- /dev/null +++ b/diskimage_builder/elements/iscsi-boot/finalise.d/51-open-iscsi-config @@ -0,0 +1,13 @@ +#!/bin/bash + +if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then + set -x +fi + +set -eu +set -o pipefail + +if [[ $DISTRO_NAME = "centos7" ]]; then + sed -i -E 's/(GRUB_CMDLINE_LINUX_DEFAULT=")(.+)(")/\1\2 rd.iscsi.firmware=1"/' /etc/default/grub + grub2-mkconfig -o /boot/grub2/grub.cfg +fi