diff options
Diffstat (limited to 'modules.d/dnbd3-rootfs')
14 files changed, 122 insertions, 165 deletions
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/fetch-config.sh b/modules.d/dnbd3-rootfs/hooks/fetch-config.sh deleted file mode 100755 index 021a4c06..00000000 --- a/modules.d/dnbd3-rootfs/hooks/fetch-config.sh +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env bash -# -*- coding: utf-8 -*- -# region imports -type emergency_shell >/dev/null 2>&1 || source /lib/dracut-lib.sh -# endregion - -slx_server="$(getarg slxsrv=)" -slx_server_base="$(getarg slxbase=)" - -# if no slxsrv was specified, use the server the kernel was -# downloaded from as fallback. Mostly for legacy PXE boot. -if [ -z "$slx_server" ]; then - slx_server="$(getarg BOOT_IMAGE= | awk -F[/:] '{print $4}')" -fi -if [ -z "$slx_server" ]; then - # use tftp server from ip parameter - slx_server="$(getarg ip= | awk -F: '{print $2}' )" -fi -if [ -z "$slx_server" ]; then - # we have a problem :/ - emergency_shell "Failed to determine SLX server to fetch config from." -fi - -# build config_url -config_url="http://${slx_server#@}/${slx_server_base}/config" - -# check if system's uuid was set -if [ -s "/run/system-uuid" ]; then - uuid=$(cat "/run/system-uuid") - if [ -n "$uuid" ]; then - config_url="${config_url}?uuid=${uuid}" - fi -fi - -config_path="/etc/openslx.tmp" - -echo "Downloading '$config_url'..." -slx-tools download_retry --slx-time 20 -sS "$config_url" > "$config_path" -return_code="$?" - -if [ ! -s "$config_path" ] ; then - emergency_shell "Downloading netboot configuration file from '$config_url' failed with: $return_code" -fi - -if ! ash -n "$config_path"; then - emergency_shell "Netboot configuration failed syntax check!" -fi - -# remember kcl server and base -{ - echo "SLX_KCL_SERVERS='$slx_server'" - echo "SLX_BASE_PATH='$slx_server_base'" - echo "# Config fetched from $config_url" - echo "CONFIG_DOWNLOAD_TIME=$(sed -r 's/^([0-9]+)\.([0-9]+).*$/\1\2/' /proc/uptime)" - echo '#_RCONFIG_TAG' -} > /etc/openslx - -# finally copy remote config into it -cat "$config_path" >> /etc/openslx - -# slxsrv overrides SLX_DNBD3_SERVERS if prefixed with @ -[ "${slx_server#@}" != "${slx_server}" ] && sed -i "s/^SLX_DNBD3_SERVERS=.*/SLX_DNBD3_SERVERS='${slx_server#@}'/" "/etc/openslx" -true 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 |