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

Alyssa Ross
2025-09-17T11:44:31Z

[-- Attachment #1: Type: text/plain, Size: 2168 bytes --]

Demi Marie Obenour <demiobenour@gmail.com> writes:

> 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(-)

So on the whole, I'm in favour of getting rid of Busybox wherever
possible, because its implementations tend to be bad. In the case of
initramfs though, the potential for unexpected circumstances is very
constrained, and we need something to implement mkfifo, head, kill, and
rm. So given we're using Busybox for that anyway, we might as well use
Busybox's smaller implementation of switch_root, right?

> 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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]