]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
detach-loopback: also don't bother detaching loopback block device /usr/ is running off
authorLennart Poettering <lennart@poettering.net>
Fri, 2 Jun 2023 09:42:08 +0000 (11:42 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 2 Jun 2023 13:56:06 +0000 (15:56 +0200)
While we are at it, let's also clean this up a bit: unlike DM/MD devices
loopback devices are likely partitioned, hence trace the block device
through the partition layer and LUKS.

src/shutdown/detach-loopback.c

index ceac74223c75e2901f751b7ef0ad32ee764844bc..f45960856bcd9372121c586dd3ce403ae926b195 100644 (file)
@@ -175,15 +175,21 @@ static int delete_loopback(const char *device) {
 
 static int loopback_points_list_detach(LoopbackDevice **head, bool *changed, bool last_try) {
         int n_failed = 0, r;
-        dev_t rootdev = 0;
+        dev_t rootdev = 0, usrdev = 0;
 
         assert(head);
         assert(changed);
 
-        (void) get_block_device("/", &rootdev);
+        (void) get_block_device_harder("/", &rootdev);
+        (void) block_get_whole_disk(rootdev, &rootdev);
+
+        (void) get_block_device_harder("/usr", &usrdev);
+        (void) block_get_whole_disk(usrdev, &usrdev);
 
         LIST_FOREACH(loopback_device, m, *head) {
-                if (major(rootdev) != 0 && rootdev == m->devnum) {
+                if ((major(rootdev) != 0 && rootdev == m->devnum) ||
+                    (major(usrdev) != 0 && usrdev == m->devnum)) {
+                        log_debug("Not detaching loopback device %s that backs the OS itself, skipping.", m->path);
                         n_failed++;
                         continue;
                 }