[PATCH 1/3] host/initramfs: Use util-linux switch_root

Demi Marie Obenour
2025-09-15T00:20:35Z

Busybox switch_root doesn't move /proc, /dev, and /sys mounts, whereas
the switch_root from util-linux does.

Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
---
host/initramfs/default.nix | 3 ++-
host/initramfs/etc/init | 4 ----
2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/host/initramfs/default.nix b/host/initramfs/default.nix
index 1123feacc7533abaf079d84b04a269f784eb43b5..28378da220bb61a51e58b8b25846097f08746f5f 100644
--- a/host/initramfs/default.nix
+++ b/host/initramfs/default.nix
@@ -43,6 +43,7 @@ let
CONFIG_MODINFO n
CONFIG_MODPROBE n
CONFIG_RMMOD n
+ CONFIG_SWITCH_ROOT n
'';
})
];
@@ -56,7 +57,7 @@ let
# TODO: this is a hack and we should just build the util-linux
# programs we want.
# https://lore.kernel.org/util-linux/87zgrl6ufb.fsf@alyssa.is/
- cp ${util-linuxMinimal}/bin/{findfs,lsblk} $out/bin
+ cp ${util-linuxMinimal}/bin/{findfs,lsblk,switch_root} $out/bin
'';

microcode = runCommand "microcode.cpio" {
diff --git a/host/initramfs/etc/init b/host/initramfs/etc/init
index 719488741b6d31564c2c17c0e41f15d16b1c0a08..b3c5b7fbcf45e9646cf0404bc44dac58aa2dfe24 100755
--- a/host/initramfs/etc/init
+++ b/host/initramfs/etc/init
@@ -45,9 +45,5 @@ background { rm /dev/rootfs /dev/verity }
if { mount /dev/mapper/root-verity /mnt/root }
wait { $mdevd_pid }

-if { mount --move /proc /mnt/root/proc }
-if { mount --move /sys /mnt/root/sys }
-if { mount --move /dev /mnt/root/dev }
-
switch_root /mnt/root
/etc/init

--
2.51.0