1

I'm trying to log the early boot output from the init script. This is what is working:

mkdir -p /run/log && \
mkdir -p /tmp && \
mkfifo /tmp/stage-1-init.log.fifo1 && \
mkfifo /tmp/stage-1-init.log.fifo2

tee -i < /tmp/stage-1-init.log.fifo1 /run/log/stage-1-init.log &
exec > /tmp/stage-1-init.log.fifo1 2>&1

The above snippet is placed in the early boot init script (shell is busybox ash) inside initrd, and the output is logged to /run/log/stage-1-init.log file and I can view it later inside the booted system, and there is content inside.

However I'm also trying to add a sed filter to filter out empty lines:

mkdir -p /run/log && \
mkdir -p /tmp && \
mkfifo /tmp/stage-1-init.log.fifo1 && \
mkfifo /tmp/stage-1-init.log.fifo2

tee -i < /tmp/stage-1-init.log.fifo1 /tmp/stage-1-init.log.fifo2 &
sed '/^$/d' < /tmp/stage-1-init.log.fifo2 > /run/log/stage-1-init.log &
exec > /tmp/stage-1-init.log.fifo1 2>&1

The moment I change to the bottom script, there's no output in /run/log/stage-1-init.log at all. The file is completely empty, but the file is created.

I installed busybox locally on the booted system to test out ASH and busybox versions of tee and sed, and I ran the bottom variant, and it worked. But for some reason, during bootup the bottom variant results in an empty log file.

What could be going wrong? It feels like it has something to do with the redirection?

0

Solved it. Turns out I needed to reset the stdout and stderr file descriptors that I used before calling switch_root in the stage-1-init.sh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.