diff options
author | Simon Rettberg | 2024-01-25 15:47:09 +0100 |
---|---|---|
committer | Simon Rettberg | 2024-01-29 09:53:08 +0100 |
commit | abb148916593de63554ef58c53cb1dd8fbbb0ab1 (patch) | |
tree | d8c640c33f699f3abc567d9bbf111190c779b7d2 | |
parent | [dnbd3-rootfs] Try optimized ext4 mount options if none are given (diff) | |
download | systemd-init-abb148916593de63554ef58c53cb1dd8fbbb0ab1.tar.gz systemd-init-abb148916593de63554ef58c53cb1dd8fbbb0ab1.tar.xz systemd-init-abb148916593de63554ef58c53cb1dd8fbbb0ab1.zip |
Try to use more systemd services
76 files changed, 522 insertions, 216 deletions
diff --git a/build-initramfs.sh b/build-initramfs.sh index e6f435bc..e41a642a 100755 --- a/build-initramfs.sh +++ b/build-initramfs.sh @@ -42,8 +42,8 @@ fi declare -A core_repo=( [handler]="git" [path]="$_repo_dir" - [url]="git://git.openslx.org/openslx-ng/systemd-init.git" - [branch]="downloader-cmake-refactor" + [url]="https://git.openslx.org/openslx-ng/systemd-init.git" + [branch]="master" ) declare -A core_dracut=( @@ -55,7 +55,7 @@ declare -A core_dracut=( declare -A module_dnbd3=( [handler]="git" [path]="${_repo_dir}/modules.d/dnbd3-rootfs/binaries/dnbd3" - [url]="git://git.openslx.org/dnbd3.git" + [url]="https://git.openslx.org/dnbd3.git" ) declare -A module_xloop=( diff --git a/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/example.service b/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/example.service index 83310c1d..666cc9c3 100644 --- a/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/example.service +++ b/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/example.service @@ -6,5 +6,4 @@ DefaultDependencies=no [Service] Type=oneshot RemainAfterExit=true -KillMode=none ExecStart=/usr/bin/bash -c '/usr/bin/echo test >/tmp/test-output.txt' diff --git a/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/multi-user.target.wants/example.service b/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/multi-user.target.wants/example.service index 83310c1d..666cc9c3 100644 --- a/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/multi-user.target.wants/example.service +++ b/dev-tools/exampleDracutModule/source/usr/lib/systemd/system/multi-user.target.wants/example.service @@ -6,5 +6,4 @@ DefaultDependencies=no [Service] Type=oneshot RemainAfterExit=true -KillMode=none ExecStart=/usr/bin/bash -c '/usr/bin/echo test >/tmp/test-output.txt' diff --git a/modules.d/busybox/install-busybox-stage4.sh b/modules.d/busybox/install-busybox-stage4.sh index bcd1f94d..bcd1f94d 100644..100755 --- a/modules.d/busybox/install-busybox-stage4.sh +++ b/modules.d/busybox/install-busybox-stage4.sh diff --git a/modules.d/busybox/install-busybox.sh b/modules.d/busybox/install-busybox.sh index 6848a735..d4606590 100644..100755 --- a/modules.d/busybox/install-busybox.sh +++ b/modules.d/busybox/install-busybox.sh @@ -1,7 +1,7 @@ #!/bin/bash -if hash busybox; then - busybox --install -s +if hash busybox && busybox --install -s; then + echo "Busybox installed" else . /lib/dracut-lib.sh emergency_shell "Failed to initialize busybox, things will go wrong..." diff --git a/modules.d/busybox/module-setup.sh b/modules.d/busybox/module-setup.sh index c2305e32..c2305e32 100644..100755 --- a/modules.d/busybox/module-setup.sh +++ b/modules.d/busybox/module-setup.sh diff --git a/modules.d/conf-tgz/hooks/fetch-config-tgz.sh b/modules.d/conf-tgz/hooks/s3-fetch-config-tgz.sh index 5fa96de7..2ed5f579 100755 --- a/modules.d/conf-tgz/hooks/fetch-config-tgz.sh +++ b/modules.d/conf-tgz/hooks/s3-fetch-config-tgz.sh @@ -7,7 +7,7 @@ type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh if [ -z "$SLX_NO_CONFIG_TGZ" ]; then # build config.tgz url from SLX_KCL_SERVERS and SLX_BASE_PATH - # both are written to /etc/openslx by dnbd3-rootfs's fetch-config.sh script + # both are written to /etc/openslx by dnbd3-rootfs's s3-fetch-config.sh script conftgz_url="http://${SLX_KCL_SERVERS}/${SLX_BASE_PATH}/config.tgz" # check if system's uuid was set diff --git a/modules.d/dnbd3-rootfs/hooks/fetch-config.sh b/modules.d/conf-tgz/hooks/s3-fetch-config.sh index 021a4c06..021a4c06 100755 --- a/modules.d/dnbd3-rootfs/hooks/fetch-config.sh +++ b/modules.d/conf-tgz/hooks/s3-fetch-config.sh diff --git a/modules.d/conf-tgz/hooks/unpack-config-tgz.sh b/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh index 2132423c..2132423c 100755 --- a/modules.d/conf-tgz/hooks/unpack-config-tgz.sh +++ b/modules.d/conf-tgz/hooks/s3-unpack-config-tgz.sh diff --git a/modules.d/conf-tgz/module-setup.sh b/modules.d/conf-tgz/module-setup.sh index e6edd1e0..29aae9ea 100755 --- a/modules.d/conf-tgz/module-setup.sh +++ b/modules.d/conf-tgz/module-setup.sh @@ -1,14 +1,26 @@ #!/usr/bin/env bash + check() { - return 255 + return 255 } depends() { - echo dnbd3-rootfs slx-tools + echo dnbd3-rootfs slx-tools } install() { - inst_hook pre-mount 20 "$moddir/hooks/fetch-config-tgz.sh" - # do NOT FUCKING CHANGE THIS - inst_hook pre-pivot 90 "$moddir/hooks/unpack-config-tgz.sh" - # TODO check if busybox is enough - inst_multiple tar mktemp gzip + inst_multiple tar mktemp gzip + + for _name in "s3-fetch-config" "s3-fetch-config-tgz" "s3-unpack-config-tgz"; do + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-pivot.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-pivot.service.requires/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-mount.service.wants" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-mount.service.wants/${_name}.service" + done } diff --git a/modules.d/conf-tgz/services/s3-fetch-config-tgz.service b/modules.d/conf-tgz/services/s3-fetch-config-tgz.service new file mode 100644 index 00000000..60d2b774 --- /dev/null +++ b/modules.d/conf-tgz/services/s3-fetch-config-tgz.service @@ -0,0 +1,13 @@ +[Unit] +Description=Download config.tgz +Requires=s3-setup-bootif-network.service +After=s3-setup-bootif-network.service +Wants=s3-fetch-config.service +After=s3-fetch-config.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-fetch-config-tgz.sh diff --git a/modules.d/conf-tgz/services/s3-fetch-config.service b/modules.d/conf-tgz/services/s3-fetch-config.service new file mode 100644 index 00000000..9d602899 --- /dev/null +++ b/modules.d/conf-tgz/services/s3-fetch-config.service @@ -0,0 +1,13 @@ +[Unit] +Description=Download config +Requires=s3-setup-bootif-network.service +After=s3-setup-bootif-network.service +Wants=s3-get-system-uuid.service +After=s3-get-system-uuid.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-fetch-config.sh diff --git a/modules.d/conf-tgz/services/s3-unpack-config-tgz.service b/modules.d/conf-tgz/services/s3-unpack-config-tgz.service new file mode 100644 index 00000000..d3b9a3e0 --- /dev/null +++ b/modules.d/conf-tgz/services/s3-unpack-config-tgz.service @@ -0,0 +1,12 @@ +[Unit] +Description=Unpack config.tgz to stage 4 +After=initrd-root-fs.target +Requires=s3-fetch-config-tgz.service +After=s3-fetch-config-tgz.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-unpack-config-tgz.sh diff --git a/modules.d/dnbd3-rootfs/configuration/systemd-newroot.conf b/modules.d/dnbd3-rootfs/configuration/systemd-newroot.conf new file mode 100644 index 00000000..6e02fad5 --- /dev/null +++ b/modules.d/dnbd3-rootfs/configuration/systemd-newroot.conf @@ -0,0 +1,2 @@ +[Manager] +DefaultEnvironment="NEWROOT=/sysroot" diff --git a/modules.d/dnbd3-rootfs/hooks/copy-dnbd3-files-into-newroot.sh b/modules.d/dnbd3-rootfs/hooks/copy-dnbd3-files-into-newroot.sh deleted file mode 100755 index 2ff8664f..00000000 --- a/modules.d/dnbd3-rootfs/hooks/copy-dnbd3-files-into-newroot.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -# -*- coding: utf-8 -*- - -# copy dnbd3root.service to NEWROOT to ensure it stays known to systemd -systemd_system_unit_path="$(dirname \ - "$(systemctl show -p FragmentPath dracut-mount.service | cut -c 14-)")" -new_systemd_system_unit_path="${NEWROOT}/lib/systemd/system" -cp "${systemd_system_unit_path}/dnbd3root.service" \ - "${new_systemd_system_unit_path}/dnbd3root.service" -mkdir --parents "${new_systemd_system_unit_path}/sysinit.target.wants" -ln --symbolic '../dnbd3root.service' \ - "${new_systemd_system_unit_path}/sysinit.target.wants/dnbd3root.service" - -# copy dnbd3-client binary to NEWROOT to make sure it is compatible with the -# kernel module -dnbd3_client_path="$(type -p dnbd3-client)" -if [ -n "$dnbd3_client_path" ]; then - mkdir -p "${NEWROOT}/${dnbd3_client_path%/*}" - cp "$dnbd3_client_path" "${NEWROOT}/${dnbd3_client_path}" -fi -true diff --git a/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh b/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh index d0e847ca..58f23207 100755 --- a/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh +++ b/modules.d/dnbd3-rootfs/hooks/copy-dracut-systemd-files-into-newroot.sh @@ -2,27 +2,20 @@ # -*- coding: utf-8 -*- type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh -# Dracut may not be installed on the new root. Thus copy all services over. -dracut_mount_unit_path="$(systemctl show -p FragmentPath dracut-mount.service \ - | cut -c 14-)" -systemd_system_unit_path="${dracut_mount_unit_path%/*}" +# Copy out services over to stage 4, so they still appear in +# systemd-analyze plot etc. new_systemd_system_unit_path="${NEWROOT}/lib/systemd/system" mkdir --parents "$new_systemd_system_unit_path/initrd.target.wants" -for file in \ - dracut-cmdline.service \ - dracut-initqueue.service \ - dracut-mount.service \ - dracut-pre-mount.service \ - dracut-pre-pivot.service \ - dracut-pre-trigger.service \ - dracut-pre-udev.service -do - cp "${systemd_system_unit_path}/${file}" \ - "${new_systemd_system_unit_path}/${file}" - # "ln" returns an error if the link already exists. - source_path="../${file}" - target_path="${new_systemd_system_unit_path}/initrd.target.wants/${file}" - ln --symbolic "$source_path" "$target_path" &>/dev/null || \ - warn "Failed to link \"$source_path\" to \"$target_path\"." + +for dir in /run/systemd/system /lib/systemd/system /etc/systemd/system; do + for file in "$dir"/s3-*.{service,target} "$dir"/dracut-*.{service,target}; do + [ -f "$file" ] || continue + name="${file##*/}" + cp "${file}" "${new_systemd_system_unit_path}/${name}" + source_path="../${name}" + target_path="${new_systemd_system_unit_path}/initrd.target.wants/${name}" + ln -nfs "$source_path" "$target_path" || \ + warn "Failed to link \"$source_path\" to \"$target_path\"." + done done diff --git a/modules.d/dnbd3-rootfs/hooks/load-custom-kernel-modules.sh b/modules.d/dnbd3-rootfs/hooks/load-custom-kernel-modules.sh deleted file mode 100755 index c9ea106a..00000000 --- a/modules.d/dnbd3-rootfs/hooks/load-custom-kernel-modules.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -# -*- coding: utf-8 -*- -type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh -for kmod in dnbd3 \ - xloop \ - xloop_file_fmt_qcow \ - xloop_file_fmt_raw; do - if ! modprobe ${kmod}; then - warn "Failed to load kernel module: $kmod" - ! : - fi -done diff --git a/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh b/modules.d/dnbd3-rootfs/hooks/s3-copy-openslx-config.sh index 7e2b74e3..bedceb85 100755 --- a/modules.d/dnbd3-rootfs/hooks/copy-openslx-configuration-into-newroot.sh +++ b/modules.d/dnbd3-rootfs/hooks/s3-copy-openslx-config.sh @@ -27,15 +27,17 @@ source "/etc/openslx" mkdir --parents "${NEWROOT}/opt/openslx" -cp "/etc/openslx" "${NEWROOT}/opt/openslx/config" - -echo "## Generated by '$0' in stage3" >> "${NEWROOT}/opt/openslx/config" -cat "/run/openslx/network.conf" >> "${NEWROOT}/opt/openslx/config" +{ + cat "/etc/openslx" + echo "## Generated by '$0' in stage3" + cat "/run/openslx/network.conf" +} > "${NEWROOT}/opt/openslx/config" +ln -nfs "${NEWROOT}/opt/openslx/config" "/etc/openslx" # Set root/demo password for stage4, if set if [ -n "${SLX_ROOT_PASS}" ]; then sed -i "s#^root:[^:]*:#root:$SLX_ROOT_PASS:#" "$NEWROOT/etc/shadow" fi -if [ -n "${SLX_DEMO_PASS}" ] && grep -q '^demo' "$NEWROOT/etc/shadow"; then +if [ -n "${SLX_DEMO_PASS}" ] && grep -q '^demo:' "$NEWROOT/etc/shadow"; then sed -i "s#^demo:[^:]*:#demo:$SLX_DEMO_PASS:#" "$NEWROOT/etc/shadow" fi diff --git a/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh b/modules.d/dnbd3-rootfs/hooks/s3-dnbd3root.sh index bef92ce9..01a8c32c 100755 --- a/modules.d/dnbd3-rootfs/hooks/prepare-root-partition.sh +++ b/modules.d/dnbd3-rootfs/hooks/s3-dnbd3root.sh @@ -37,6 +37,11 @@ container_unpack_xmount() { container_unpack_xloop() { local in_device="$1" local out_device="$(xlosetup -f)" + for kmod in xloop xloop_file_fmt_qcow xloop_file_fmt_raw; do + if ! modprobe "${kmod}"; then + warn "Failed to load kernel module: $kmod" + fi + done if ! xlosetup -r -t QCOW "$out_device" "$in_device" --partscan; then warn "Failed to attach '$in_device' to '$out_device'." return @@ -68,7 +73,10 @@ if [ -n "$SLX_DNBD3_RID" ]; then _dnbd3_client_additional_args=("--rid" "$SLX_DNBD3_RID") fi -IFS=", " +if ! modprobe dnbd3; then + warn "Failed to load kernel module: dnbd3" +fi + for try in {1..5} ""; do if [ -z "$try" ]; then emergency_shell "Failed to connect '${SLX_DNBD3_IMAGE}'" \ @@ -141,4 +149,5 @@ info "Using read-only partition: $read_only_partition" # region add rw layer to dnbd3 image # don't be fooled to think we are done, the next part is crucial dmsetup-slx-device "$read_only_partition" +udevadm settle # endregion diff --git a/modules.d/dnbd3-rootfs/hooks/mount-root-device.sh b/modules.d/dnbd3-rootfs/hooks/s3-mount-root.sh index 73d947d0..11ea46e3 100755 --- a/modules.d/dnbd3-rootfs/hooks/mount-root-device.sh +++ b/modules.d/dnbd3-rootfs/hooks/s3-mount-root.sh @@ -1,6 +1,18 @@ +#!/bin/bash + type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh source "/etc/openslx" + +cnt=0 +while ! [ -b "$SLX_DNBD3_DEVICE_COW" ] \ + || ! [ "$( blockdev --getsize64 "$SLX_DNBD3_DEVICE_COW" 2> /dev/null )" -gt 0 ]; do + (( ++cnt > 20 )) && break + (( cnt % 5 == 0 )) && echo "Waiting for block device...." + usleep 100000 + (( cnt > 10 )) && udevadm trigger && udevadm settle +done + ret=99 if [ -n "$SLX_MOUNT_ROOT_OPTIONS" ]; then # Always prefer mount options mandated by server @@ -17,10 +29,11 @@ else fi fi +(( ret != 0 )) && exit $ret + if [ -n "$SLX_GENERATE_FSTAB_SCRIPT" ]; then eval "$SLX_GENERATE_FSTAB_SCRIPT" else echo "" > "$NEWROOT/etc/fstab" fi - -return $ret +true diff --git a/modules.d/dnbd3-rootfs/hooks/shutdown-umount.sh b/modules.d/dnbd3-rootfs/hooks/shutdown-umount.sh index ab78733c..ab78733c 100644..100755 --- a/modules.d/dnbd3-rootfs/hooks/shutdown-umount.sh +++ b/modules.d/dnbd3-rootfs/hooks/shutdown-umount.sh diff --git a/modules.d/dnbd3-rootfs/module-setup.sh b/modules.d/dnbd3-rootfs/module-setup.sh index eb5a4390..ce1b4b36 100755 --- a/modules.d/dnbd3-rootfs/module-setup.sh +++ b/modules.d/dnbd3-rootfs/module-setup.sh @@ -147,41 +147,49 @@ install() { dracut_module_included "network" && inst_hook cmdline 10 \ "$moddir/hooks/prepare-kernel-command-line-parameter.sh" inst_hook cmdline 90 "$moddir/hooks/set-dracut-environment-variables.sh" - inst_hook pre-udev 00 "$moddir/hooks/load-custom-kernel-modules.sh" - # Get the openslx config from the servers configured in the kernel command line. - inst_hook pre-mount 10 "$moddir/hooks/fetch-config.sh" # make the final blockdevice for the root system (dnbd3 -> xmount -> # device-mapper) - if dracut_module_included "systemd-initrd"; then - inst "$moddir/hooks/prepare-root-partition.sh" \ - /usr/local/bin/dnbd3root - inst_simple "${moddir}/services/dnbd3root.service" \ - "${systemdsystemunitdir}/dnbd3root.service" - mkdir --parents \ - "${initdir}/${systemdsystemunitdir}/dracut-mount.service.requires" - ln_r "${systemdsystemunitdir}/dnbd3root.service" \ - "${systemdsystemunitdir}/dracut-mount.service.requires/dnbd3root.service" - mkdir --parents \ - "${initdir}/${systemdsystemunitdir}/initrd.target.requires" - ln_r "${systemdsystemunitdir}/dnbd3root.service" \ - "${systemdsystemunitdir}/initrd.target.requires/dnbd3root.service" - # Copy systemd services to new root (so they don't get killed after - # switch_root) - inst_hook pre-pivot 00 \ - "$moddir/hooks/copy-dnbd3-files-into-newroot.sh" - inst_hook pre-pivot 00 \ - "$moddir/hooks/copy-dracut-systemd-files-into-newroot.sh" - inst_hook pre-shutdown 00 "$moddir/hooks/shutdown-umount.sh" - else - inst_hook pre-mount 10 "$moddir/hooks/prepare-root-partition.sh" - fi - inst_hook mount 10 "$moddir/hooks/mount-root-device.sh" - inst_hook pre-pivot 00 \ - "$moddir/hooks/copy-openslx-configuration-into-newroot.sh" + inst "$moddir/hooks/s3-dnbd3root.sh" \ + /usr/local/bin/s3-dnbd3root.sh + inst_simple "${moddir}/services/s3-dnbd3root.service" \ + "${systemdsystemunitdir}/s3-dnbd3root.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/initrd-root-device.target.requires" + ln_r "${systemdsystemunitdir}/s3-dnbd3root.service" \ + "${systemdsystemunitdir}/initrd-root-device.target.requires/s3-dnbd3root.service" + # Mount the root file system + inst "$moddir/hooks/s3-mount-root.sh" \ + /usr/local/bin/s3-mount-root.sh + inst_simple "${moddir}/services/s3-mount-root.service" \ + "${systemdsystemunitdir}/s3-mount-root.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/initrd-root-fs.target.requires" + ln_r "${systemdsystemunitdir}/s3-mount-root.service" \ + "${systemdsystemunitdir}/initrd-root-fs.target.requires/s3-mount-root.service" + # Copy /opt/openslx/config to newroot + inst "$moddir/hooks/s3-copy-openslx-config.sh" \ + /usr/local/bin/s3-copy-openslx-config.sh + inst_simple "${moddir}/services/s3-copy-openslx-config.service" \ + "${systemdsystemunitdir}/s3-copy-openslx-config.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/initrd.target.requires" + ln_r "${systemdsystemunitdir}/s3-copy-openslx-config.service" \ + "${systemdsystemunitdir}/initrd.target.requires/s3-copy-openslx-config.service" + # Copy systemd services to new root (so they don't get killed after + # switch_root) + inst_hook pre-pivot 90 \ + "$moddir/hooks/copy-dracut-systemd-files-into-newroot.sh" + #inst_hook pre-shutdown 00 "$moddir/hooks/shutdown-umount.sh" + #inst_hook pre-pivot 00 \ + # "$moddir/hooks/copy-openslx-configuration-into-newroot.sh" # endregion # region scripts # endregion # region configuration files + mkdir --parents \ + "${initdir}/etc/systemd/system.conf.d" + inst "$moddir/configuration/systemd-newroot.conf" \ + "/etc/systemd/system.conf.d/systemd-newroot.conf" # Use terminal readline settings from the template system. inst /etc/inputrc /etc/inputrc # Set some aliases for the initramfs context. diff --git a/modules.d/dnbd3-rootfs/services/dnbd3root.service b/modules.d/dnbd3-rootfs/services/dnbd3root.service deleted file mode 100644 index df079576..00000000 --- a/modules.d/dnbd3-rootfs/services/dnbd3root.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=root fs on dnbd3 (distributed network block device) -After=dracut-pre-mount.service network.target -Before=dracut-mount.service -DefaultDependencies=no -IgnoreOnIsolate=true - -[Service] -Type=oneshot -RemainAfterExit=true -KillMode=none -ExecStart=/usr/local/bin/dnbd3root diff --git a/modules.d/dnbd3-rootfs/services/s3-copy-openslx-config.service b/modules.d/dnbd3-rootfs/services/s3-copy-openslx-config.service new file mode 100644 index 00000000..41de7fe3 --- /dev/null +++ b/modules.d/dnbd3-rootfs/services/s3-copy-openslx-config.service @@ -0,0 +1,11 @@ +[Unit] +Description=Copy final /opt/openslx/config to /sysroot +Requires=initrd-root-fs.target +After=initrd-root-fs.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-copy-openslx-config.sh diff --git a/modules.d/dnbd3-rootfs/services/s3-dnbd3root.service b/modules.d/dnbd3-rootfs/services/s3-dnbd3root.service new file mode 100644 index 00000000..3197a9cc --- /dev/null +++ b/modules.d/dnbd3-rootfs/services/s3-dnbd3root.service @@ -0,0 +1,15 @@ +[Unit] +Description=root fs on dnbd3 (distributed network block device) +Requires=s3-fetch-config.service +After=s3-fetch-config.service +After=dracut-pre-mount.service +Wants=dracut-mount.service +Before=dracut-mount.service +Before=initrd-root-device.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-dnbd3root.sh diff --git a/modules.d/dnbd3-rootfs/services/s3-mount-root.service b/modules.d/dnbd3-rootfs/services/s3-mount-root.service new file mode 100644 index 00000000..626e21f4 --- /dev/null +++ b/modules.d/dnbd3-rootfs/services/s3-mount-root.service @@ -0,0 +1,12 @@ +[Unit] +Description=Mount dnbd3/devmapped device to /sysroot +Requires=initrd-root-device.target +After=initrd-root-device.target +Before=initrd-root-fs.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-mount-root.sh diff --git a/modules.d/haveged/module-setup.sh b/modules.d/haveged/module-setup.sh index 6cd1e1b8..6cd1e1b8 100644..100755 --- a/modules.d/haveged/module-setup.sh +++ b/modules.d/haveged/module-setup.sh diff --git a/modules.d/slx-addons/scripts/setup-addons.sh b/modules.d/slx-addons/hooks/s3-setup-addons.sh index d4b94a1a..0a947f23 100644..100755 --- a/modules.d/slx-addons/scripts/setup-addons.sh +++ b/modules.d/slx-addons/hooks/s3-setup-addons.sh @@ -37,7 +37,7 @@ fi # Since addons are likely to install libs, this is necessary to garantee # that the live system "sees" the libraries. activate_stage4_ldconfig() { - local service_path="/opt/openslx/services/ldconfig.service" + local service_path="/opt/openslx/services/ldconfig-stage4.service" [ -e "$service_path" ] || return 1 local target_dir="${NEWROOT}/etc/systemd/system/sysinit.target.wants" mkdir -p "$target_dir" @@ -51,7 +51,7 @@ setup_addon() { return 1 fi local addon_dir="$1" - cd "$addon_dir" + cd "$addon_dir" || return 1 if ! bash addon-required 2>&1 ; then info "'$addon_dir/addon-required' missing or returned non-zero, skipping..." return 1 @@ -60,7 +60,8 @@ setup_addon() { rm -f -- addon-* # move all the files over - for entry in $(find * -not -type d 2>/dev/null); do + find . -not -type d 2>/dev/null | while read -r entry || [ -n "$entry" ]; do + entry="${entry#./}" [ "$entry" != "${entry%/*}" ] && mkdir -p "${NEWROOT}/${entry%/*}" mv -f -- "$entry" "${NEWROOT}/${entry}" done @@ -69,8 +70,8 @@ setup_addon() { # (e.g. they were removed during the addon installation) for WHITEOUT in "$NEWROOT/opt/openslx/etc/"*.whiteout; do [ -e "$WHITEOUT" ] || continue - while read line; do - rm -f "${NEWROOT}/${line}" + while read -r line; do + rm -f -- "${NEWROOT}/${line}" done < "$WHITEOUT" done @@ -80,7 +81,7 @@ setup_addon() { active=() for addon in "${NEWROOT}/opt/openslx/addons/"*; do if setup_addon "$addon"; then - active+=("${addon#${NEWROOT}/opt/openslx/addons/}") + active+=("${addon#"${NEWROOT}/opt/openslx/addons/"}") info "Activated '$addon' (@ $(date +%s))" fi done @@ -95,7 +96,7 @@ if [ "${#active[@]}" -eq 1 ]; then mv -f -- "$addon_cache" "${NEWROOT}/etc/ld.so.cache" fi elif [ "${#active[@]}" -gt 1 ]; then - info "Activating ldconfig in stage4 due to multiple loaded addons: ${active[@]}" + info "Activating ldconfig in stage4 due to multiple loaded addons: ${active[*]}" activate_stage4_ldconfig fi diff --git a/modules.d/slx-addons/module-setup.sh b/modules.d/slx-addons/module-setup.sh index 7a2d78aa..5d84584c 100755 --- a/modules.d/slx-addons/module-setup.sh +++ b/modules.d/slx-addons/module-setup.sh @@ -8,7 +8,16 @@ depends() { echo dnbd3-rootfs } install() { - inst_hook pre-pivot 70 "$moddir/scripts/setup-addons.sh" - inst "${moddir}/services/ldconfig.service" \ - "/opt/openslx/services/ldconfig.service" + inst "${moddir}/services/ldconfig-stage4.service" \ + "/opt/openslx/services/ldconfig-stage4.service" + # Install service that enables addons + _name="s3-setup-addons" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-pivot.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-pivot.service.requires/${_name}.service" } diff --git a/modules.d/slx-addons/services/ldconfig.service b/modules.d/slx-addons/services/ldconfig-stage4.service index be799e66..be799e66 100644 --- a/modules.d/slx-addons/services/ldconfig.service +++ b/modules.d/slx-addons/services/ldconfig-stage4.service diff --git a/modules.d/slx-addons/services/s3-setup-addons.service b/modules.d/slx-addons/services/s3-setup-addons.service new file mode 100644 index 00000000..ee6c203b --- /dev/null +++ b/modules.d/slx-addons/services/s3-setup-addons.service @@ -0,0 +1,11 @@ +[Unit] +Description=Enable SLX addons +After=initrd-root-fs.target +Before=initrd-switch-root.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-setup-addons.sh diff --git a/modules.d/slx-clock/scripts/configure-timesyncd.sh b/modules.d/slx-clock/hooks/s3-configure-timesyncd.sh index 77541ab0..77541ab0 100644..100755 --- a/modules.d/slx-clock/scripts/configure-timesyncd.sh +++ b/modules.d/slx-clock/hooks/s3-configure-timesyncd.sh diff --git a/modules.d/slx-clock/scripts/ntp-sync.sh b/modules.d/slx-clock/hooks/s3-ntp-sync.sh index a533353c..96e72c04 100755 --- a/modules.d/slx-clock/scripts/ntp-sync.sh +++ b/modules.d/slx-clock/hooks/s3-ntp-sync.sh @@ -50,11 +50,4 @@ ntp_sync() { echo "Timesync finished" } -if command -v systemd-cat > /dev/null; then - ntp_sync 2>&1 | systemd-cat -else - ntp_sync -fi - -true - +ntp_sync diff --git a/modules.d/slx-clock/module-setup.sh b/modules.d/slx-clock/module-setup.sh index f9ff0c48..3b62089c 100755 --- a/modules.d/slx-clock/module-setup.sh +++ b/modules.d/slx-clock/module-setup.sh @@ -8,16 +8,16 @@ depends() { echo dnbd3-rootfs busybox } install() { - # see where systemd-cat is installed - local sdc_bin="$( command -v systemd-cat )" - if [ -z "$sdc_bin" ]; then - warn "Could not find systemd-cat in $PATH. Check if its installed." - return 1 - fi - # wait til we have the openslx config for ntp servers - # which happens in pre-mount/10 - inst_multiple "/etc/services" "/usr/share/zoneinfo/Europe/Berlin" "$sdc_bin" + inst_multiple "/etc/services" "/usr/share/zoneinfo/Europe/Berlin" inst "/usr/share/zoneinfo/Europe/Berlin" "/etc/localtime" - inst_hook pre-mount 15 "$moddir/scripts/ntp-sync.sh" - inst_hook pre-pivot 15 "$moddir/scripts/configure-timesyncd.sh" + for _name in "s3-setup-addons" "s3-configure-timesyncd"; do + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-pivot.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-pivot.service.requires/${_name}.service" + done } diff --git a/modules.d/slx-clock/services/s3-configure-timesyncd.service b/modules.d/slx-clock/services/s3-configure-timesyncd.service new file mode 100644 index 00000000..c370859a --- /dev/null +++ b/modules.d/slx-clock/services/s3-configure-timesyncd.service @@ -0,0 +1,12 @@ +[Unit] +Description=Configure timesyncd in stage 4 +After=initrd-root-fs.target +After=s3-ntp-sync.service +Before=initrd-switch-root.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-configure-timesyncd.sh diff --git a/modules.d/slx-clock/services/s3-ntp-sync.service b/modules.d/slx-clock/services/s3-ntp-sync.service new file mode 100644 index 00000000..77208d0f --- /dev/null +++ b/modules.d/slx-clock/services/s3-ntp-sync.service @@ -0,0 +1,11 @@ +[Unit] +Description=Sync time via NTP +Requires=s3-setup-bootif-network.service +After=s3-setup-bootif-network.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-ntp-sync.sh diff --git a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device b/modules.d/slx-dmsetup/hooks/dmsetup-slx-device index 195ab3ad..77e51c7d 100755 --- a/modules.d/slx-dmsetup/scripts/dmsetup-slx-device +++ b/modules.d/slx-dmsetup/hooks/dmsetup-slx-device @@ -450,11 +450,16 @@ find_ntfs_partitions() { echo "$0: ntfsfree not found, cannot use NTFS partitions as RW layer" return fi - local part sum + local part sum ro dev ntfs_extra_space_sz=0 for part in /dev/disk/by-partuuid/*; do + # Skip empty/ro devices + dev="$( readlink -f "$part" )" + dev="${dev##*/}" + ro="$( cat "/sys/class/block/${dev}/ro" )" + [ "$ro" = 1 ] && continue # Only count ranges >= 256MB, sum will be in number of 512b blocks - sum="$( ntfsfree --block-size 512 --min-size "$(( 256 * 1024 * 1024 ))" "$part" \ + sum="$( ntfsfree --block-size 512 --min-size "$(( 256 * 1024 * 1024 ))" "$part" 2> /dev/null \ | awk -v sum=0 '{if ($1 == "Range") sum += $4}END{printf "%.0f", sum}' )" # Only consider volume if sum of these ranges > 1GB (this is BLOCKS, not bytes) (( "$sum" > 2 * 1024 * 1024 )) || continue diff --git a/modules.d/slx-dmsetup/scripts/grow-rootfs.sh b/modules.d/slx-dmsetup/hooks/s3-grow-rootfs.sh index e2603835..b93c5658 100644..100755 --- a/modules.d/slx-dmsetup/scripts/grow-rootfs.sh +++ b/modules.d/slx-dmsetup/hooks/s3-grow-rootfs.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This tried to call growfs helpers (xfs_growfs, resize2fs, ...) to resize +# This tries to call growfs helpers (xfs_growfs, resize2fs, ...) to resize # the root filesystem mounted on $NEWROOT to the maximum size of the backing # disk partition (done by dmsetup-slx-device). @@ -38,7 +38,7 @@ resize_rootfs() { return 1 fi return 0 -} &> /run/openslx/rootfs-grow.log +} [ -b "$SLX_DNBD3_DEVICE_COW" ] && resize_rootfs # non-critical, so always fake success diff --git a/modules.d/slx-dmsetup/module-setup.sh b/modules.d/slx-dmsetup/module-setup.sh index e478a5f7..3bbbd8f3 100755 --- a/modules.d/slx-dmsetup/module-setup.sh +++ b/modules.d/slx-dmsetup/module-setup.sh @@ -6,9 +6,18 @@ depends() { echo "haveged slx-tools" } install() { - inst "$moddir/scripts/dmsetup-slx-device" "/usr/local/bin/dmsetup-slx-device" + inst "$moddir/hooks/dmsetup-slx-device" "/usr/local/bin/dmsetup-slx-device" - inst_hook pre-pivot 00 "$moddir/scripts/grow-rootfs.sh" + # Grows the rootfs to match the underlying blockdev + _name="s3-grow-rootfs" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/initrd.target.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/initrd.target.requires/${_name}.service" inst_multiple blockdev xxd \ mkfs.ext4 resize2fs \ diff --git a/modules.d/slx-dmsetup/services/s3-grow-rootfs.service b/modules.d/slx-dmsetup/services/s3-grow-rootfs.service new file mode 100644 index 00000000..a849f4a3 --- /dev/null +++ b/modules.d/slx-dmsetup/services/s3-grow-rootfs.service @@ -0,0 +1,12 @@ +[Unit] +Description=Grow size of rootfs to underlying block device +# For ext4, -root-device would be sufficient, but XFS tool needs mountpoint +After=initrd-root-fs.target +Before=initrd-switch-root.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-grow-rootfs.sh diff --git a/modules.d/slx-drm/hooks/activate-nvidia-drivers.sh b/modules.d/slx-drm/hooks/s3-activate-nvidia-drivers.sh index 00c2334a..00c2334a 100644..100755 --- a/modules.d/slx-drm/hooks/activate-nvidia-drivers.sh +++ b/modules.d/slx-drm/hooks/s3-activate-nvidia-drivers.sh diff --git a/modules.d/slx-drm/hooks/copy-nvidia-drivers.sh b/modules.d/slx-drm/hooks/s3-copy-nvidia-drivers.sh index 6e4a8529..5afc71c7 100644..100755 --- a/modules.d/slx-drm/hooks/copy-nvidia-drivers.sh +++ b/modules.d/slx-drm/hooks/s3-copy-nvidia-drivers.sh @@ -1,4 +1,4 @@ -#!/bin/ash +#!/bin/bash # # This script checks whether the nvidia kernel module was loaded by udev # and copies the kernel modules over to stage4 and disables nouveau diff --git a/modules.d/slx-drm/module-setup.sh b/modules.d/slx-drm/module-setup.sh index 4baa5b2a..00ff80a7 100755 --- a/modules.d/slx-drm/module-setup.sh +++ b/modules.d/slx-drm/module-setup.sh @@ -17,6 +17,14 @@ install() { mkdir -p "${initdir}/${dir%/*}" cp -ar "$dir" "${initdir}/${dir%/*}" done - inst_hook pre-udev 10 "${moddir}/hooks/activate-nvidia-drivers.sh" - inst_hook pre-pivot 50 "${moddir}/hooks/copy-nvidia-drivers.sh" + for _name in "s3-activate-nvidia-drivers" "s3-copy-nvidia-drivers"; do + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-pivot.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-pivot.service.requires/${_name}.service" + done } diff --git a/modules.d/slx-drm/services/s3-activate-nvidia-drivers.service b/modules.d/slx-drm/services/s3-activate-nvidia-drivers.service new file mode 100644 index 00000000..4ea86525 --- /dev/null +++ b/modules.d/slx-drm/services/s3-activate-nvidia-drivers.service @@ -0,0 +1,13 @@ +[Unit] +Description=Enable loading of nVidia drivers if a suitable GPU is found +Requires=dracut-cmdline.service +After=dracut-cmdline.service +Before=dracut-pre-udev.service +Wants=dracut-pre-udev.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-activate-nvidia-drivers.sh diff --git a/modules.d/slx-drm/services/s3-copy-nvidia-drivers.service b/modules.d/slx-drm/services/s3-copy-nvidia-drivers.service new file mode 100644 index 00000000..587a1175 --- /dev/null +++ b/modules.d/slx-drm/services/s3-copy-nvidia-drivers.service @@ -0,0 +1,12 @@ +[Unit] +Description=Copy nVidia drivers to stage 4 if in use +After=dracut-mount.service +After=s3-activate-nvidia-drivers.service +Before=initrd-switch-root.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-copy-nvidia-drivers.sh diff --git a/modules.d/slx-network/hooks/activate-bootif-dhcp.sh b/modules.d/slx-network/hooks/activate-stage4-dhcp.sh index 9a5f0b88..8ac1e7b0 100644..100755 --- a/modules.d/slx-network/hooks/activate-bootif-dhcp.sh +++ b/modules.d/slx-network/hooks/activate-stage4-dhcp.sh @@ -9,7 +9,7 @@ if [ "$SLX_STAGE4_DHCP" != "no" ] \ && ! [ -e "${NEWROOT}/opt/openslx/scripts/udhcpc-openslx" ]; then mkdir -p "${NEWROOT}/opt/openslx/scripts" - for script in setup-bootif-network udhcpc-trigger; do + for script in s3-setup-bootif-network udhcpc-trigger; do if [ -e "${NEWROOT}/opt/openslx/scripts/${script}" ]; then mv "${NEWROOT}/opt/openslx/scripts/${script}"{,.stage4} fi diff --git a/modules.d/slx-network/hooks/configure-jumbo-frames.sh b/modules.d/slx-network/hooks/configure-jumbo-frames.sh index 97ac8e9d..97ac8e9d 100644..100755 --- a/modules.d/slx-network/hooks/configure-jumbo-frames.sh +++ b/modules.d/slx-network/hooks/configure-jumbo-frames.sh diff --git a/modules.d/slx-network/hooks/copy-network-files.sh b/modules.d/slx-network/hooks/s3-copy-network-files.sh index 5d28669e..5d28669e 100644..100755 --- a/modules.d/slx-network/hooks/copy-network-files.sh +++ b/modules.d/slx-network/hooks/s3-copy-network-files.sh diff --git a/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh b/modules.d/slx-network/hooks/s3-parse-network-kcl.sh index fec160a8..daf2e9b7 100644..100755 --- a/modules.d/slx-network/hooks/parse-ipxe-network-kcl.sh +++ b/modules.d/slx-network/hooks/s3-parse-network-kcl.sh @@ -28,9 +28,9 @@ parse_kcl_ip() { # parse new style 'ipv4.*=...' parameters parse_kcl_ipv4() { - for param in ip router dns hostname domain search if ntpsrv subnet; do - echo "Getting $param..." + for param in "ip" "router" "dns" "hostname" "domain" "search" "if" "ntpsrv" "subnet"; do local current="$(getarg ipv4.${param}=)" + echo "KCL '$param'='$current'" [ -z "$current" ] && continue declare -g "${param}=${current}" done @@ -86,6 +86,7 @@ save_network_config() { SLX_BRIDGE='${bridged:+${bridge_name}}' SLX_VLAN_ID='$vlan' EOF + echo "network.conf written." } # Create udev rule to rename the PXE boot interface to BOOTIF_NAME @@ -101,17 +102,18 @@ create_udev_bootif_name_rule() { ## MAIN ## parse_kcl -# set hostname asap -[ -n "$hostname" ] && echo "$hostname" > /proc/sys/kernel/hostname +if [ -z "$if" ]; then + emergency_shell "MAC address of primary interface not given on command line" + exit 1 +fi + +# Create the udev rule to rename the boot interface to the declared BOOTIF_NAME +create_udev_bootif_name_rule & # Save network config for later use save_network_config & -# Create the udev rule to rename the boot interface to the declared BOOTIF_NAME -create_udev_bootif_name_rule & +# set hostname asap +[ -n "$hostname" ] && echo "$hostname" > /proc/sys/kernel/hostname wait - -# TODO handle case where the MAC address of the boot interface was not found -/sbin/initqueue --settled /usr/local/bin/setup-bootif-network -/sbin/initqueue --finished [ -e "/.network" ] diff --git a/modules.d/slx-network/scripts/setup-bootif-network.stage3 b/modules.d/slx-network/hooks/s3-setup-bootif-network.sh index 1f8fb9ee..1ae58464 100755 --- a/modules.d/slx-network/scripts/setup-bootif-network.stage3 +++ b/modules.d/slx-network/hooks/s3-setup-bootif-network.sh @@ -10,10 +10,16 @@ type emergency_shell >/dev/null 2>&1 || . /lib/dracut-lib.sh . /run/openslx/network.conf -# do not run until the physical interface is not ready yet -if [ ! -e "/sys/class/net/${SLX_PXE_NETIF}/device" ]; then - exit 1 -fi +# do not run until the physical interface exists (driver loaded) +_fails=0 +while ! [ -e "/sys/class/net/${SLX_PXE_NETIF}/device" ]; do + if (( ++_fails > 20 )); then + emergency_shell "Boot interface '${SLX_PXE_NETIF}' did not appear" + exit 1 + fi + (( (_fails % 5) == 0 )) && udevadm trigger + usleep 500000 +done # wrapper around splashtool to disable it if its not present _splashtool() { @@ -28,21 +34,28 @@ fi wait_for_iface() { local _iface="$1" local _timeout="${2:-50}" + local _fails=0 + local _state if [ "$_iface" = "$SLX_PXE_NETIF" ]; then img="??-nic" elif [ "$_iface" = "$SLX_BRIDGE" ]; then img="??-bridge" fi - while [ "$_timeout" -ne 0 ]; do - [ "$(cat /sys/class/net/${_iface}/operstate)" = "up" ] && break - (( _timeout -- )) + while (( _timeout-- > 0 )); do + _state="$(cat "/sys/class/net/${_iface}/operstate" 2> /dev/null)" + [ "$_state" = "up" ] && break + if (( ++_fails > 5 )) && [[ "$_state" = "unknown" || "$_state" = "" ]]; then + if (( _fails > 10 )) || [ "$(cat "/sys/class/net/${_iface}/carrier" 2> /dev/null)" = "1" ]; then + break + fi + fi # every 500ms usleep 500000 in= - [ "$(( _timeout % 2 ))" = 0 ] && in=in + (( (_timeout % 2) == 0 )) && in=in _splashtool --icon "/opt/openslx/icons/${in}active/${img}.ppm" & done - if [ "$_timeout" -ne 0 ]; then + if (( _timeout > 0 )); then _splashtool --icon "/opt/openslx/icons/active/${img}.ppm" & return 0 else @@ -78,7 +91,7 @@ fi if [ -n "$SLX_BRIDGE" ]; then for try in {1..10} ""; do - ( + if ( set -e brctl addbr "$SLX_BRIDGE" brctl stp "$SLX_BRIDGE" 0 @@ -87,9 +100,7 @@ if [ -n "$SLX_BRIDGE" ]; then brctl addif "$SLX_BRIDGE" "$MAIN_NETIF" ip link set dev "$SLX_BRIDGE" up wait_for_iface "$SLX_BRIDGE" - ) - # success? - if [ "$?" -eq 0 ]; then + ); then MAIN_NETIF="$SLX_BRIDGE" break fi @@ -97,6 +108,7 @@ if [ -n "$SLX_BRIDGE" ]; then # nope, handle if [ -z "$try" ]; then emergency_shell "Failed to setup main network bridge, giving up!" + exit 1 fi warn "Failed to setup main network bridge on try $try. Retrying ..." # delete bridge, inc try and sleep 100ms before trying again @@ -131,7 +143,7 @@ sleep 1 additional_opts=() # we need to send the same UID (without '-') as the PXE firmware did, so use the plain -# one read with dmidecode (and not the one by get-system-uuid). +# one read with dmidecode (and not the one by s3-get-system-uuid). if [ "$USE_DHCP_UUID" = "yes" ]; then UID="$(dmidecode -s system-uuid | sed -r 's/^(..)(..)(..)(..)-(..)(..)-(..)(..)-(....)-/00\4\3\2\1\6\5\8\7\9/')" if [ "${#UID}" = 34 ]; then @@ -155,16 +167,18 @@ request_opts+=("-O" "nisdomain") # udhcpc for i in 1 1 1 fail; do - [ "$i" = "fail" ] && emergency_shell "DHCP failed 3 times... cannot continue." + if [ "$i" = "fail" ]; then + emergency_shell "DHCP failed 3 times... cannot continue." + exit 1 + fi udhcpc -t 4 -T 3 -f -n -q \ -i "${MAIN_NETIF}" \ "${request_opts[@]}" \ "${additional_opts[@]}" \ - -s "/usr/local/bin/udhcpc-trigger" - # success? - [ "$?" -eq 0 ] && break - # nope, keep trying... - warn "DHCP failed, retrying in 1sec..." + -s "/usr/local/bin/udhcpc-trigger" \ + && break + # failed, keep trying... + warn "DHCP failed, retrying in $i sec..." sleep $i done diff --git a/modules.d/slx-network/module-setup.sh b/modules.d/slx-network/module-setup.sh index bf384322..6e28ba1f 100755 --- a/modules.d/slx-network/module-setup.sh +++ b/modules.d/slx-network/module-setup.sh @@ -24,19 +24,48 @@ install() { inst_libdir_file {"tls/$_arch/",tls/,"$_arch/",}"libnss_dns.so.*" # stage3 network scripts - inst "${moddir}/scripts/setup-bootif-network.stage3" "/usr/local/bin/setup-bootif-network" inst "${moddir}/scripts/udhcpc-trigger.stage3" "/usr/local/bin/udhcpc-trigger" # files for stage4, park them in /opt/openslx gcc -o "${initdir}/usr/local/bin/rdns" "${moddir}/rdns.c" - inst "${moddir}/scripts/setup-bootif-network.stage4" "/opt/openslx/scripts/setup-bootif-network.stage4" + inst "${moddir}/scripts/s3-setup-bootif-network.stage4" "/opt/openslx/scripts/s3-setup-bootif-network.stage4" inst "${moddir}/scripts/udhcpc-trigger.stage4" "/opt/openslx/scripts/udhcpc-trigger.stage4" - inst "${moddir}/services/udhcpc-bootif.service" "/opt/openslx/services/udhcpc-bootif.service" + inst "${moddir}/services/udhcpc-bootif-stage4.service" "/opt/openslx/services/udhcpc-bootif.service" + + # Parse IP config etc. from KCL + _name="s3-parse-network-kcl" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-cmdline.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-cmdline.service.requires/${_name}.service" + # Setup bootif network: bridge, vlan, dhcp, ... + _name="s3-setup-bootif-network" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-initqueue.service.wants" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-initqueue.service.wants/${_name}.service" + # Copy files related to networking. Must be the very last thing before switchroot to + # make sure nothing else tries to meddle with these after copying, e.g. slx-ssl. + _name="s3-copy-network-files" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-pivot.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-pivot.service.requires/${_name}.service" # hooks - inst_hook cmdline 10 "${moddir}/hooks/parse-ipxe-network-kcl.sh" inst_hook pre-pivot 10 "${moddir}/hooks/configure-jumbo-frames.sh" # DO NOT TOUCH THIS - inst_hook pre-pivot 99 "${moddir}/hooks/copy-network-files.sh" - inst_hook pre-pivot 60 "${moddir}/hooks/activate-bootif-dhcp.sh" + inst_hook pre-pivot 60 "${moddir}/hooks/activate-stage4-dhcp.sh" } diff --git a/modules.d/slx-network/services/s3-copy-network-files.service b/modules.d/slx-network/services/s3-copy-network-files.service new file mode 100644 index 00000000..24325cef --- /dev/null +++ b/modules.d/slx-network/services/s3-copy-network-files.service @@ -0,0 +1,12 @@ +[Unit] +Description=Copy networking-related files to stage 4 +After=s3-ssl-sat.service +After=initrd-root-fs.target +Before=initrd-switch-root.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-copy-network-files.sh diff --git a/modules.d/slx-network/services/s3-parse-network-kcl.service b/modules.d/slx-network/services/s3-parse-network-kcl.service new file mode 100644 index 00000000..da0445ca --- /dev/null +++ b/modules.d/slx-network/services/s3-parse-network-kcl.service @@ -0,0 +1,13 @@ +[Unit] +Description=Extract network config from KCL +DefaultDependencies=no +Wants=dracut-cmdline.service +After=dracut-cmdline.service +Wants=systemd-udevd.service +Before=systemd-udevd.service +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-parse-network-kcl.sh diff --git a/modules.d/slx-network/services/s3-setup-bootif-network.service b/modules.d/slx-network/services/s3-setup-bootif-network.service new file mode 100644 index 00000000..227a8ff6 --- /dev/null +++ b/modules.d/slx-network/services/s3-setup-bootif-network.service @@ -0,0 +1,13 @@ +[Unit] +Description=Configure main network link +DefaultDependencies=no +IgnoreOnIsolate=true +Wants=s3-parse-network-kcl.service +After=s3-parse-network-kcl.service +Before=dracut-pre-mount.service +Before=s3-dnbd3root.service + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-setup-bootif-network.sh diff --git a/modules.d/slx-network/services/udhcpc-bootif.service b/modules.d/slx-network/services/udhcpc-bootif-stage4.service index 71a721dc..71a721dc 100644 --- a/modules.d/slx-network/services/udhcpc-bootif.service +++ b/modules.d/slx-network/services/udhcpc-bootif-stage4.service diff --git a/modules.d/slx-runmode/scripts/runmode.sh b/modules.d/slx-runmode/hooks/s3-enable-runmode.sh index a563486f..a563486f 100644..100755 --- a/modules.d/slx-runmode/scripts/runmode.sh +++ b/modules.d/slx-runmode/hooks/s3-enable-runmode.sh diff --git a/modules.d/slx-runmode/module-setup.sh b/modules.d/slx-runmode/module-setup.sh index 7705ad06..c6ab9524 100755 --- a/modules.d/slx-runmode/module-setup.sh +++ b/modules.d/slx-runmode/module-setup.sh @@ -8,6 +8,13 @@ depends() { echo dnbd3-rootfs } install() { - # unpacking config.tgz should be pre-pivot 10, let's do this afterwards - inst_hook pre-pivot 50 "$moddir/scripts/runmode.sh" + _name="s3-enable-runmode" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-pivot.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-pivot.service.requires/${_name}.service" } diff --git a/modules.d/slx-runmode/services/s3-enable-runmode.service b/modules.d/slx-runmode/services/s3-enable-runmode.service new file mode 100644 index 00000000..00f0dcd7 --- /dev/null +++ b/modules.d/slx-runmode/services/s3-enable-runmode.service @@ -0,0 +1,11 @@ +[Unit] +Description=Set up proper default target +After=s3-fetch-config.service +Before=initrd-switch-root.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-enable-runmode.sh diff --git a/modules.d/slx-splash/scripts/restore-cursor.sh b/modules.d/slx-splash/scripts/restore-cursor.sh index 4ba9880d..4ba9880d 100644..100755 --- a/modules.d/slx-splash/scripts/restore-cursor.sh +++ b/modules.d/slx-splash/scripts/restore-cursor.sh diff --git a/modules.d/slx-splash/scripts/slx-splash-exam.sh b/modules.d/slx-splash/scripts/slx-splash-exam.sh index 79160fc4..79160fc4 100644..100755 --- a/modules.d/slx-splash/scripts/slx-splash-exam.sh +++ b/modules.d/slx-splash/scripts/slx-splash-exam.sh diff --git a/modules.d/slx-splash/scripts/slx-splash-icon-config.sh b/modules.d/slx-splash/scripts/slx-splash-icon-config.sh index fb7cd9d0..fb7cd9d0 100644..100755 --- a/modules.d/slx-splash/scripts/slx-splash-icon-config.sh +++ b/modules.d/slx-splash/scripts/slx-splash-icon-config.sh diff --git a/modules.d/slx-splash/scripts/slx-splash-icon-hdd.sh b/modules.d/slx-splash/scripts/slx-splash-icon-hdd.sh index 2b1ff4a3..2b1ff4a3 100644..100755 --- a/modules.d/slx-splash/scripts/slx-splash-icon-hdd.sh +++ b/modules.d/slx-splash/scripts/slx-splash-icon-hdd.sh diff --git a/modules.d/slx-splash/scripts/slx-splash-icon-puzzle.sh b/modules.d/slx-splash/scripts/slx-splash-icon-puzzle.sh index 5c8d310b..5c8d310b 100644..100755 --- a/modules.d/slx-splash/scripts/slx-splash-icon-puzzle.sh +++ b/modules.d/slx-splash/scripts/slx-splash-icon-puzzle.sh diff --git a/modules.d/slx-splash/scripts/slx-splash-icon-rootfs.sh b/modules.d/slx-splash/scripts/slx-splash-icon-rootfs.sh index a0cf9218..a0cf9218 100644..100755 --- a/modules.d/slx-splash/scripts/slx-splash-icon-rootfs.sh +++ b/modules.d/slx-splash/scripts/slx-splash-icon-rootfs.sh diff --git a/modules.d/slx-splash/scripts/slx-splash-init.sh b/modules.d/slx-splash/scripts/slx-splash-init.sh index a4c71f88..a4c71f88 100644..100755 --- a/modules.d/slx-splash/scripts/slx-splash-init.sh +++ b/modules.d/slx-splash/scripts/slx-splash-init.sh diff --git a/modules.d/slx-ssl/hooks/setup-ssl-sat.sh b/modules.d/slx-ssl/hooks/s3-ssl-sat.sh index d6fec336..d6fec336 100644..100755 --- a/modules.d/slx-ssl/hooks/setup-ssl-sat.sh +++ b/modules.d/slx-ssl/hooks/s3-ssl-sat.sh diff --git a/modules.d/slx-ssl/module-setup.sh b/modules.d/slx-ssl/module-setup.sh index b3fd803b..5b756e32 100755 --- a/modules.d/slx-ssl/module-setup.sh +++ b/modules.d/slx-ssl/module-setup.sh @@ -9,6 +9,13 @@ depends() { } install() { # config.tgz unpacking happens in pre-pivot/90 - # BEFORE "copy network files" - inst_hook pre-pivot 98 "$moddir/hooks/setup-ssl-sat.sh" + # TODO: BEFORE "copy network files", as we modify /etc/hosts + inst "$moddir/hooks/s3-ssl-sat.sh" \ + /usr/local/bin/s3-ssl-sat.sh + inst_simple "${moddir}/services/s3-ssl-sat.service" \ + "${systemdsystemunitdir}/s3-ssl-sat.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-mount.service.requires" + ln_r "${systemdsystemunitdir}/s3-ssl-sat.service" \ + "${systemdsystemunitdir}/dracut-mount.service.requires/s3-ssl-sat.service" } diff --git a/modules.d/slx-ssl/services/s3-ssl-sat.service b/modules.d/slx-ssl/services/s3-ssl-sat.service new file mode 100644 index 00000000..95645334 --- /dev/null +++ b/modules.d/slx-ssl/services/s3-ssl-sat.service @@ -0,0 +1,12 @@ +[Unit] +Description=Enable SSL communication with Satellite Server +After=s3-unpack-config-tgz.service +Requires=s3-unpack-config-tgz.service +Before=initrd-switch-root.target +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-ssl-sat.sh diff --git a/modules.d/slx-tools/module-setup.sh b/modules.d/slx-tools/module-setup.sh index faf2a04f..faf2a04f 100644..100755 --- a/modules.d/slx-tools/module-setup.sh +++ b/modules.d/slx-tools/module-setup.sh diff --git a/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh b/modules.d/slx-uuid/hooks/copy-system-uuid-to-newroot.sh index 553109fb..e451ce26 100644..100755 --- a/modules.d/slx-uuid/scripts/copy-system-uuid-to-newroot.sh +++ b/modules.d/slx-uuid/hooks/copy-system-uuid-to-newroot.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/ash if [ -s "/run/system-uuid" ]; then cp "/run/system-uuid" "$NEWROOT/etc/system-uuid" diff --git a/modules.d/slx-uuid/scripts/get-system-uuid.sh b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh index fd6bb125..e65a3394 100644..100755 --- a/modules.d/slx-uuid/scripts/get-system-uuid.sh +++ b/modules.d/slx-uuid/hooks/s3-get-system-uuid.sh @@ -8,22 +8,24 @@ get_system_uuid() { if [ -e /run/openslx/network.conf ]; then . /run/openslx/network.conf + else + echo "Don't have /run/openslx/network.conf" fi - + if [ -z "$SLX_PXE_MAC" ]; then - eval $(grep -Eo BOOTIF=\\S+ /proc/cmdline) + warn "Getting MAC from /run/openslx/network.conf failed, using 'ip a'..." + for iface in "${SLX_BRIDGE:-br0}" boot0 eth0; do + BOOTIF=01-$(ip a | grep -A 1 ": ${iface}" | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g) + [ "${#BOOTIF}" -eq "20" ] && break + done if [ "${#BOOTIF}" -ne "20" ]; then - warn "Getting MAC from /proc/cmdline failed, using 'ip a'..." - BOOTIF=01-$(ip a | grep -A 1 ": ${SLX_BRIDGE:-br0}" | grep -o 'ether ..:..:..:..:..:..' | cut -d' ' -f2 | sed s/:/-/g) - fi - if [ "${#BOOTIF}" -ne "20" ]; then - warn "Getting MAC from 'ip a' failed, using a default value..." + warn "Getting MAC from 'ip a' failed, using bogus value..." BOOTIF="99-88-77-66-55-44-33" fi else BOOTIF="01-$(tr ':' '-' <<< $SLX_PXE_MAC)" fi - + local UUID=$(dmidecode -q -s system-uuid | grep -v '^#' | head -n 1 | tr 'a-z' 'A-Z') if [ "${#UUID}" -ne "36" ]; then warn "Determined UUID (${UUID}) has not expected length of 36, falling back to MAC..." diff --git a/modules.d/slx-uuid/module-setup.sh b/modules.d/slx-uuid/module-setup.sh index 1e550136..1cac712d 100755 --- a/modules.d/slx-uuid/module-setup.sh +++ b/modules.d/slx-uuid/module-setup.sh @@ -13,17 +13,24 @@ depends() { } install() { mkdir -p "$initdir/etc/bad-uuid.d" - # check if we have an uuid blacklists installed by openslx/mltk on this system - if [ "$(ls -A /opt/openslx/bad-uuid.d)" ]; then - for blacklist in "/opt/openslx/bad-uuid.d"/* ]; do - inst_simple "$blacklist" "/etc/bad-uuid.d/${blacklist##*/}" - done - else - # use this module's default blacklist - inst_simple "$moddir/bad-uuid-defaults.conf" "/etc/bad-uuid.d/bad-uuid-defaults.conf" - fi + # check if we have any uuid blacklists installed by openslx/mltk on this system + for blacklist in /opt/openslx/bad-uuid.d/*; do + [ -s "$blacklist" ] || continue + inst_simple "$blacklist" "/etc/bad-uuid.d/${blacklist##*/}" + done + # add this module's default blacklist + inst_simple "$moddir/bad-uuid-defaults.conf" "/etc/bad-uuid.d/bad-uuid-defaults.conf" inst_multiple dmidecode - inst_hook pre-udev 05 "$moddir/scripts/get-system-uuid.sh" - inst_hook pre-pivot 10 "$moddir/scripts/copy-system-uuid-to-newroot.sh" + inst_hook pre-pivot 10 "$moddir/hooks/copy-system-uuid-to-newroot.sh" + + _name="s3-get-system-uuid" + inst "$moddir/hooks/${_name}.sh" \ + "/usr/local/bin/${_name}.sh" + inst_simple "${moddir}/services/${_name}.service" \ + "${systemdsystemunitdir}/${_name}.service" + mkdir --parents \ + "${initdir}/${systemdsystemunitdir}/dracut-pre-udev.service.requires" + ln_r "${systemdsystemunitdir}/${_name}.service" \ + "${systemdsystemunitdir}/dracut-pre-udev.service.requires/${_name}.service" } diff --git a/modules.d/slx-uuid/services/s3-get-system-uuid.service b/modules.d/slx-uuid/services/s3-get-system-uuid.service new file mode 100644 index 00000000..b726cd2b --- /dev/null +++ b/modules.d/slx-uuid/services/s3-get-system-uuid.service @@ -0,0 +1,13 @@ +[Unit] +Description=Get system UUID +Requires=dracut-cmdline.service +After=dracut-cmdline.service +Wants=s3-parse-network-kcl.service +After=s3-parse-network-kcl.service +DefaultDependencies=no +IgnoreOnIsolate=true + +[Service] +Type=oneshot +RemainAfterExit=true +ExecStart=/usr/local/bin/s3-get-system-uuid.sh diff --git a/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh b/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh index b9803729..b9803729 100644..100755 --- a/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh +++ b/modules.d/systemd-networkd-ext/hooks/configure-dhcp-for-newroot.sh diff --git a/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh b/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh index ec61616c..ec61616c 100644..100755 --- a/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh +++ b/modules.d/systemd-networkd-ext/hooks/copy-networkd-files-to-newroot.sh diff --git a/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh b/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh index afe4ab7e..afe4ab7e 100644..100755 --- a/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh +++ b/modules.d/systemd-networkd-ext/hooks/parse-kcl-for-networkd.sh |