summaryrefslogtreecommitdiff
path: root/src/nspawn
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-12 16:59:15 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-12 17:30:25 +0100
commitc4e34a612c81266773cf8358cb38a43d2e43474e (patch)
tree30365df7de959342130bd88d1ce6d6be7c32d73d /src/nspawn
parentdf9a75e480ecbfe230589a7c1e8e0bb790ee0595 (diff)
nspawn: allow spawning ephemeral nspawn containers based on the root file system of the OS
This works now: # systemd-nspawn -xb -D / -M foobar Which boots up an ephemeral container, based on the host's root file system. Or in other words: you can now run the very same host OS you booted your system with also in a container, on top of it, without having it interfere. Great for testing whether the init system you are hacking on still boots without reboot the system!
Diffstat (limited to 'src/nspawn')
-rw-r--r--src/nspawn/nspawn.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index f6f20abdaf..651a45126b 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -2942,8 +2942,8 @@ int main(int argc, char *argv[]) {
if (arg_directory) {
assert(!arg_image);
- if (path_equal(arg_directory, "/")) {
- log_error("Spawning container on root directory not supported.");
+ if (path_equal(arg_directory, "/") && !arg_ephemeral) {
+ log_error("Spawning container on root directory is not supported. Consider using --ephemeral.");
r = -EINVAL;
goto finish;
}
@@ -2964,7 +2964,21 @@ int main(int argc, char *argv[]) {
} else if (arg_ephemeral) {
char *np;
- r = tempfn_random(arg_directory, &np);
+ /* If the specified path is a mount point we
+ * generate the new snapshot immediately
+ * inside it under a random name. However if
+ * the specified is not a mount point we
+ * create the new snapshot in the parent
+ * directory, just next to it. */
+ r = path_is_mount_point(arg_directory, false);
+ if (r < 0) {
+ log_error_errno(r, "Failed to determine whether directory %s is mount point: %m", arg_directory);
+ goto finish;
+ }
+ if (r > 0)
+ r = tempfn_random_child(arg_directory, &np);
+ else
+ r = tempfn_random(arg_directory, &np);
if (r < 0) {
log_error_errno(r, "Failed to generate name for snapshot: %m");
goto finish;