core,systemctl: refuse switching root if we're not in initrd

This commit is contained in:
Mike Yuan
2023-09-02 15:56:24 +08:00
parent b0c5f0e1f4
commit 4da159bc53
4 changed files with 24 additions and 16 deletions
+4
View File
@@ -5,6 +5,7 @@
#include "bus-locator.h"
#include "chase.h"
#include "fd-util.h"
#include "initrd-util.h"
#include "parse-util.h"
#include "path-util.h"
#include "proc-cmdline.h"
@@ -63,6 +64,9 @@ int verb_switch_root(int argc, char *argv[], void *userdata) {
} else
root = "/sysroot";
if (!in_initrd())
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Not in initrd, refusing switch-root operation.");
if (argc >= 3)
init = argv[2];
else {