Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

01bootetc: introduce module for updating dracut etc #792

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dracut.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions modules.d/01bootetc/boot-etc.service
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions modules.d/01bootetc/boot-etc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
. /lib/dracut-lib.sh

bootetc=$(getarg bootetc=)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so we require an explicit opt-in karg like bootetc=1; and you see us changing FCOS to pass that by default? Or it only gets injected when e.g. dm-multipath is in use?

Copy link
Contributor Author

@darkmuggle darkmuggle Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more like bootetc=LABEL=..... I envision this being an opt-in. We could use it for FCOS, but I'm particularly keen on not making that decision today.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part is probably the most unfortunate. I don't know all of what's going on in dracut-cmdline.service but it'll need to be prepared to be killed at arbitrary points.

Can't we have this bit run Before=dracut-cmdline.service?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I looked at the boot-path. dracut-cmdline.service is run before Udev. we need udev to find the boot device.

systemctl try-restart systemd-udev-trigger.service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, why does udev need to be retriggered?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably so the device that contains the boot partition can be found?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh re-triggered.. not sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Udev rules :)

fi
fi

umount /boot >/dev/null 2>&1
24 changes: 24 additions & 0 deletions modules.d/01bootetc/module-setup.sh
Original file line number Diff line number Diff line change
@@ -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

}
2 changes: 1 addition & 1 deletion modules.d/01fips/fips-boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion modules.d/01fips/fips-noboot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
53 changes: 0 additions & 53 deletions modules.d/01fips/fips.sh
Original file line number Diff line number Diff line change
@@ -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=<boot device> 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)
Expand Down
56 changes: 56 additions & 0 deletions modules.d/99base/dracut-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=<boot device> 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
}