【发布时间】:2015-06-12 23:26:45
【问题描述】:
我在带有busybox 的嵌入式Linux 环境中。我已经阅读了severalposts,试图学习如何使用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 的一些基本信息吗?还是需要一些简单的命令行修改?
【问题讨论】: