From 9ae903606e4e36c1dd652279c412b5ef0ab7d762 Mon Sep 17 00:00:00 2001 From: Alexandru Avadanii Date: Fri, 15 Nov 2019 15:19:01 +0100 Subject: [PATCH] EFI support for installmedia dracut module - fix non-printable character in sh script; - add UEFI and GPT partition table handling: * move backup GPT data structures to the end of the disk after dumping the image to disk; * mount the 3rd partition as root if EFI system partition (ESP) is present, while also mounting ESP separately; * use the appropiate path for grub.cfg depending on whether UEFI is used or not; * add a few seconds of delay to allow all GPT partitions to be properly discovered before attempting to mount sysroot; - extend requires to include the full `cloud-utils` package and its dependencies (e.g. util-linux, qemu-img-ev, cloud-utils-growpart) since the AArch64 base image does not include growpart like the x86_64 base image does (x86_64 base image qcow2 being newer than its aarch64 counterpart - version 1801 versus 1708); While at it, fix loading the ipmi_ssif kernel module on AArch64. Co-authored-by: Jimmy Lafontaine Rivera Signed-off-by: Alexandru Avadanii Change-Id: Ibef1b8fc16c3d95eca1ac87ec8cc3b449df1eb0a --- dracut/modules/00installmedia/installmedia-lib.sh | 9 +++++ dracut/modules/00installmedia/installmedia.sh | 40 ++++++++++++++++++++--- dracut/modules/00installmedia/module-setup.sh | 2 +- image-provision.spec | 12 +++++-- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/dracut/modules/00installmedia/installmedia-lib.sh b/dracut/modules/00installmedia/installmedia-lib.sh index 72b8b0e..de57bc8 100755 --- a/dracut/modules/00installmedia/installmedia-lib.sh +++ b/dracut/modules/00installmedia/installmedia-lib.sh @@ -121,6 +121,15 @@ function is_removable(){ } +function is_esp_partition_present(){ + check_params 1 "$@" + device=$1 + if [ 'vfat' = "$(blkid -o value -s TYPE ${device}1)" ]; then + return 0 + fi + return 1 +} + function get_config_from_device_end(){ check_params 1 "$@" local BOOTDEVICE=$1 diff --git a/dracut/modules/00installmedia/installmedia.sh b/dracut/modules/00installmedia/installmedia.sh index 3d24daf..57026a3 100755 --- a/dracut/modules/00installmedia/installmedia.sh +++ b/dracut/modules/00installmedia/installmedia.sh @@ -77,7 +77,7 @@ for hd_dev in ${hd_devices[@]}; do if [ -b /dev/$hd_dev ] && (( is_removable $hd_dev ) || ( is_partition $hd_dev ) || ( is_loop $hd_dev )); then logmsg "Removable, loop or partition $hd_dev. Skipping..." continue - elif ! [ -b /dev/$hd_dev ];then + elif ! [ -b /dev/$hd_dev ]; then continue fi logmsg "Erasing existing GPT and MBR data structures from ${hd_dev}" @@ -96,6 +96,21 @@ if [ $? -ne 0 ]; then fi sync +partprobe ${rootdev} +is_esp_partition_present "${rootdev}" +rootdev_has_uefi=$? + +# For UEFI systems (which imply using a GPT partition table), fix the GPT backup +# data structures by moving them to the end of the disk; rootfs partition will +# have index 3 (1=ESP, 2=boot, 3=rootfs), unlike BIOS/MBR layout where it has 1. +if [ "${rootdev_has_uefi}" -eq 0 ]; then + sgdisk -e "${rootdev}" + sleep 5 + rootpartno=3 +else + rootpartno=1 +fi + logmsg "${rootdev} dumped successfully!" echo "Finishing installation... Please wait." > $CONSOLE_DEV @@ -104,12 +119,22 @@ partprobe ${rootdev} parted ${rootdev} --script -- mkpart primary 50GiB -1 partprobe ${rootdev} -mount ${rootdev}1 /sysroot/ +# For GPT and 3 partitions, it might take some time to (re)discover them all +sleep 5 +mount "${rootdev}${rootpartno}" /sysroot/ if [ $? -ne 0 ];then logmsg "FAILED TO MOUNT SYSROOT. All hope is lost" exit 255 fi +if [ "${rootdev_has_uefi}" -eq 0 ]; then + mount "${rootdev}1" /sysroot/boot/efi + if [ $? -ne 0 ];then + logmsg "FAILED TO MOUNT EFI SYSTEM PARTITION. All hope is lost" + exit 255 + fi +fi + kernel_cmdline="intel_iommu=on iommu=pt crashkernel=256M" # Check if this has a iscsi target if so, add extra cmdline option for HDD boot. iscsiadm -m fw >/dev/null 2>&1 @@ -125,10 +150,14 @@ fi run_crit mount -o bind /dev /sysroot/dev run_crit mount -o bind /proc /sysroot/proc run_crit mount -o bind /sys /sysroot/sys -run_crit chroot /sysroot /bin/bash -c \"/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg\" +if [ "${rootdev_has_uefi}" -eq 0 ]; then + run_crit chroot /sysroot /bin/bash -c \"/usr/sbin/grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg\" +else + run_crit chroot /sysroot /bin/bash -c \"/usr/sbin/grub2-mkconfig -o /boot/grub2/grub.cfg\" +fi logmsg "Extending partition and filesystem size" -run_crit chroot /sysroot /bin/bash -c \"growpart ${rootdev} 1\" +run_crit chroot /sysroot /bin/bash -c \"growpart ${rootdev} ${rootpartno}\" run_crit chroot /sysroot /bin/bash -c \"xfs_growfs /\" logmsg "Copying cloud guest image" @@ -168,6 +197,9 @@ cp -rf /run/initramfs/ /sysroot/var/log/provisioning-logs/ sync +if [ "${rootdev_has_uefi}" -eq 0 ]; then + umount /sysroot/boot/efi +fi umount /sysroot/dev umount /sysroot/proc umount /sysroot/sys diff --git a/dracut/modules/00installmedia/module-setup.sh b/dracut/modules/00installmedia/module-setup.sh index 3480784..526a058 100755 --- a/dracut/modules/00installmedia/module-setup.sh +++ b/dracut/modules/00installmedia/module-setup.sh @@ -30,7 +30,7 @@ depends () installkernel() { - instmods = sr_mod mpt3sas raid_class scsi_transport_sas weak-updates/be2iscsi/be2iscsi ipmi_msghandler ipmi_devintf ipmi_si + instmods = sr_mod mpt3sas raid_class scsi_transport_sas weak-updates/be2iscsi/be2iscsi ipmi_msghandler ipmi_devintf ipmi_si ipmi_ssif } install_python_module() { diff --git a/image-provision.spec b/image-provision.spec index 32ce868..0882b82 100644 --- a/image-provision.spec +++ b/image-provision.spec @@ -14,7 +14,7 @@ Name: image-provision Version: %{_version} -Release: 3%{?dist} +Release: 4%{?dist} Summary: Contains dracut modules used for provisioning master image from a boot CD. License: %{_platform_licence} Source0: %{name}-%{version}.tar.gz @@ -22,7 +22,7 @@ Vendor: %{_platform_vendor} BuildArch: noarch BuildRequires: rsync -Requires: cloud-init, dracut, coreutils, parted, gzip, iproute, util-linux, findutils, kmod, kbd, iscsi-initiator-utils, qemu-img-ev, gdisk, tar, wget, curl, glibc, hw-detector +Requires: cloud-init, dracut, coreutils, parted, gzip, iproute, cloud-utils, findutils, kmod, kbd, iscsi-initiator-utils, gdisk, tar, wget, curl, glibc, hw-detector %description This RPM contains dracut modules. They are used for provisioning master image from a boot CD. @@ -76,7 +76,13 @@ fi grep -q "net.ifnames=0" /etc/default/grub if [[ $? == 0 ]];then sed -i 's/net.ifnames=0 //' /etc/default/grub - grub2-mkconfig > /etc/grub2.cfg + # /etc/grub2[-efi].cfg are symlinks to /boot/.../grub.cfg + if [ -e /etc/grub2.cfg ]; then + grub2-mkconfig > /etc/grub2.cfg + fi + if [ -e /etc/grub2-efi.cfg ]; then + grub2-mkconfig > /etc/grub2-efi.cfg + fi fi -- 2.16.6