[systemd-devel] OSTree mount integration

Lennart Poettering lennart at poettering.net
Mon Sep 24 15:36:14 PDT 2012


On Mon, 24.09.12 18:12, Colin Walters (walters at verbum.org) wrote:

> 
> On Mon, 2012-09-24 at 22:19 +0200, Lennart Poettering wrote:
> 
> > i.e. my suggestion would be to patch dracut (or write a dracut module)
> > that sets up your target OS tree with /var and friends directly, and
> > then transitions directly to it via moving it to / rather than first
> > moving into the host OS tree via a move/bind mount and then using
> > chroot() for the second step. (That said, whether you do this in one or
> > two steps is not important, what is important however is that you do not
> > use chroot()).
> 
> For reference by the way, the current ostree_switch_root code that gets
> called from dracut is here:
> http://git.gnome.org/browse/ostree/tree/src/switchroot/ostree-switch-root.c
> (It's a fork of util-linux switch_root).
> 
> The issue with your suggestion I think is that the "deployment root" as
> I call them (ostree chroots) isn't a mount point, so I can't just
> MS_MOVE move the whole directory to /.  Although I can make it into a
> mount point I guess with the trick of bind-mounting it to itself, and
> then move that?

Instead of moving it you can simply bind mount it to / instead. 

(But note that bind mounting on itself is not really considered a
"trick", it's actually a core part of the kernel API).

> Hm.  So something something like this, from dracut's perspective,
> where /sysroot is the "target rootfs", and its / is the initramfs:
> 
> mount(/sysroot/ostree/current/,/sysroot/ostree/current/)

Hmm, so the dir is already a mount point?

> move(/dev, /sysroot/ostree/current/dev)
> move(/proc, /sysroot/ostree/current/proc)
> move(/sys, /sysroot/ostree/current/sys)

Note that you need /run here, too. We need the runtime data from the
initrd in the host system too.

More importatnly though note that systemd will do this bit for you
anyway btw, as part of "systemctl switch-root". You just need to pass it
the right path. (See src/core/switch-root.c which is the code in PID1
that backs "systemctl switch-root"). 

> bind(/sysroot, /sysroot/ostree/current/sysroot)
> bind(/sysroot/home, /sysroot/ostree/current/home)
> bind(/sysroot/ostree/var, /sysroot/ostree/current/var)
> bind(/sysroot/ostree/current-etc, /sysroot/ostree/current/etc)

THis is the part that is actually truly ostree specific, and should be
in a dracut module.

> move(/sysroot/ostree/current/, /)
> execv(/sbin/init)

This is what systemd already can do for you.

> But I don't think this will exactly the solve all the problems.  In this
> case / is still a bind mount, not the real backing store.  So for
> example if I have a normal / entry in /etc/fstab, systemd is going to
> fail to remount it read/write.

No, this should work properly. We accept mounts as they are, we do not
check the backing device of this, and the root fs check ignores
/etc/fstab anyway and uses stat() to determine the backing device.

Note that OLPC is actually using a setup very similar to yours. It
appears to work fine for them these days.

> I should get a chance to try out some patches here within a few weeks.
> The main thing that needs fixing is /etc/fstab :
> 
> https://mail.gnome.org/archives/ostree-list/2012-September/msg00008.html

I can't say I follow here.

The root fsck is very special. It is not done via fsck at .service, but via
root-fsck.service, and follows very different semantics, as it requires
read-only root. On top of that we actually do the root fsck in the
initrd anyway, to avoid having to run the fsck tool from the disk it is
supposed to check/fix.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list