From 63bbe53448604f73f7c598a42ae8fe28f0a46a79 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 22 Aug 2025 08:39:40 -0400 Subject: [PATCH] Address numerous issues with 'installtodisk' for el8 Add missing pre.d directory to let user know they can use such scripts Preserve console directievs from kernelargs into installed system Retry umount during image2disk, if processes have the filesystem busy. Fix DNS behavior during post phase of installtodisk Invoke confignet properly during firstboot to set up additional interfaces. Have sshd run during the install from '/sysroot', for convenience Fix some cosmetic error output for setupssh --- .../common/profile/scripts/setupssh | 8 ++++--- .../profiles/default/scripts/firstboot.sh | 3 ++- .../profiles/default/scripts/image2disk.py | 23 +++++++++++++++---- .../profiles/default/scripts/installimage | 10 +++++++- .../profiles/default/scripts/post.sh | 2 ++ .../profiles/default/scripts/pre.d/.gitignore | 0 6 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 confluent_osdeploy/el8-diskless/profiles/default/scripts/pre.d/.gitignore diff --git a/confluent_osdeploy/common/profile/scripts/setupssh b/confluent_osdeploy/common/profile/scripts/setupssh index 63d5e462..83c05fa1 100644 --- a/confluent_osdeploy/common/profile/scripts/setupssh +++ b/confluent_osdeploy/common/profile/scripts/setupssh @@ -31,9 +31,11 @@ confluentpython $confapiclient /confluent-public/site/initramfs.tgz -o initramfs tar xf initramfs.tgz for ca in ssh/*.ca; do LINE=$(cat $ca) - if [ -z "$LINE" ]; then continue; fi - cp -af /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts.new - grep -v "$LINE" /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.new + if [ -z "$LINE" ]; then continue; fi + if [ -f /etc/ssh/ssh_known_hosts ]; then + cp -af /etc/ssh/ssh_known_hosts /etc/ssh/ssh_known_hosts.new + grep -v "$LINE" /etc/ssh/ssh_known_hosts > /etc/ssh/ssh_known_hosts.new + fi echo '@cert-authority *' $LINE >> /etc/ssh/ssh_known_hosts.new mv /etc/ssh/ssh_known_hosts.new /etc/ssh/ssh_known_hosts done diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/firstboot.sh b/confluent_osdeploy/el8-diskless/profiles/default/scripts/firstboot.sh index 2bab4136..922dbcda 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/firstboot.sh +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/firstboot.sh @@ -25,7 +25,8 @@ if [ ! -f /etc/confluent/firstboot.ran ]; then touch /etc/confluent/firstboot.ran 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/el8-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py index 5aeaeefe..a6951379 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py @@ -157,6 +157,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) if os.path.exists(grubsyscfg): with open(grubsyscfg) as defgrubin: defgrub = defgrubin.read().split('\n') @@ -168,13 +177,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() @@ -468,8 +477,14 @@ def install_to_disk(imgpath): - - subprocess.check_call(['umount', '/run/imginst/targ']) + while True: + try: + subprocess.check_call(['umount', '/run/imginst/targ']) + except subprocess.CalledProcessError: + print("Failed to unmount /run/imginst/targ, retrying") + time.sleep(1) + else: + break 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/el8-diskless/profiles/default/scripts/installimage b/confluent_osdeploy/el8-diskless/profiles/default/scripts/installimage index a880c3ee..031b1479 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/installimage +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/installimage @@ -5,6 +5,7 @@ # and existing mounts of image (to take advantage of caching) mount -o bind /sys /sysroot/sys mount -o bind /dev /sysroot/dev +mount -o bind /dev/pts /sysroot/dev/pts mount -o bind /proc /sysroot/proc mount -o bind /run /sysroot/run @@ -21,8 +22,14 @@ else done fi cd /sysroot/run +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 +#chroot /sysroot/ bash -c "source /etc/confluent/functions; run_remote_python confignet" 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 @@ -39,7 +46,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) +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/el8-diskless/profiles/default/scripts/post.sh b/confluent_osdeploy/el8-diskless/profiles/default/scripts/post.sh index a61bc67b..23e13dfe 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/post.sh +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/post.sh @@ -37,6 +37,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 curl -sf -X POST -d 'status: staged' -H "CONFLUENT_NODENAME: $nodename" -H "CONFLUENT_APIKEY: $confluent_apikey" https://$confluent_mgr/confluent-api/self/updatestatus kill $logshowpid diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/pre.d/.gitignore b/confluent_osdeploy/el8-diskless/profiles/default/scripts/pre.d/.gitignore new file mode 100644 index 00000000..e69de29b