From df42831f6395437801d2dc69ac7e1f49e4882be2 Mon Sep 17 00:00:00 2001 From: Alan Baghumian Date: Thu, 15 Aug 2024 17:01:21 -0700 Subject: [PATCH] added curtin hooks to properly add main storage kernel modules including NVME, resolving failed deployment issues on machines with NVME disks. --- sles15/curtin/curtin-hooks | 94 ++++++++++++++++++++++++++++++++++ sles15/curtin/setup-bootloader | 23 +++++++++ sles15/http/sles15.xml | 3 +- 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100755 sles15/curtin/curtin-hooks create mode 100755 sles15/curtin/setup-bootloader diff --git a/sles15/curtin/curtin-hooks b/sles15/curtin/curtin-hooks new file mode 100755 index 00000000..6d43c272 --- /dev/null +++ b/sles15/curtin/curtin-hooks @@ -0,0 +1,94 @@ +#!/usr/bin/env python3 +# Copyright (C) 2024 Canonical +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + + +import os +import shutil +import platform + +from curtin import distro, util +from curtin.config import load_command_config +from curtin.log import LOG +from curtin.paths import target_path +from curtin.util import load_command_environment, ChrootableTarget +from curtin.commands import curthooks + +def run_hook_in_target(target, hook): + """Look for "hook" in "target" and run in a chroot""" + target_hook = target_path(target, '/curtin/' + hook) + if os.path.isfile(target_hook): + LOG.debug("running %s" % target_hook) + with ChrootableTarget(target=target) as in_chroot: + in_chroot.subp(['/curtin/' + hook]) + return True + return False + +def curthook(cfg, target, state): + """Configure network and bootloader""" + LOG.info('Running curtin builtin curthooks') + state_etcd = os.path.split(state['fstab'])[0] + machine = platform.machine() + + distro_info = distro.get_distroinfo(target=target) + if not distro_info: + raise RuntimeError('Failed to determine target distro') + osfamily = distro_info.family + LOG.info('Configuring target system for distro: %s osfamily: %s', + distro_info.variant, osfamily) + + sources = cfg.get('sources', {}) + dd_image = len(util.get_dd_images(sources)) > 0 + + curthooks.disable_overlayroot(cfg, target) + curthooks.disable_update_initramfs(cfg, target, machine) + + if not dd_image: + curthooks.configure_iscsi(cfg, state_etcd, target, osfamily=osfamily) + curthooks.configure_mdadm(cfg, state_etcd, target, osfamily=osfamily) + curthooks.copy_fstab(state.get('fstab'), target) + curthooks.add_swap(cfg, target, state.get('fstab')) + + run_hook_in_target(target, 'install-custom-packages') + + curthooks.apply_networking(target, state) + curthooks.handle_pollinate_user_agent(cfg, target) + + # set cloud-init maas datasource + if cfg.get('cloudconfig'): + curthooks.handle_cloudconfig( + cfg['cloudconfig'], + base_dir=target_path(target, + 'etc/cloud/cloud.cfg.d')) + + run_hook_in_target(target, 'setup-bootloader') + +def cleanup(): + """Remove curtin-hooks so its as if we were never here.""" + curtin_dir = os.path.dirname(__file__) + shutil.rmtree(curtin_dir) + + +def main(): + state = load_command_environment() + config = load_command_config(None, state) + target = state['target'] + + curthook(config, target, state) + cleanup() + + +if __name__ == "__main__": + main() diff --git a/sles15/curtin/setup-bootloader b/sles15/curtin/setup-bootloader new file mode 100755 index 00000000..07e5c3ec --- /dev/null +++ b/sles15/curtin/setup-bootloader @@ -0,0 +1,23 @@ +#!/bin/bash +# Ensure There are adequete storage drivers +echo 'add_drivers+=" ahci nvme nvme_core raid_class scsi_mod sd_mod "' > /etc/dracut.conf.d/custom.conf + +# Update All initramfs files +for kernel in $(ls /lib/modules/); do + dracut --force /boot/initrd-${kernel} ${kernel} +done + +# Generate the GRUB config file +grub2-mkconfig -o /boot/grub2/grub.cfg + +# Install GRUB and update the configuration +if [ -d /sys/firmware/efi/efivars/ ]; then + shim-install +else + grub_dev="/dev/$(lsblk -r | grep 'part /$' | awk '{print $1}' | sed s/[0-9]//g)" + + grub2-install \ + --target=i386-pc \ + --recheck ${grub_dev} +fi +exit 0 diff --git a/sles15/http/sles15.xml b/sles15/http/sles15.xml index 343f2072..eb053ce9 100644 --- a/sles15/http/sles15.xml +++ b/sles15/http/sles15.xml @@ -160,6 +160,7 @@ glibc jfsutils kernel-default-devel + kernel-default kexec-tools lvm2 make @@ -263,4 +264,4 @@ rm -rf /etc/ssh/ssh_host_* - \ No newline at end of file +