Skip to content

Commit 8d1d32b

Browse files
committed
systemd: various fixes for boot with container-arrays.
1/ Add systemd shutdown script to ensure DDF and IMSM are clean before we actually shutdown 2/ Get udev to tell systemd to run the [email protected] units when a member array appears. If we boot off a member array (with dracut at least), the mdmon started in the initramfs will lose track of /sys etc, so we need to restart it. systemd will try to forget about it too (but not actually kill it because we said not to do this). Having udev tell it to start it will allow a new mdmon to run which can see /sys, and systemd will know about it. 3/ Always use --offroot and --takeover when starting mdmon with systemd --offroot is needed else shutdown will hang. --takeover is needed incase an mdmon was started earlier (e.g. in initramfs). Neither hurt if they aren't actually needed. Signed-off-by: NeilBrown <[email protected]>
1 parent f43f5b3 commit 8d1d32b

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ install-systemd: systemd/[email protected]
288288
$(INSTALL) -D -m 644 systemd/mdmonitor.service $(DESTDIR)$(SYSTEMD_DIR)/mdmonitor.service
289289
$(INSTALL) -D -m 644 systemd/[email protected] $(DESTDIR)$(SYSTEMD_DIR)/[email protected]
290290
$(INSTALL) -D -m 644 systemd/[email protected] $(DESTDIR)$(SYSTEMD_DIR)/[email protected]
291+
$(INSTALL) -D -m 755 systemd/mdadm.shutdown $(DESTDIR)$(SYSTEMD_DIR)-shutdown/mdadm.shutdown
291292
if [ -f /etc/SuSE-release -o -n "$(SUSE)" ] ;then $(INSTALL) -D -m 755 systemd/SUSE-mdadm_env.sh $(DESTDIR)$(SYSTEMD_DIR)/../scripts/mdadm_env.sh ;fi
292293

293294
uninstall:

systemd/mdadm.shutdown

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# We need to ensure all md arrays with external metadata
3+
# (e.g. IMSM, DDF) are clean before completing the shutdown.
4+
/sbin/mdadm --wait-clean --scan

systemd/[email protected]

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ Before=initrd-switch-root.target
1414
# mdmon should never complain due to lack of a platform,
1515
# that is mdadm's job if at all.
1616
Environment=IMSM_NO_PLATFORM=1
17-
ExecStart=/sbin/mdmon %I
17+
# The mdmon starting in the initramfs (with dracut at least)
18+
# cannot see sysfs after root is mounted, so we will have to
19+
# 'takeover'. As the '--offroot --takeover' don't hurt when
20+
# not necessary, are are useful with root-on-md in dracut,
21+
# have them always present.
22+
ExecStart=/sbin/mdmon --offroot --takeover %I
1823
Type=forking
19-
PIDFile=/run/mdadm/%I.pid
24+
# Don't set the PIDFile. It isn't necessary (systemd can work
25+
# it out) and systemd will remove it when transitioning from
26+
# initramfs to rootfs.
27+
#PIDFile=/run/mdadm/%I.pid
2028
KillMode=none

udev-md-raid-arrays.rules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk
3434

3535
ENV{MD_LEVEL}=="raid[1-9]*", ENV{SYSTEMD_WANTS}+="mdmonitor.service"
3636

37+
# Tell systemd to run mdmon for our container, if we need it.
38+
ENV{MD_LEVEL}=="raid[1-9]*", ENV{MD_CONTAINER}=="?*", PROGRAM="/usr/bin/readlink $env{MD_CONTAINER}", ENV{MD_MON_THIS}="%c"
39+
ENV{MD_MON_THIS}=="?*", PROGRAM="/usr/bin/basename $env{MD_MON_THIS}", ENV{SYSTEMD_WANTS}+="mdmon@%c.service"
40+
3741
LABEL="md_end"

0 commit comments

Comments
 (0)