!PSmBFWNKoXmlQBzUQf:helsinki-systems.de

Stage 1 systemd

73 Members
systemd in NixOs's stage 1, replacing the current bash tooling https://github.com/NixOS/nixpkgs/projects/5123 Servers

Load older messages


SenderMessageTime
18 Apr 2023
@elvishjerricco:matrix.org@elvishjerricco:matrix.org There is no use case where systemd-repart alters only non-root disks and cannot be run in stage 2 and ordered before whatever services depend on it. 16:44:20
@elvishjerricco:matrix.org@elvishjerricco:matrix.org And there's absolutely no point in running it in stage 1 if running it requires initrd-fs.target to be reached 16:46:27
@elvishjerricco:matrix.org@elvishjerricco:matrix.org (the nixos module just requires sysroot.mount to be reached but if this is the design we're going with it really should wait for /sysroot/nix/store, and the simplest way is initrd-fs.target) 16:47:44
@nikstur:matrix.org@nikstur:matrix.org

The docs say this is the default: "By default when invoked on the regular system this defaults to the host's root file system /. If invoked from the initrd this defaults to /sysroot/, so that the tool operates on the configuration and machine ID stored in the root file system later transitioned into itself.". I tried to stay as close as possible to the default.

systemd-repart actually does not only look into sysusr. It also looks for configs in /sysroot/etc. E.g. see the conditions for the service:

ConditionDirectoryNotEmpty=|/sysroot/usr/lib/repart.d
ConditionDirectoryNotEmpty=|/sysroot/usr/local/lib/repart.d
ConditionDirectoryNotEmpty=|/sysroot/etc/repart.d
ConditionDirectoryNotEmpty=|/sysusr/usr/lib/repart.d
ConditionDirectoryNotEmpty=|/sysusr/usr/local/lib/repart.d

If I understand it correctly, your point is that the nix store might not be on sysroot but instead mounted later (alongside the other partitions marked with x-initrd.mount in the fstab). Thus, it would only be available after initrs-fs.target is reached. Then instead of sysroot.mount, we should use initrd-fs.target to order the systemd-repart service. That makes sense to me.

I also agree that /sysusr/ is the preferred/ideal way to store the config files in the systemd world. However, I don't see a way to imitate that in NixOS.

On the top of my head I can think of at least one solid use case where systemd-repart has to run in the initrd. Imagine you have disk images that only contain the Nix Store on the root fs without even space in the root fs to accomodate the rest of the / subtree created during activation. Repart can then make the space in the root fs after sysroot.mount (or even initrd-fs.target) but before activation.

I don't really love baking configuration (i.e. the repart configs) into the initrd if it can be avoided. And again, I think the current module is closer to how systemd-repart operates by default than the alternative of baking the configs into the initrd. But maybe we can give users the option in the module.

21:22:01
@nikstur:matrix.org@nikstur:matrix.orgSorry for the long ass reply. This was a good exercise to think it all through again :) 21:22:38
@nikstur:matrix.org@nikstur:matrix.org *

The docs say this is the default: "By default when invoked on the regular system this defaults to the host's root file system /. If invoked from the initrd this defaults to /sysroot/, so that the tool operates on the configuration and machine ID stored in the root file system later transitioned into itself.". I tried to stay as close as possible to the default.

systemd-repart actually does not only look into sysusr. It also looks for configs in /sysroot/etc. E.g. see the conditions for the service:

ConditionDirectoryNotEmpty=|/sysroot/usr/lib/repart.d
ConditionDirectoryNotEmpty=|/sysroot/usr/local/lib/repart.d
ConditionDirectoryNotEmpty=|/sysroot/etc/repart.d
ConditionDirectoryNotEmpty=|/sysusr/usr/lib/repart.d
ConditionDirectoryNotEmpty=|/sysusr/usr/local/lib/repart.d

If I understand it correctly, your point is that the nix store might not be on sysroot but instead mounted later (alongside the other partitions marked with x-initrd.mount in the fstab). Thus, it would only be available after initrs-fs.target is reached. Then instead of sysroot.mount, we should use initrd-fs.target to order the systemd-repart service. That makes sense to me.

I also agree that /sysusr/ is the preferred/ideal way to store the config files in the systemd world. However, I don't see a way to imitate that in NixOS.

On the top of my head I can think of at least one solid use case where systemd-repart has to run in the initrd. Imagine you have disk images that only contain the Nix Store on the root fs without even space in the root fs to accomodate the rest of the / subtree created during activation. Repart can then make the space in the root fs after sysroot.mount (or even initrd-fs.target) but before activation.

I don't really love baking configuration (i.e. the repart configs) into the initrd if it can be avoided. And again, I think the current module is closer to how systemd-repart operates by default than the alternative of baking the configs into the initrd. But maybe we can give users the option in the module.

21:25:01
@elvishjerricco:matrix.org@elvishjerricco:matrix.org

If invoked from the initrd this defaults to /sysroot/, so that the tool operates on the configuration and machine ID stored in the root file system later transitioned into itself

I think you're leaning heavily on this line as the only indication of how the docs want it to work in initrd. But I still think it's a misinterpretation. By defaulting to /sysroot, that includes the required disk formatting, and therefore comes before sysroot.mount and not after.

21:39:12
@elvishjerricco:matrix.org@elvishjerricco:matrix.org I'm made more confident about this given a comment I received from poettering suggesting that root fs formatting is the job of repart 21:40:46
@elvishjerricco:matrix.org@elvishjerricco:matrix.org

