[英]switch_root busybox init problems?
我在带有busybox的嵌入式Linux环境中。 我已经通读了几篇 文章,试图学习如何使用switch_root 。 我尝试了这个:
exec switch_root -c /dev/console /mnt/newroot /bin/busybox init
将显示switch_root
帮助,并为我提供一个新的登录名:
[root@buildroot ~]# exec switch_root -c /dev/console /mnt/newroot /bin/busybox init
BusyBox v1.21.0 (2015-04-24 18:14:40 MDT) multi-call binary.
busybox init
Usage: switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGS]root /bin/busybox in
Free initramfs and switch to another root fs:
chroot to NEW_ROOT, delete all in /, move NEW_ROOT to /,
execute NEW_INIT. PID must be 1. NEW_ROOT must be a mountpoint.
-c DEV Reopen stdio to DEV after switch
Welcome to Buildroot
buildroot login:
当我登录时, newroot尚未加载,旧的仍然存在。 这是因为我直接从命令行而不是某种初始化脚本运行此命令吗?
我阅读了本文,发现它们在运行switch_root
之前执行其他步骤:
mount --move /sys /newroot/sys
mount --move /proc /newroot/proc
mount --move /dev /newroot/dev
首先,这使我感到困惑。 为什么要在运行switch_root
之前运行这些命令? switch_root
不帮我吗?
无论如何,我继续尝试先运行它们,然后再运行switch_root
命令。 但是,这完全可以解决问题:
[root@buildroot /]# switch_root -c /dev/console /mnt/newroot /bin/busybox init
BusyBox v1.21.0 (2015-04-24 18:14:40 MDT) multi-call binary.
Usage: switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGS]
Free initramfs and switch to another root fs:
chroot to NEW_ROOT, delete all in /, move NEW_ROOT to /,
execute NEW_INIT. PID must be 1. NEW_ROOT must be a mountpoint.
-c DEV Reopen stdio to DEV after switch
can't open /dev/ttyS0: No such file or directoryole /mnt/newroot /bin/busybox init
can't open /dev/ttyS0: No such file or directory
can't open /dev/ttyS0: No such file or directory
can't open /dev/ttyS0: No such file or directory
can't open /dev/ttyS0: No such file or directory
can't open /dev/ttyS0: No such file or directory
can't open /dev/ttyS0: No such file or directory
... message continues to repeat ...
如此看来,因为我已经移动了dev的安装架,所以当我的init运行并尝试将getty放在我的串行端口上时,找不到它了吗? 混乱........
我在这里缺少关于switch_root
基本switch_root
吗? 还是需要一些简单的命令行修改?
首先,正如其帮助文本所说, switch_root
必须作为PID 1执行。因此,它必须由使用exec
的初始化脚本来调用。
其次,(如您所见)手动移动tmpfilesystems是一个坏主意。 您收到的错误是因为您的控制台( /dev/ttyS0
)已通过mount --move
调用mount --move
。 switch_root
将自动删除那些安装。 因此,您的第二次初始化(由switch_root
)需要再次安装它们。
第三,这是我在initramfs中使用的init脚本的简短版本,应该可以帮助您:
#!/bin/sh
ROOT="/mnt/.root"
ROOT_DEV="/dev/sdb2"
echo "init from initramfs"
# mount temporary filesystems
mount -n -t devtmpfs devtmpfs /dev
mount -n -t proc proc /proc
mount -n -t sysfs sysfs /sys
mount -n -t tmpfs tmpfs /run
# mount new root
[ -d ${ROOT} ] || mkdir -p ${ROOT}
mount ${ROOT_DEV} ${ROOT}
# switch to new rootfs and exec init
cd ${ROOT}
exec switch_root . "/sbin/init" "$@"
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.