gpt4 book ai didi

Linux initramfs switch_root 无法找到内核使用的控制台

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:23:37 26 4
gpt4 key购买 nike

我的系统 (ARM32) 正在通过 U-Boot 启动 Linux。内核从 u-boot 获取 console=ttymxc1,115200 作为参数。然后它在 initramfs 中使用带有 switch_root(由 busybox 解释)的 shell 脚本来初始化根文件系统。此外,此 initramfs 脚本解析内核命令行以获取正确的 console

问题是 switch_root 正在打印到 tty1。尽管如此,内核还是使用了在其参数中指定的正确控制台。如果我没有将 -c 参数传递给 switch_root,它也会使用 /dev/tty1,这就是我的显示。

你们有没有人知道我如何让 init (sysvinit) 使用内核参数中指定的控制台?

这是 initramfs 脚本源:

#!/bin/sh

echo "init: rootfs setup"

# 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

read -r cmdline < /proc/cmdline

# define filesystems
ROOT_DEV="/dev/mydev"
ROOT="/newroot"

# mount rootfs
mkdir -p ${ROOT}
mount ${ROOT_DEV} ${ROOT}

# get & create console
CONSOLE=$(echo $cmdline) | sed 's/.*console=\(.*\),.*/\1/'
mknod -m 644 ${ROOT}/dev/${CONSOLE} c 5 1

# switch to new rootfs and exec init
echo "init: rootfs successful mounted (${ROOT})"
cd ${ROOT}
exec switch_root -c /dev/${CONSOLE} . "/sbin/init" "$@"

这是 initramfs config.cfg

dir /bin 755 1000 1000
dir /dev 755 0 0
dir /mnt 755 0 0
dir /proc 755 0 0
dir /run 755 0 0
dir /sys 755 0 0
file /bin/busybox initramfs/busybox 755 0 0
file /init initramfs/init 755 0 0
nod /dev/console 644 0 0 c 5 1
nod /dev/ttymxc1 644 0 0 c 5 1
slink /bin/chroot busybox 777 0 0
slink /bin/find busybox 777 0 0
slink /bin/grep busybox 777 0 0
slink /bin/mkdir busybox 777 0 0
slink /bin/mknod busybox 777 0 0
slink /bin/mount busybox 777 0 0
slink /bin/sed busybox 777 0 0
slink /bin/sh busybox 777 0 0

最佳答案

终于我找到了解决方案(以及我犯的错误)!

控制台设备是用错误的主要/次要编号创建的。使用与内核分配给 ttymxc* 相同的方式创建它,它可以工作:

mknod -m 644 ${ROOT}/dev/${CONSOLE} c 207 17

关于Linux initramfs switch_root 无法找到内核使用的控制台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39014689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com