From 1a64768fca3126b43fe9e7c1fbf9750b0f954b5b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 26 Aug 2025 08:08:24 -0400 Subject: [PATCH] Carry forward EL* installtodisk to EL9 --- .../profiles/default/scripts/firstboot.sh | 4 +++- .../profiles/default/scripts/image2disk.py | 21 ++++++++++++++++--- .../profiles/default/scripts/installimage | 10 ++++++++- .../profiles/default/scripts/post.sh | 3 ++- .../profiles/default/scripts/pre.d/.gitignore | 0 5 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 confluent_osdeploy/el9-diskless/profiles/default/scripts/pre.d/.gitignore diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/firstboot.sh b/confluent_osdeploy/el9-diskless/profiles/default/scripts/firstboot.sh index fabb9385..6a1c98b4 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/firstboot.sh +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/firstboot.sh @@ -31,8 +31,10 @@ done if [ ! -f /etc/confluent/firstboot.ran ]; then touch /etc/confluent/firstboot.ran - cat /etc/confluent/tls/*.pem >> /etc/pki/tls/certs/ca-bundle.crt + cat /etc/confluent/tls/*.pem >> /etc/pki/tls/certs/ca-bundle.crt + confluentpython /root/confignet + rm /root/confignet run_remote firstboot.custom # Firstboot scripts may be placed into firstboot.d, e.g. firstboot.d/01-firstaction.sh, firstboot.d/02-secondaction.sh run_remote_parts firstboot.d diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py index 51a58c7d..36ce84c6 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py @@ -170,6 +170,15 @@ def fixup(rootdir, vols): grubsyscfg = os.path.join(rootdir, 'etc/sysconfig/grub') if not os.path.exists(grubsyscfg): grubsyscfg = os.path.join(rootdir, 'etc/default/grub') + currcmdline = [] + with open('/proc/cmdline') as cmdlinein: + cmdline = cmdlinein.read().strip() + for arg in cmdline.split(): + if arg.startswith('console='): + currcmdline.append(arg) + elif arg == 'quiet': + currcmdline.append(arg) + currcmdlinestr = ' '.join(currcmdline) kcmdline = os.path.join(rootdir, 'etc/kernel/cmdline') if os.path.exists(kcmdline): with open(kcmdline) as kcmdlinein: @@ -225,13 +234,13 @@ def fixup(rootdir, vols): 'GRUB_DISABLE_SUBMENU=true', 'GRUB_TERMINAL=""', 'GRUB_SERIAL_COMMAND=""', - 'GRUB_CMDLINE_LINUX="crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M rd.lvm.lv=vg/root rd.lvm.lv=vg/swap"', + 'GRUB_CMDLINE_LINUX="{}crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M rd.lvm.lv=vg/root rd.lvm.lv=vg/swap"'.format(currcmdlinestr), 'GRUB_DISABLE_RECOVERY="true"', 'GRUB_ENABLE_BLSCFG=true', ] if not os.path.exists(os.path.join(rootdir, "etc/kernel/cmdline")): with open(os.path.join(rootdir, "etc/kernel/cmdline"), "w") as cmdlineout: - cmdlineout.write("root=/dev/mapper/localstorage-root rd.lvm.lv=localstorage/root") + cmdlineout.write("{} root=/dev/mapper/localstorage-root rd.lvm.lv=localstorage/root".format(currcmdlinestr)) with open(grubsyscfg, 'w') as defgrubout: for gline in defgrub: gline = gline.split() @@ -592,7 +601,13 @@ def install_to_disk(imgpath): - subprocess.check_call(['umount', '/run/imginst/targ']) + while True: + try: + subprocess.check_call(['umount', '/run/imginst/targ']) + break + except subprocess.CalledProcessError: + print("Failed to unmount /run/imginst/targ, retrying") + time.sleep(1) for vol in allvols: subprocess.check_call(['mount', vol['targetdisk'], '/run/imginst/targ/' + vol['mount']]) fixup('/run/imginst/targ', allvols) diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage b/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage index c461173b..b342de7d 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage @@ -21,8 +21,15 @@ else done fi cd /sysroot/run +[ -f /run/sshd.pid ] && +cp /run/sshd.pid /tmp/dbgssh.pid +chroot /sysroot/ bash -c "/usr/sbin/sshd" chroot /sysroot/ bash -c "source /etc/confluent/functions; run_remote_python getinstalldisk" chroot /sysroot/ bash -c "source /etc/confluent/functions; run_remote_parts pre.d" +for nameserver in $(sed -n '/^nameservers:/,/^[^-]/p' /etc/confluent/confluent.deploycfg|grep ^- | cut -d ' ' -f 2|sed -e 's/ //'); do + echo "nameserver $nameserver" >> /sysroot/etc/resolv.conf +done + if [ ! -f /sysroot/tmp/installdisk ]; then echo 'Unable to find a suitable installation target device, ssh to port 2222 to investigate' while [ ! -f /sysroot/tmp/installdisk ]; do @@ -40,7 +47,8 @@ chroot /sysroot bash -c "source /etc/confluent/functions; run_remote_python imag echo "Port 22" >> /etc/ssh/sshd_config echo 'Match LocalPort 22' >> /etc/ssh/sshd_config echo ' ChrootDirectory /sysroot/run/imginst/targ' >> /etc/ssh/sshd_config -kill -HUP $(cat /run/sshd.pid) +kill $(cat /sysroot/var/run/sshd.pid) +[ -f /tmp/dbgssh.pid ] && kill -HUP $(cat /tmp/dbgssh.pid) cp /sysroot/etc/pki/ca-trust/source/anchors/* /sysroot/run/imginst/targ/etc/pki/ca-trust/source/anchors/ chroot /sysroot/run/imginst/targ update-ca-trust diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh b/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh index 914a12c3..0a09299b 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/post.sh @@ -43,7 +43,8 @@ run_remote_parts post.d # Induce execution of remote configuration, e.g. ansible plays in ansible/post.d/ run_remote_config post.d - +cd /root/ +fetch_remote confignet # rebuild initrd, pick up new drivers if needed dracut -f /boot/initramfs-$(uname -r).img $(uname -r) diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/pre.d/.gitignore b/confluent_osdeploy/el9-diskless/profiles/default/scripts/pre.d/.gitignore new file mode 100644 index 00000000..e69de29b