diff --git a/confluent_client/doc/man/imgutil.ronn b/confluent_client/doc/man/imgutil.ronn index ff014ec1..b3a82da7 100644 --- a/confluent_client/doc/man/imgutil.ronn +++ b/confluent_client/doc/man/imgutil.ronn @@ -26,6 +26,10 @@ * `exec`: Start the specified scratch directory as a container and optionally run a command inside it. + While it runs, `/proc`, `/sys`, `/dev`, an empty `/run` and the build + system's `/etc/resolv.conf` are mounted, without changing the scratch + directory. A plain `chroot` lacks them (no DNS, no `/dev/null`), so run + chroot based tools through `imgutil exec`, see EXAMPLES. * `unpack`: Unpack a diskless image profile to a scratch directory for modification. @@ -142,7 +146,8 @@ Directory of an unpacked diskless root. * : - Optional command to run (defaults to a shell). + Optional command to run (defaults to a shell). Put `--` before a + command that has options. ## UNPACK OPTIONS @@ -223,7 +228,19 @@ Execute a shell in an unpacked image: Execute a specific command in an image: - imgutil exec /tmp/myimage /bin/rpm -qa + imgutil exec /tmp/myimage -- rpm -qa + +Run an ansible playbook in an image through `imgutil exec` (chroot +connection of community.general): + + cat > /usr/local/sbin/imgutil-chroot << 'EOF' + #!/bin/sh + exec /opt/confluent/bin/imgutil exec -- "$@" + EOF + chmod 755 /usr/local/sbin/imgutil-chroot + ansible-playbook -c community.general.chroot \ + -e ansible_chroot_exe=/usr/local/sbin/imgutil-chroot \ + -i /tmp/myimage, site.yml Unpack an existing profile for modification: diff --git a/confluent_osdeploy/el10-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/el10-diskless/profiles/default/scripts/imageboot.sh index d1acfe83..57c32a7b 100644 --- a/confluent_osdeploy/el10-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/el10-diskless/profiles/default/scripts/imageboot.sh @@ -159,6 +159,10 @@ if [ ${#machineid} -eq 32 ]; then echo $machineid > /sysroot/etc/machine-id chmod 444 /sysroot/etc/machine-id fi +# Do not autoactivate LVM on local disks unless the image sets auto_activation_volume_list +if [ -e /sysroot/etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /sysroot/etc/lvm/lvm.conf /sysroot/etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /sysroot/etc/lvm/lvmlocal.conf +fi if [ -x /sysroot/usr/sbin/matchpathcon ] && grep -Eq '^SELINUX=(enforcing|permissive)' /sysroot/etc/selinux/config 2> /dev/null; then # Files written to /sysroot before policy load are unlabeled. selinuxpolicy=$(sed -n 's/^SELINUXTYPE=//p' /sysroot/etc/selinux/config) diff --git a/confluent_osdeploy/el7-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/el7-diskless/profiles/default/scripts/imageboot.sh index 1e82e84d..4ff8517f 100644 --- a/confluent_osdeploy/el7-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/el7-diskless/profiles/default/scripts/imageboot.sh @@ -133,6 +133,10 @@ if [ ${#machineid} -eq 32 ]; then echo $machineid > /sysroot/etc/machine-id chmod 444 /sysroot/etc/machine-id fi +# Do not autoactivate LVM on local disks unless the image sets auto_activation_volume_list +if [ -e /sysroot/etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /sysroot/etc/lvm/lvm.conf /sysroot/etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /sysroot/etc/lvm/lvmlocal.conf +fi if grep installtodisk /proc/cmdline > /dev/null; then . /etc/confluent/functions run_remote installimage diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py index 66b3d38c..195d46ea 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/image2disk.py @@ -193,9 +193,7 @@ def fixup(rootdir, vols): 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': + if arg == 'quiet' or arg.startswith(('console=', 'net.ifnames=', 'biosdevname=')): currcmdline.append(arg) currcmdlinestr = ' '.join(currcmdline) if os.path.exists(grubsyscfg): diff --git a/confluent_osdeploy/el8-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/el8-diskless/profiles/default/scripts/imageboot.sh index 747b28b8..fb599b62 100644 --- a/confluent_osdeploy/el8-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/el8-diskless/profiles/default/scripts/imageboot.sh @@ -137,6 +137,10 @@ if [ ${#machineid} -eq 32 ]; then echo $machineid > /sysroot/etc/machine-id chmod 444 /sysroot/etc/machine-id fi +# Do not autoactivate LVM on local disks unless the image sets auto_activation_volume_list +if [ -e /sysroot/etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /sysroot/etc/lvm/lvm.conf /sysroot/etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /sysroot/etc/lvm/lvmlocal.conf +fi if [ -x /sysroot/usr/sbin/matchpathcon ] && grep -Eq '^SELINUX=(enforcing|permissive)' /sysroot/etc/selinux/config 2> /dev/null; then # Files written to the upper layer before policy load are unlabeled. # Label only those, using globstar since the initramfs has no find. diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py b/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py index ce03f84b..a35252e0 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/image2disk.py @@ -213,9 +213,7 @@ def fixup(rootdir, vols): 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': + if arg == 'quiet' or arg.startswith(('console=', 'net.ifnames=', 'biosdevname=')): currcmdline.append(arg) currcmdlinestr = ' '.join(currcmdline) kcmdline = os.path.join(rootdir, 'etc/kernel/cmdline') @@ -236,6 +234,11 @@ def fixup(rootdir, vols): newkcmdlineent.append(ent) else: newkcmdlineent.append(ent) + # the network configuration written during the install uses the + # interface names of this boot + for arg in currcmdline: + if arg.startswith(('net.ifnames=', 'biosdevname=')) and arg not in newkcmdlineent: + newkcmdlineent.append(arg) with open(kcmdline, 'w') as kcmdlineout: kcmdlineout.write(' '.join(newkcmdlineent) + '\n') for loadent in glob.glob(os.path.join(rootdir, 'boot/loader/entries/*.conf')): @@ -286,7 +289,7 @@ 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"'.format(currcmdlinestr), + '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', ] diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/el9-diskless/profiles/default/scripts/imageboot.sh index c94b25f6..6c9fc7ee 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/imageboot.sh @@ -161,6 +161,10 @@ if [ ${#machineid} -eq 32 ]; then echo $machineid > /sysroot/etc/machine-id chmod 444 /sysroot/etc/machine-id fi +# Do not autoactivate LVM on local disks unless the image sets auto_activation_volume_list +if [ -e /sysroot/etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /sysroot/etc/lvm/lvm.conf /sysroot/etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /sysroot/etc/lvm/lvmlocal.conf +fi rm -f /sysroot/etc/dracut.conf.d/diskless.conf # remove diskless dracut from runtime, to make kdump happier if [ -x /sysroot/usr/sbin/matchpathcon ] && grep -Eq '^SELINUX=(enforcing|permissive)' /sysroot/etc/selinux/config 2> /dev/null; then # Files written to /sysroot before policy load are unlabeled. diff --git a/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage b/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage index bec197a3..8ce648b1 100644 --- a/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage +++ b/confluent_osdeploy/el9-diskless/profiles/default/scripts/installimage @@ -25,8 +25,6 @@ else done fi cd /sysroot/run -[ -f /run/sshd.pid ] && -cp /run/sshd.pid /tmp/dbgssh.pid chmod 0600 /sysroot/etc/ssh/ssh*key chroot /sysroot/ bash -c "/usr/sbin/sshd" chroot /sysroot/ bash -c "source /etc/confluent/functions; run_remote_python getinstalldisk" @@ -36,7 +34,7 @@ for nameserver in $(sed -n '/^nameservers:/,/^[^-]/p' /etc/confluent/confluent.d done if [ ! -f /sysroot/tmp/installdisk ]; then - echo 'Unable to find a suitable installation target device, ssh to port 2222 to investigate' + echo 'Unable to find a suitable installation target device, ssh to port 22, or 2222 with debugssh, to investigate' while [ ! -f /sysroot/tmp/installdisk ]; do sleep 1 done @@ -49,11 +47,14 @@ if [ -f /sysroot/etc/lvm/devices/system.devices ]; then fi chroot /sysroot /usr/lib/systemd/systemd-udevd --daemon chroot /sysroot bash -c "source /etc/confluent/functions; run_remote_python image2disk.py" -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 $(cat /sysroot/var/run/sshd.pid) -[ -f /tmp/dbgssh.pid ] && kill -HUP $(cat /tmp/dbgssh.pid) +sshdpid=$(cat /sysroot/var/run/sshd.pid) +kill $sshdpid +# wait for the old sshd to release port 22 +for i in {1..50}; do kill -0 $sshdpid 2> /dev/null || break; sleep 0.1; done +# Serve the install target on port 22 for the syncfiles push of post.sh. Use +# the sshd of the image: the initramfs sshd only runs with debugssh and may +# lack helpers of the image's OpenSSH version, like sshd-session +chroot /sysroot /usr/sbin/sshd -p 22 -o ChrootDirectory=/run/imginst/targ 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/suse15-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/suse15-diskless/profiles/default/scripts/imageboot.sh index 5e077464..a83ba995 100644 --- a/confluent_osdeploy/suse15-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/suse15-diskless/profiles/default/scripts/imageboot.sh @@ -121,6 +121,10 @@ if [ ${#machineid} -eq 32 ]; then echo $machineid > /sysroot/etc/machine-id chmod 444 /sysroot/etc/machine-id fi +# Do not autoactivate LVM on local disks unless the image sets auto_activation_volume_list +if [ -e /sysroot/etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /sysroot/etc/lvm/lvm.conf /sysroot/etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /sysroot/etc/lvm/lvmlocal.conf +fi nameserversec=0 nameservers="" diff --git a/confluent_osdeploy/suse16-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/suse16-diskless/profiles/default/scripts/imageboot.sh index 2c47b672..875421b1 100644 --- a/confluent_osdeploy/suse16-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/suse16-diskless/profiles/default/scripts/imageboot.sh @@ -121,6 +121,10 @@ if [ ${#machineid} -eq 32 ]; then echo $machineid > /sysroot/etc/machine-id chmod 444 /sysroot/etc/machine-id fi +# Do not autoactivate LVM on local disks unless the image sets auto_activation_volume_list +if [ -e /sysroot/etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /sysroot/etc/lvm/lvm.conf /sysroot/etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /sysroot/etc/lvm/lvmlocal.conf +fi # Hand NetworkManager the connection the initramfs is already using. Without # this it claims the interface on its own terms and the tethered root diff --git a/confluent_osdeploy/ubuntu20.04-diskless/initramfs/conf/conf.d/confluent b/confluent_osdeploy/ubuntu20.04-diskless/initramfs/conf/conf.d/confluent index 79787074..561880b0 100644 --- a/confluent_osdeploy/ubuntu20.04-diskless/initramfs/conf/conf.d/confluent +++ b/confluent_osdeploy/ubuntu20.04-diskless/initramfs/conf/conf.d/confluent @@ -7,3 +7,7 @@ if ! grep console= /proc/cmdline > /dev/null; then fi fi echo . /scripts/init-premount/confluent >> /scripts/init-premount/ORDER +# Same as imageboot.sh, but for the lvm2 udev rules in this initramfs +if [ -e /etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /etc/lvm/lvm.conf /etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /etc/lvm/lvmlocal.conf +fi diff --git a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh index ef029575..3828e671 100644 --- a/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh +++ b/confluent_osdeploy/ubuntu20.04-diskless/profiles/default/scripts/imageboot.sh @@ -208,6 +208,10 @@ else hostname | sha512sum | head -c 32 > /sysroot/etc/machine-id fi echo >> /sysroot/etc/machine-id +# Do not autoactivate LVM on local disks unless the image sets auto_activation_volume_list +if [ -e /sysroot/etc/lvm/lvm.conf ] && ! grep -qs '^[[:space:]]*auto_activation_volume_list' /sysroot/etc/lvm/lvm.conf /sysroot/etc/lvm/lvmlocal.conf; then + printf 'activation {\n\tauto_activation_volume_list = []\n}\n' >> /sysroot/etc/lvm/lvmlocal.conf +fi ipv4=$(grep ^ipv4_address: /etc/confluent/confluent.deploycfg | awk '{print $2}') ipv4method=$(grep ^ipv4_method: /etc/confluent/confluent.deploycfg | awk '{print $2}') ipv4gateway=$(grep ^ipv4_gateway: /etc/confluent/confluent.deploycfg | awk '{print $2}') diff --git a/imgutil/el9/dracut/install b/imgutil/el9/dracut/install index d935f2a7..7c339109 100644 --- a/imgutil/el9/dracut/install +++ b/imgutil/el9/dracut/install @@ -8,6 +8,7 @@ dracut_install -o unsquashfs # optional, imageboot extracts with cp when absent dracut_install modprobe touch echo cut wc bash uniq grep ip hostname dracut_install awk egrep dirname expr sort dracut_install ssh sshd reboot parted mkfs mkfs.ext4 mkfs.xfs xfs_db mkswap +dracut_install -o /usr/libexec/openssh/sshd-session # OpenSSH 9.8 and later, EL 9.8 has 9.9 dracut_install efibootmgr uuidgen dracut_install du df ssh-keygen scp dhclient dracut_install /lib64/libnss_dns*