pid1: skip cleanup if root is not tmpfs/ramfs
in_initrd() was really doing two things: checking if we're in the initrd, and also verifying that the initrd is set up correctly. But this second check is complicated, in particular it would return false for overlayfs, even with an upper tmpfs layer. It also doesn't support the use case of having an initial initrd with tmpfs, and then transitioning into an intermediate initrd that is e.g. a DDI, i.e. a filesystem possibly with verity arranged as a disk image. We don't need to check if we're in initrd in every program. Instead, concerns are separated: - in_initrd() just does a simple check for /etc/initrd-release. - When doing cleanup, pid1 checks if it's on a tmpfs before starting to wipe the old root. The only case where we want to remove the old root is when we're on a plain tempory filesystem. With an overlay, we'd be creating whiteout files, which is not very useful. (*) This should resolve https://bugzilla.redhat.com/show_bug.cgi?id=2137631 which is caused by systemd refusing to treat the system as an initrd because overlayfs is used. (*) I think the idea of keeping the initrd fs around for shutdown is outdated. We should just have a completely separate exitrd that is unpacked when we want to shut down. This way, we don't waste memory at runtime, and we also don't transition to a potentially older version of systemd. But we don't have support for this yet. This replaces 0fef5b0f0bd9ded1ae7bcb3e4e4b2893e36c51a6.
This commit is contained in:
+9
-11
@@ -3,6 +3,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "env-util.h"
|
||||
#include "errno-util.h"
|
||||
#include "initrd-util.h"
|
||||
#include "parse-util.h"
|
||||
#include "stat-util.h"
|
||||
@@ -16,14 +17,8 @@ bool in_initrd(void) {
|
||||
if (saved_in_initrd >= 0)
|
||||
return saved_in_initrd;
|
||||
|
||||
/* We make two checks here:
|
||||
*
|
||||
* 1. the flag file /etc/initrd-release must exist
|
||||
* 2. the root file system must be a memory file system
|
||||
*
|
||||
* The second check is extra paranoia, since misdetecting an
|
||||
* initrd can have bad consequences due the initrd
|
||||
* emptying when transititioning to the main systemd.
|
||||
/* If /etc/initrd-release exists, we're in an initrd.
|
||||
* This can be overridden by setting SYSTEMD_IN_INITRD=0|1.
|
||||
*/
|
||||
|
||||
r = getenv_bool_secure("SYSTEMD_IN_INITRD");
|
||||
@@ -32,9 +27,12 @@ bool in_initrd(void) {
|
||||
|
||||
if (r >= 0)
|
||||
saved_in_initrd = r > 0;
|
||||
else
|
||||
saved_in_initrd = access("/etc/initrd-release", F_OK) >= 0 &&
|
||||
path_is_temporary_fs("/") > 0;
|
||||
else {
|
||||
r = RET_NERRNO(access("/etc/initrd-release", F_OK));
|
||||
if (r < 0 && r != -ENOENT)
|
||||
log_debug_errno(r, "Failed to check if /etc/initrd-release exists, assuming it does not: %m");
|
||||
saved_in_initrd = r >= 0;
|
||||
}
|
||||
|
||||
return saved_in_initrd;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user