|
| 1 | +From 8993e7086444ca9b757b611f98834fa7a4e169c5 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Alexey Gladkov <legion@kernel.org> |
| 3 | +Date: Mon, 16 Jun 2025 09:42:16 +0200 |
| 4 | +Subject: [PATCH] switch_root: Make filesystem check not fatal |
| 5 | + |
| 6 | +The switch_root utility from util-linux does not fail if rootdev is not |
| 7 | +ramfs/tmpfs but only skips removing content from rootdev [1]. |
| 8 | + |
| 9 | +This change increases the compatibility of the switch_root utility |
| 10 | +between busybox and util_linux. |
| 11 | + |
| 12 | +[1] https://web.git.kernel.org/pub/scm/utils/util-linux/util-linux.git/tree/sys-utils/switch_root.c#n198 |
| 13 | + |
| 14 | +Signed-off-by: Alexey Gladkov <legion@kernel.org> |
| 15 | +--- |
| 16 | + util-linux/switch_root.c | 8 ++++---- |
| 17 | + 1 file changed, 4 insertions(+), 4 deletions(-) |
| 18 | + |
| 19 | +diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c |
| 20 | +index 14139736e..c3fef628b 100644 |
| 21 | +--- a/util-linux/switch_root.c |
| 22 | ++++ b/util-linux/switch_root.c |
| 23 | +@@ -245,13 +245,13 @@ int switch_root_main(int argc UNUSED_PARAM, char **argv) |
| 24 | + if ((unsigned)stfs.f_type != RAMFS_MAGIC |
| 25 | + && (unsigned)stfs.f_type != TMPFS_MAGIC |
| 26 | + ) { |
| 27 | +- bb_simple_error_msg_and_die("root filesystem is not ramfs/tmpfs"); |
| 28 | +- } |
| 29 | +- |
| 30 | +- if (!dry_run) { |
| 31 | ++ bb_simple_error_msg("root filesystem is not ramfs/tmpfs"); |
| 32 | ++ } else if (!dry_run) { |
| 33 | + // Zap everything out of rootdev |
| 34 | + delete_contents("/", rootdev); |
| 35 | ++ } |
| 36 | + |
| 37 | ++ if (!dry_run) { |
| 38 | + // Overmount / with newdir and chroot into it |
| 39 | + if (mount(".", "/", NULL, MS_MOVE, NULL)) { |
| 40 | + // For example, fails when newroot is not a mountpoint |
| 41 | +-- |
| 42 | +2.49.0 |
| 43 | + |
0 commit comments