如何在 init=/bin/bash 的早期引导阶段将 stdout 重定向到文件

问题描述

我有一个在早期启动 Bash 环境中运行的脚本,其中 init=/bin/bash。我想将脚本输出重定向到日志文件。但是,我收到一条错误消息,指出 /dev/fd/XX 不可用。

有没有办法做到这一点?

这是我的内核配置文件(在 RaspBerry Pi 上),cmdline.txt(为了可读性添加了新行;这实际上是一长行)

console=serial0,115200 console=tty1 root=PARTUUID=067e19d7-02 rootfstype=ext4
elevator=deadline fsck.repair=yes rootwait 
init=/bin/bash -c 
  "mount -t proc proc /proc; 
   mount -t sysfs sys /sys; 
   mount /boot; 
   source /boot/unattended"

/boot/unattended 内部

mount -t tmpfs tmp /run
mkdir -p /run/systemd
mount / -o remount,rw

# This is where I want to start redirecting command output
ls -la 
# Would like the above command output to go to a log file

通常,我会添加如下所示的代码片段……但这是在早期引导 shell 中失败的代码片段。

# Redirect stdout and stderr
exec >  >(tee -ia /boot/log/script_stdout.log >&1)
exec 2> >(tee -ia /boot/log/script_stderr.log >&2)

在早期的 Bash shell 中,这会导致:

bash: /dev/fd/62: No such file or directory

不用说,只有一些tty文件urandom,少数(我认为是)RPi视频设备节点(vc...),{{1} } 和 watchdog{0}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...