bash - 如何在 init=/bin/bash 的早期引导阶段将标准输出重定向到文件
问题描述
我有一个在早期启动 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...
)watchdog{0}
和zero
.
解决方案
推荐阅读
- c# - Owin如何使用OAuthAuthorizationServer?
- r - ggplot中舍入数据标签的问题
- dart - 覆盖 Dart 的本地时区
- r - 如何更正我的代码以在 R 中使用 ggplot2 运行堆积条形图?
- azure-application-insights - Web 应用程序上的分析
- hardware - 同时在一台显示器上使用两个 HDMI 输入
- loopbackjs - 全局 createOptionsFromRemotingContext
- c++ - 如何通过一个或多个参数实现搜索
- python - Python:读取和操作 DataFrame 数据时出错
- android - 构建时的 transformClassesWithDexBuilderForDebug 错误