diff --git a/dracut.spec b/dracut.spec index 0369dde684..6bf2f78255 100644 --- a/dracut.spec +++ b/dracut.spec @@ -343,6 +343,7 @@ install -m 0755 51-dracut-rescue-postinst.sh $RPM_BUILD_ROOT%{_sysconfdir}/kerne %if 0%{?fedora} || 0%{?rhel} || 0%{?suse_version} %{dracutlibdir}/modules.d/01fips %endif +%{dracutlibdir}/modules.d/01bootetc %{dracutlibdir}/modules.d/01systemd-initrd %{dracutlibdir}/modules.d/03modsign %{dracutlibdir}/modules.d/03rescue diff --git a/modules.d/01bootetc/boot-etc.service b/modules.d/01bootetc/boot-etc.service new file mode 100644 index 0000000000..79b6ec5e33 --- /dev/null +++ b/modules.d/01bootetc/boot-etc.service @@ -0,0 +1,20 @@ +[Unit] +Description=Update initramfs etc +Before=iscsi.service iscsid.service lvm2-activation-early.service +Wants=systemd-udev-trigger.service systemd-udev-settle.service local-fs-pre.target +After=systemd-udev-trigger.service systemd-udev-settle.service +Before=local-fs-pre.target dracut-initqueue.service + +DefaultDependencies=no +Conflicts=shutdown.target + +ConditionKernelCommandLine=bootetc +ConditionPathExists=!/run/bootetc.done + +[Service] +Type=oneshot +ExecStart=/sbin/boot-etc +ExecStart=/usr/bin/touch /run/bootetc.done + +[Install] +WantedBy=sysinit.target diff --git a/modules.d/01bootetc/boot-etc.sh b/modules.d/01bootetc/boot-etc.sh new file mode 100755 index 0000000000..be67149ad7 --- /dev/null +++ b/modules.d/01bootetc/boot-etc.sh @@ -0,0 +1,21 @@ +#!/bin/sh +. /lib/dracut-lib.sh + +bootetc=$(getarg bootetc=) +if [ "${bootetc}x" == "x" ]; then + exit 0 +fi + +mount_boot bootetc +if [ -d /boot/initrd-etc ] && [ ! -f /run/bootetc.done ]; then + info "bootetc: Updating initramfs etc from ${bootetc}/initrd-etc" + copytree /boot/initrd-etc /etc + touch /run/bootetc.done + + if [ -z "$DRACUT_SYSTEMD" ]; then + systemctl try-restart dracut-cmdline.service + systemctl try-restart systemd-udev-trigger.service + fi +fi + +umount /boot >/dev/null 2>&1 diff --git a/modules.d/01bootetc/module-setup.sh b/modules.d/01bootetc/module-setup.sh new file mode 100755 index 0000000000..f88af6ddb5 --- /dev/null +++ b/modules.d/01bootetc/module-setup.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# called by dracut +check() { + return 0 +} + +# called by dracut +depends() { + return 0 +} + +# called by dracut +install() { + inst_simple "$moddir/boot-etc.sh" "/sbin/boot-etc" + + if dracut_module_included "systemd"; then + inst_simple "${moddir}/boot-etc.service" "${systemdsystemunitdir}/boot-etc.service" + systemctl -q --root "$initdir" enable boot-etc.service + else + inst_hook pre-trigger 01 "$moddir/boot-etc.sh" + fi + +} diff --git a/modules.d/01fips/fips-boot.sh b/modules.d/01fips/fips-boot.sh index 1676a6e307..0f5ac2954b 100755 --- a/modules.d/01fips/fips-boot.sh +++ b/modules.d/01fips/fips-boot.sh @@ -6,7 +6,7 @@ elif [ -z "$fipsmode" ]; then die "FIPS mode have to be enabled by 'fips=1' not just 'fips'" elif getarg boot= >/dev/null; then . /sbin/fips.sh - if mount_boot; then + if mount_boot boot fips=1; then do_fips || die "FIPS integrity test failed" fi fi diff --git a/modules.d/01fips/fips-noboot.sh b/modules.d/01fips/fips-noboot.sh index 8d6037e5ca..c528cd8607 100755 --- a/modules.d/01fips/fips-noboot.sh +++ b/modules.d/01fips/fips-noboot.sh @@ -6,6 +6,6 @@ elif [ -z "$fipsmode" ]; then die "FIPS mode have to be enabled by 'fips=1' not just 'fips'" elif ! [ -f /tmp/fipsdone ]; then . /sbin/fips.sh - mount_boot + mount_boot boot fips=1 do_fips || die "FIPS integrity test failed" fi diff --git a/modules.d/01fips/fips.sh b/modules.d/01fips/fips.sh index 8fba135b2f..6007ee5f2a 100755 --- a/modules.d/01fips/fips.sh +++ b/modules.d/01fips/fips.sh @@ -1,58 +1,5 @@ #!/bin/sh -mount_boot() -{ - boot=$(getarg boot=) - - if [ -n "$boot" ]; then - case "$boot" in - LABEL=*) - boot="$(echo $boot | sed 's,/,\\x2f,g')" - boot="/dev/disk/by-label/${boot#LABEL=}" - ;; - UUID=*) - boot="/dev/disk/by-uuid/${boot#UUID=}" - ;; - PARTUUID=*) - boot="/dev/disk/by-partuuid/${boot#PARTUUID=}" - ;; - PARTLABEL=*) - boot="/dev/disk/by-partlabel/${boot#PARTLABEL=}" - ;; - /dev/*) - ;; - *) - die "You have to specify boot= as a boot option for fips=1" ;; - esac - - if ! [ -e "$boot" ]; then - udevadm trigger --action=add >/dev/null 2>&1 - [ -z "$UDEVVERSION" ] && UDEVVERSION=$(udevadm --version) - i=0 - while ! [ -e $boot ]; do - if [ $UDEVVERSION -ge 143 ]; then - udevadm settle --exit-if-exists=$boot - else - udevadm settle --timeout=30 - fi - [ -e $boot ] && break - sleep 0.5 - i=$(($i+1)) - [ $i -gt 40 ] && break - done - fi - - [ -e "$boot" ] || return 1 - - mkdir /boot - info "Mounting $boot as /boot" - mount -oro "$boot" /boot || return 1 - elif [ -d "$NEWROOT/boot" ]; then - rm -fr -- /boot - ln -sf "$NEWROOT/boot" /boot - fi -} - do_rhevh_check() { KERNEL=$(uname -r) diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh index c53cd13b94..9d0f7e7c5a 100755 --- a/modules.d/99base/dracut-lib.sh +++ b/modules.d/99base/dracut-lib.sh @@ -1300,3 +1300,59 @@ remove_hostonly_files() { done < /lib/dracut/hostonly-files fi } + +mount_boot() { + boot_flag="$1"; shift; + calling_args="${@}" + + boot=$(getarg $boot_flag=) + if [ -n "$boot" ]; then + case "$boot" in + LABEL=*) + boot="$(echo $boot | sed 's,/,\\x2f,g')" + boot="/dev/disk/by-label/${boot#LABEL=}" + ;; + UUID=*) + boot="/dev/disk/by-uuid/${boot#UUID=}" + ;; + PARTUUID=*) + boot="/dev/disk/by-partuuid/${boot#PARTUUID=}" + ;; + PARTLABEL=*) + boot="/dev/disk/by-partlabel/${boot#PARTLABEL=}" + ;; + /dev/*) + die "You have to specify $boot_flag= as a boot option${calling_args:+ for $calling_args}" + ;; + *) + die "${die_msg}" + ;; + esac + + if ! [ -e "$boot" ]; then + udevadm trigger --action=add >/dev/null 2>&1 + [ -z "$UDEVVERSION" ] && UDEVVERSION=$(udevadm --version) + i=0 + while ! [ -e $boot ]; do + if [ $UDEVVERSION -ge 143 ]; then + udevadm settle --exit-if-exists=$boot + else + udevadm settle --timeout=30 + fi + [ -e $boot ] && break + sleep 0.5 + i=$(($i+1)) + [ $i -gt 40 ] && break + done + fi + + [ -e "$boot" ] || return 1 + + mkdir -p /boot + info "Mounting $boot as /boot" + mount -oro "$boot" /boot || return 1 + elif [ -d "$NEWROOT/boot" ]; then + rm -fr -- /boot + ln -sf "$NEWROOT/boot" /boot + fi +}