On the top of my head I can think of at least one solid use case where systemd-repart has to run in the initrd. Imagine you have disk images that only contain the Nix Store on the root fs without even space in the root fs to accomodate the rest of the / subtree created during activation. Repart can then make the space in the root fs after sysroot.mount (or even initrd-fs.target) but before activation.

Partitions can often be resized online. e.g. Look at how systemd-growfs works. The partition table is not part of the FS, so that can be changed without consequence. Then the FS can be adjusted to consume the whole partition online ala growfs

21:45:07
@elvishjerricco:matrix.org@elvishjerricco:matrix.org (in fact that's how fileSystems.<name>.autoResize works with systemd initrd enabled) 21:46:40
@elvishjerricco:matrix.org@elvishjerricco:matrix.org I maintain that there is no excuse for mounting the root FS before running systemd-repart in initrd. 21:47:46
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgah wait I misunderstood the example21:49:29
@elvishjerricco:matrix.org@elvishjerricco:matrix.orghmm21:49:51
@elvishjerricco:matrix.org@elvishjerricco:matrix.org well that use case would still be taken care of by running systemd-repart before mounting /sysroot 21:50:39
@nikstur:matrix.org@nikstur:matrix.org
In reply to @elvishjerricco:matrix.org

If invoked from the initrd this defaults to /sysroot/, so that the tool operates on the configuration and machine ID stored in the root file system later transitioned into itself

I think you're leaning heavily on this line as the only indication of how the docs want it to work in initrd. But I still think it's a misinterpretation. By defaulting to /sysroot, that includes the required disk formatting, and therefore comes before sysroot.mount and not after.

Well there is also this: "On systems where usr= is not used this target is ordered after sysroot.mount and thus mostly equivalent to initrd-root-fs.target." https://www.freedesktop.org/software/systemd/man/systemd.special.html#initrd-usr-fs.target which means the default Before= in the systemd-repart.service is essentially equivalet to Before=initrd-root-fs.target and then there is also this comment in the code: https://github.com/systemd/systemd/blob/main/src/partition/repart.c#L6109
21:51:10
@nikstur:matrix.org@nikstur:matrix.orgSo I fully agree that it would be awesome to even be able to create the root fs with systemd-repat (which means it has to run before sysroot.mount) but we don't have a /sysuser. So the only thing we can really do is bake the configs into the initrd, which I don't love but I'd be willing to offer it as an option. My argument is not that the current solution is the end-all be-all but that it has a purpose and we should not get rid of it, but we might add on to it. 21:53:10
@nikstur:matrix.org@nikstur:matrix.org * So I fully agree that it would be awesome to even be able to create the root fs with systemd-repart (which means it has to run before sysroot.mount) but we don't have a /sysuser. So the only thing we can really do is bake the configs into the initrd, which I don't love but I'd be willing to offer it as an option. My argument is not that the current solution is the end-all be-all but that it has a purpose and we should not get rid of it, but we might add on to it. 21:53:19
@elvishjerricco:matrix.org@elvishjerricco:matrix.org As far as I can tell, any usecase that requires systemd-repart being run in initrd is a use case where it's perfectly acceptable to put the config files in the initrd 21:55:37
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgwhen the purpose is to mess with the root fs before mounting, initrd is the correct place21:55:57
@elvishjerricco:matrix.org@elvishjerricco:matrix.organd if the purpose has nothing to do with the root fs, it almost certainly can/should be done in stage 221:57:19
@nikstur:matrix.org@nikstur:matrix.orgEven if I agree with that (and I'm not too far away) then the fact still remains that systemd-repart thinks its sensible to operate also on /sysroot. I think we should give the users the option to use the tool as close to the default as possible (even if there are compromises because NixOS works differently than other distros). All the users that think repart should exclusively run in stage 2 can still configure it that way. The module already offers this flexibility.22:01:35
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgThe docs don't say repart works on a mounted /sysroot by default. repart is designed to work on unmounted devices.22:03:22
@elvishjerricco:matrix.org@elvishjerricco:matrix.org When they say it defaults to /sysroot, they mean it works on the device that will be eventually mounted as /sysroot 22:04:05
@nikstur:matrix.org@nikstur:matrix.orgBut it finds config files in the sysroot. How can it find config files in the sysroot if it is not mounted?22:04:41
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgthat's a good question :P I'm not sure why they have code that checks that unless it's just for robustness22:05:21
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgbut given that poettering himself has told me that repart is meant to be used for partitioning the root disk, I'm heavily inclined to believe that's what it's for in initrd22:06:13
@nikstur:matrix.org@nikstur:matrix.orgI'm like 90% certain that it works on a mounted sysroot but maybe I'm also losing my mind.22:06:37
@elvishjerricco:matrix.org@elvishjerricco:matrix.org * but given that poettering himself has told me that repart is meant to be used for partitioning/formatting the root disk, I'm heavily inclined to believe that's what it's for in initrd22:06:40
@nikstur:matrix.org@nikstur:matrix.org
In reply to @elvishjerricco:matrix.org
but given that poettering himself has told me that repart is meant to be used for partitioning/formatting the root disk, I'm heavily inclined to believe that's what it's for in initrd
It definetely is. There is no contradiction. It can just do more than that
22:06:58
@elvishjerricco:matrix.org@elvishjerricco:matrix.orgI mean it very well might, even if that's just additional functionality22:07:06

Show newer messages


Back to Room ListRoom Version: 6