<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Feb 21, 2015 at 7:31 AM, Jeff Waugh <span dir="ltr"><<a href="mailto:jdub@bethesignal.org" target="_blank">jdub@bethesignal.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi all,</div><div><br></div><div>Marko Hoyer recently brought up the concept of a staged startup [1] on this list.</div><div><br></div><div>I have a specific use case for some form of staging, though I don't know if it meets Marko's definition or requirements! Perhaps systemd can handle this already, but let's see...</div><div><br></div><div><br></div><div>So, I've been building a systemd package for OpenWrt [2] to test on my little VoCore coin-sized MIPS machine. (Stay with me, the weird part is over.)</div><div><br></div><div>The root filesystem is a read-only squashfs blob stored on the VoCore's generous (!) 8MB of flash memory. During initial testing, I was happy to boot up into a read-only environment, bring up a few tmpfs mount points, and then keep mucking around with systemd.</div><div><br></div><div>But it's time to get serious. And everyone knows that "serious" means having a writeable root filesystem. OpenWrt uses overlayfs with JFFS2 as the top layer. but I'm just using tmpfs for now. (For some values of "serious".)</div><div><br></div><div><br></div><div>I wanted to make best use of systemd's built-in primitives, so here's what I've done:</div><div><br></div><div>- default.target is symlinked to initrd.target in the read-only filesystem image</div><div><br></div><div>- I've added some custom services to prepare all the mounts for the root switch (including one which changes the default.target symlink on the new, writeable root)</div><div><br></div><div>Yes, I'm abusing systemd's idea of an initrd.</div><div><br></div><div><br></div><div>Here's where it breaks down:</div><div><br></div><div>- systemd dutifully starts all the services it knows about during the initrd.target run, because they're all right there on the read-only filesystem (and they fail a lot)</div><div><br></div><div>- then systemd dutifully stops them all again to switch the root</div><div><br></div><div>- and dutifully starts them all again once we're headed towards multi-user.target</div><div><br></div><div>That's a *lot* of noise in the startup process!</div><div><br></div><div><br></div><div>I did get the impression from the documentation that initrd.target was somehow special, but it makes complete sense that it's not. If I were using an initramfs, there wouldn't be any superfluous service files in the initramfs filesystem, and I'd be happy to know that systemd would behave *exactly* the same way it would elsewhere.</div><div><br></div><div><br></div><div>One hacky idea I had to fix this:</div><div><br></div><div>- Pull all of the systemd service symlinks out of the squashfs filesystem and store them in a tarball</div><div><br></div><div>- Add specific symlinks to make the initrd stage works properly</div><div><br></div><div>- In the pre-switch prepare service, unpack the tarball into the rw-mounted /sysroot</div><div><br></div><div><br></div><div>Before anyone says it: No, using a real initramfs would be highly inappropriate. I do not want to store two copies of systemd and friends in 8MB of flash. It's hard enough with just the one!</div><div><br></div><div><br></div><div>Is there an existing systemd solution to this problem? Is there a better way to go about it?</div><div><br></div></div></blockquote><div>You could try a bazillion bind mounts from the initrd to the target filesystem, and then calling switch_root(8) from util-linux, and you do not need systemctl like the previous post suggests, if you get the dependencies right. You might also look at overlayfs, which got merged in Linux 3.18. I think overlayfs will make this possible, and of course share your results!</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div></div><div>Thanks,</div><div>Jeff</div><div><br></div><div><div>[1] <a href="http://lists.freedesktop.org/archives/systemd-devel/2015-January/027688.html" target="_blank">http://lists.freedesktop.org/archives/systemd-devel/2015-January/027688.html</a></div><div>[2] <a href="https://github.com/jdub/openwrt-systemd" target="_blank">https://github.com/jdub/openwrt-systemd</a></div></div></div>
<br>_______________________________________________<br>
systemd-devel mailing list<br>
<a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><br>---<br>Shawn Landden</div><div dir="ltr">ChurchOfGit.com</div></div></div></div>
</div></div>