summaryrefslogtreecommitdiff
path: root/src/dissect
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-11-30 12:55:13 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-12-02 02:58:44 +0900
commit41a95b18bd5dfbaee583270768f156f5b39c8499 (patch)
tree56f5cc7310b55780b67ecbb168da1f547f2bbbff /src/dissect
parent040d34390301977f90ee2655300be15f8fa7a2e8 (diff)
downloadsystemd-41a95b18bd5dfbaee583270768f156f5b39c8499.tar.gz
dissect: support to unmount image without root partition
Fixes #25480.
Diffstat (limited to 'src/dissect')
-rw-r--r--src/dissect/dissect.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c
index 395294ebb4..3892bfb208 100644
--- a/src/dissect/dissect.c
+++ b/src/dissect/dissect.c
@@ -1194,6 +1194,19 @@ static int action_umount(const char *path) {
return log_error_errno(r, "Failed to determine whether '%s' is a mount point: %m", canonical);
r = block_device_new_from_fd(fd, BLOCK_DEVICE_LOOKUP_WHOLE_DISK | BLOCK_DEVICE_LOOKUP_BACKING, &dev);
+ if (r < 0) {
+ _cleanup_close_ int usr_fd = -1;
+
+ /* The command `systemd-dissect --mount` expects that the image at least has the root or /usr
+ * partition. If it does not have the root partition, then we mount the /usr partition on a
+ * tmpfs. Hence, let's try to find the backing block device through the /usr partition. */
+
+ usr_fd = openat(fd, "usr", O_CLOEXEC | O_DIRECTORY | O_NOFOLLOW);
+ if (usr_fd < 0)
+ return log_error_errno(errno, "Failed to open '%s/usr': %m", canonical);
+
+ r = block_device_new_from_fd(usr_fd, BLOCK_DEVICE_LOOKUP_WHOLE_DISK | BLOCK_DEVICE_LOOKUP_BACKING, &dev);
+ }
if (r < 0)
return log_error_errno(r, "Failed to find backing block device for '%s': %m", canonical);