Skip to content

Commit

Permalink
Move dracut specifics to dracut mount unit
Browse files Browse the repository at this point in the history
Dracut depends on BOOTFS environment variable to be set after pool
import. This dracut specific systemd ExecStartPost command should not be
called for any non-dracut systems, so let's move it to a static systemd
unit that gets pulled in by the generated mount unit.

Signed-off-by: Michael Niewöhner <foss@mniewoehner.de>
  • Loading branch information
c0d3z3r0 committed Mar 22, 2019
1 parent efe7c08 commit c49a150
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ AC_CONFIG_FILES([
contrib/dracut/Makefile
contrib/dracut/02zfsexpandknowledge/Makefile
contrib/dracut/90zfs/Makefile
contrib/dracut/systemd/Makefile
contrib/initramfs/Makefile
contrib/initramfs/hooks/Makefile
contrib/initramfs/scripts/Makefile
Expand Down
3 changes: 2 additions & 1 deletion contrib/dracut/90zfs/zfs-generator.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ echo "zfs-generator: writing extension for sysroot.mount to $GENERATOR_DIR"/sysr
{
echo "[Unit]"
echo "Before=initrd-root-fs.target"
echo "After=zfs-import.target"
echo "After=zfs-dracut-bootfs.service zfs-import.target"
echo "Requires=zfs-dracut-bootfs.service"
echo "[Mount]"
if [ "${root}" = "zfs:AUTO" ] ; then
echo "PassEnvironment=BOOTFS"
Expand Down
3 changes: 2 additions & 1 deletion contrib/dracut/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SUBDIRS = 02zfsexpandknowledge 90zfs
SUBDIRS = 02zfsexpandknowledge 90zfs $(ZFS_INIT_SYSTEMD)
DIST_SUBDIRS = 02zfsexpandknowledge 90zfs systemd

EXTRA_DIST = README.dracut.markdown
1 change: 1 addition & 0 deletions contrib/dracut/systemd/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
zfs-dracut-bootfs.service
13 changes: 13 additions & 0 deletions contrib/dracut/systemd/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
systemdunit_DATA = \
zfs-dracut-bootfs.service

EXTRA_DIST = \
$(top_srcdir)/contrib/dracut/systemd/zfs-dracut-bootfs.service.in

$(systemdunit_DATA):%:%.in
-$(SED) -e 's,@bindir\@,$(bindir),g' \
-e 's,@sbindir\@,$(sbindir),g' \
$< >'$@'

distclean-local::
-$(RM) $(systemdunit_DATA)
10 changes: 10 additions & 0 deletions contrib/dracut/systemd/zfs-dracut-bootfs.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Set BOOTFS environment for dracut
Documentation=man:zfs(8)
DefaultDependencies=no
After=zfs-import.target
Requires=zfs-import.target

[Service]
Type=oneshot
ExecStart=/bin/sh -c "/bin/systemctl set-environment BOOTFS=$(@sbindir@/zpool list -H -o bootfs | grep -v '^-$' | head -1)"
1 change: 0 additions & 1 deletion etc/systemd/system/zfs-import-cache.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ ConditionPathExists=@sysconfdir@/zfs/zpool.cache
Type=oneshot
RemainAfterExit=yes
ExecStart=@sbindir@/zpool import -c @sysconfdir@/zfs/zpool.cache -aN
ExecStartPost=/bin/sh -c "/bin/systemctl set-environment BOOTFS=$(@sbindir@/zpool list -H -o bootfs | grep -v '^-$' | head -1)"

[Install]
WantedBy=zfs-import.target
1 change: 0 additions & 1 deletion etc/systemd/system/zfs-import-scan.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ ConditionPathExists=!@sysconfdir@/zfs/zpool.cache
Type=oneshot
RemainAfterExit=yes
ExecStart=@sbindir@/zpool import -aN -o cachefile=none
ExecStartPost=/bin/sh -c "/bin/systemctl set-environment BOOTFS=$(@sbindir@/zpool list -H -o bootfs | grep -v '^-$' | head -1)"

[Install]
WantedBy=zfs-import.target
6 changes: 5 additions & 1 deletion rpm/generic/zfs.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ image which is ZFS aware.

%if 0%{?_systemd}
%define systemd --enable-systemd --with-systemdunitdir=%{_unitdir} --with-systemdpresetdir=%{_presetdir} --with-systemdmodulesloaddir=%{_modulesloaddir} --with-systemdgeneratordir=%{_systemdgeneratordir} --disable-sysvinit
%define systemd_svcs zfs-import-cache.service zfs-import-scan.service zfs-mount.service zfs-share.service zfs-zed.service zfs.target zfs-import.target
%define systemd_svcs zfs-import-cache.service zfs-import-scan.service zfs-mount.service zfs-share.service zfs-zed.service zfs.target zfs-import.target zfs-dracut-bootfs.service
%else
%define systemd --enable-sysvinit --disable-systemd
%endif
Expand Down Expand Up @@ -435,6 +435,7 @@ systemctl --system daemon-reload >/dev/null || true
%{_presetdir}/*
%{_modulesloaddir}/*
%{_systemdgeneratordir}/*
%exclude %{_unitdir}/zfs-dracut*
%else
%config(noreplace) %{_sysconfdir}/init.d/*
%config(noreplace) %{_initconfdir}/zfs
Expand Down Expand Up @@ -467,6 +468,9 @@ systemctl --system daemon-reload >/dev/null || true
%files dracut
%doc contrib/dracut/README.dracut.markdown
%{_dracutdir}/modules.d/*
%if 0%{?_systemd}
%{_unitdir}/zfs-dracut*
%endif

%if %{with pyzfs}
%files -n python%{__python_pkg_version}-pyzfs
Expand Down

0 comments on commit c49a150

Please sign in to comment.