我在带有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:
当我登录时,新根还没有加载,旧的还在。这是因为我直接从命令行而不是从某种初始化脚本运行此命令吗?
我阅读了这篇文章,发现他们在运行之前执行了其他步骤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
吗?或者需要一些简单的命令行修改?