-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
nixos/systemd-initrd: silence various warnings #432704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0e3edec
to
6885eff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the solution to the first problem, but not the second.
# Defaults to true in the initrd. Setting to false prevents systemd | ||
# from attempting to remount a non-existent `/usr` as read-only. | ||
ProtectSystem = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do this instead of making an empty /usr
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My logic here was to prevent systemd from wasting time remounting it at all (since it would be empty anyway, it's not useful to remount it as read-only) instead of simply silencing it. But I'm happy to change it to create an empty /usr
if that's better (or maybe do both?), since technically it's fewer characters of code.
Here is the relevant code in systemd, it doesn't check if /usr
is empty and will always remount it, unless ProtectSystem disabled:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason that I like making an empty /usr
(and this is just me, the @NixOS/systemd team members might have a different opinion) is that ProtectSystem
might gain other semantics beyond remounting usr as read-only. Making an empty /usr
allows us to remain in the "default" zone with systemd settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After a few days thinking I will concede that making an empty /usr
is better, like you said, to be more compatible with systemd defaults in the future. I updated it to do that instead.
6885eff
to
ae2e694
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to build nixosTests.systemd-initrd-simple
, it freezes immediately with systemd[1]: Freezing execution.
Not sure why.
Interesting. I ran the test for The "Freezing execution" means systemd crashed. It looks like it does make
|
ae2e694
to
6885eff
Compare
Found the issue. We set
So this fixes it. diff --git a/nixos/modules/system/boot/systemd/initrd.nix b/nixos/modules/system/boot/systemd/initrd.nix
index 394cbb487b..ffce5e7e0d 100644
--- a/nixos/modules/system/boot/systemd/initrd.nix
+++ b/nixos/modules/system/boot/systemd/initrd.nix
@@ -506,6 +506,8 @@
"/bin".source = "${initrdBinEnv}/bin";
"/sbin".source = "${initrdBinEnv}/sbin";
+ "/usr/bin".source = "${initrdBinEnv}/bin";
+ "/usr/sbin".source = "${initrdBinEnv}/sbin";
"/etc/sysctl.d/nixos.conf".text = "kernel.modprobe = /sbin/modprobe";
"/etc/modprobe.d/systemd.conf".source = "${cfg.package}/lib/modprobe.d/systemd.conf";
diff --git a/pkgs/build-support/kernel/make-initrd-ng.nix b/pkgs/build-support/kernel/make-initrd-ng.nix
index e0a415a09b..35fd66e89d 100644
--- a/pkgs/build-support/kernel/make-initrd-ng.nix
+++ b/pkgs/build-support/kernel/make-initrd-ng.nix
@@ -100,7 +100,7 @@
++ lib.optional makeUInitrd ubootTools;
})
''
- mkdir -p ./root/{run,tmp,usr,var/empty}
+ mkdir -p ./root/{run,tmp,var/empty}
ln -s ../run ./root/var/run
make-initrd-ng "$contentsPath" ./root
mkdir "$out" |
Interesting that an unpopulated |
6885eff
to
970b0a6
Compare
Silences 2 warning messages that appear when using the systemd initrd: 1. "System tainted (var-run-bad)": occurs because `/var/run` isn't a symlink to `/run`. Fixed by making /run and linking /var/run to it. 2. "Failed to make /usr a mountpoint": occurs because ProtectSystem defaults to true in the initrd, which makes systemd try to remount `/usr` as read-only, which doesn't exist in the initrd. Fixed by linking `/usr/bin` and `/usr/sbin` to the initrd bin directories. Also moves the `/tmp` creation from the initrd module to make-initrd-ng, to avoid making an unnecessary `/tmp/.keep`, saving a store path and a few bytes in the initrd image.
970b0a6
to
216d98a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for figuring this out!
Silences 2 warning messages that appear when using the systemd initrd:
"System tainted (var-run-bad)": occurs because
/var/run
isn't a symlink to/run
. Fixed by making /run and linking /var/run to it."Failed to make /usr a mountpoint": occurs because ProtectSystem defaults to true in the initrd, which makes systemd try to remount
/usr
as read-only, which doesn't exist in the initrd. Fixed by linking/usr/bin
and/usr/sbin
to the initrd bin directories.Also moves the
/tmp
creation from the initrd module to make-initrd-ng, to avoid making an unnecessary/tmp/.keep
, saving a store path and a few bytes in the initrd image.Things done
passthru.tests
.nixpkgs-review
on this PR. See nixpkgs-review usage../result/bin/
.Add a 👍 reaction to pull requests you find important.