summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-switch-root.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemctl/systemctl-switch-root.c')
-rw-r--r--src/systemctl/systemctl-switch-root.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/systemctl/systemctl-switch-root.c b/src/systemctl/systemctl-switch-root.c
index cc31cf0e19..ae4a1a72c2 100644
--- a/src/systemctl/systemctl-switch-root.c
+++ b/src/systemctl/systemctl-switch-root.c
@@ -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 {