The switch_root utility from util-linux does not fail if rootdev is not
ramfs/tmpfs but only skips removing content from rootdev [1].

This change increases the compatibility of the switch_root utility
between busybox and util_linux.

[1] 
https://web.git.kernel.org/pub/scm/utils/util-linux/util-linux.git/tree/sys-utils/switch_root.c#n198

Signed-off-by: Alexey Gladkov <leg...@kernel.org>
---
 util-linux/switch_root.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c
index 14139736e..c3fef628b 100644
--- a/util-linux/switch_root.c
+++ b/util-linux/switch_root.c
@@ -245,13 +245,13 @@ int switch_root_main(int argc UNUSED_PARAM, char **argv)
        if ((unsigned)stfs.f_type != RAMFS_MAGIC
         && (unsigned)stfs.f_type != TMPFS_MAGIC
        ) {
-               bb_simple_error_msg_and_die("root filesystem is not 
ramfs/tmpfs");
-       }
-
-       if (!dry_run) {
+               bb_simple_error_msg("root filesystem is not ramfs/tmpfs");
+       } else if (!dry_run) {
                // Zap everything out of rootdev
                delete_contents("/", rootdev);
+       }
 
+       if (!dry_run) {
                // Overmount / with newdir and chroot into it
                if (mount(".", "/", NULL, MS_MOVE, NULL)) {
                        // For example, fails when newroot is not a mountpoint
-- 
2.49.0

_______________________________________________
busybox mailing list
busybox@busybox.net
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to