summaryrefslogtreecommitdiff
path: root/src/volatile-root
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-12-20 10:13:35 +0100
committerLennart Poettering <lennart@poettering.net>2019-03-01 14:11:07 +0100
commitd10b92cb5e0461efa3defe76a16605d73e3977c9 (patch)
tree0a026db0f8b1d4610c8dd01be35e0cdd502f76af /src/volatile-root
parent1de7f825d3a585846c7421041a21a1672eaf837d (diff)
downloadsystemd-d10b92cb5e0461efa3defe76a16605d73e3977c9.tar.gz
volatile-root: export original root
Diffstat (limited to 'src/volatile-root')
-rw-r--r--src/volatile-root/volatile-root.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/volatile-root/volatile-root.c b/src/volatile-root/volatile-root.c
index 02f6d31b05..701f5a2832 100644
--- a/src/volatile-root/volatile-root.c
+++ b/src/volatile-root/volatile-root.c
@@ -3,6 +3,7 @@
#include <sys/mount.h>
#include "alloc-util.h"
+#include "blockdev-util.h"
#include "escape.h"
#include "fs-util.h"
#include "main-func.h"
@@ -115,6 +116,7 @@ finish:
static int run(int argc, char *argv[]) {
VolatileMode m = _VOLATILE_MODE_INVALID;
const char *path;
+ dev_t devt;
int r;
log_setup_service();
@@ -166,6 +168,24 @@ static int run(int argc, char *argv[]) {
return 0;
}
+ /* We are about to replace the root directory with something else. Later code might want to know what we
+ * replaced here, hence let's save that information as a symlink we can later use. (This is particularly
+ * relevant for the overlayfs case where we'll fully obstruct the view onto the underlying device, hence
+ * querying the backing device node from the file system directly is no longer possible. */
+ r = get_block_device_harder(path, &devt);
+ if (r < 0)
+ return log_error_errno(r, "Failed to determine device major/minor of %s: %m", path);
+ else if (r > 0) {
+ _cleanup_free_ char *dn = NULL;
+
+ r = device_path_make_major_minor(S_IFBLK, devt, &dn);
+ if (r < 0)
+ return log_error_errno(r, "Failed to format device node path: %m");
+
+ if (symlink(dn, "/run/systemd/volatile-root") < 0)
+ log_warning_errno(errno, "Failed to create symlink /run/systemd/volatile-root: %m");
+ }
+
if (m == VOLATILE_YES)
return make_volatile(path);
else {