[systemd-devel] systemd kills mdmon if it was started manually by user

Michal Soltys soltys at ziu.info
Tue Nov 8 08:46:18 PST 2011


On 11-11-08 01:11, Michal Soltys wrote:
>
> I've peeked into systemd, and from what I can see, it /only/ jumps back
> to initramfs (prepare_new_root() and pivot_to_new_root()) if shutdown
> "binary" is present on initramfs. And whenever mdmon is still running or
> not, is not in any way determinent for pivot_root(2) call to succeed (or
> ... ?).
>
> If /run/initramfs/shutdown is not present, then systemd just do the
> things the old way as far as I can see - it doesn't even attempt to
> pivot. And if it doesn't, the it can't umount the root (being itself
> tied to it) ?
>
> So essentially, if systemd execs /shutdown (after pivoting to
> /run/initramfs) - then it's dracut's modules.d/99shutdown, which itself
> sources hooks from other modules to do the rest of cleaning job. And
> that should take care of all the remaining stuff (including terminating
> mdmon in graceful way, and then umounting /oldroot). Either way - pretty
> simple to add the necessary functionality to dracut.
>
> So wouldn't simply a systemd's cgroup named say - immortals - with mdmon
> (by default) in it suffice ? Pivot back as usual, leave mdmon alive, let
> the dracut (or anything else used for initramfs) do the rest of the job
> (properly).

I did some testings today, and it's all working nicely as expected. 
Actually I modified "classic" rc scripts I'm using under sysinit to 
perform full umount/detach (using similar methods to systemd), with 
mdmon happily living through everything. The only things needed after 
pivot_root were:

mdmon --takeover --all
telinit U

(so obviously my dracut image had mdmon, telinit and init, and slightly 
adjusted shutdown script).

Then everything from oldroot could be nicely and cleanly umounted.

Even more elegant would be if e.g. mdmon had added option such as:

--reroot <newroot>

to chroot() and reopen its files under <newroot>, and then systemd would 
call

mdmon --reroot /run/initramfs --all --takeover

after - prepare_new_root() and before - pivot_to_new_root()

Then even existing intiramfs image could (probably) be mdmon-agnostic.


More information about the systemd-devel mailing list