title: How to redirect stdout to a file in an early boot stage where init=/bin/bash
body: <p>I have a script that runs inside an early boot Bash environment, where <code>init=/bin/bash</code>.  I want to redirect script output to a log file.  However, I get an error message saying that <code>/dev/fd/XX</code> is not available.</p>
  <p>Is there a way to accomplish this?</p>
  <p>This is my kernel config file (on a Raspberry Pi), <code>cmdline.txt</code> (new lines added for readability; this is actually one long line)</p>
  <pre><code>console=serial0,115200 console=tty1 root=PARTUUID=067e19d7-02 rootfstype=ext4
  elevator=deadline fsck.repair=yes rootwait 
  init=/bin/bash -c 
    &quot;mount -t proc proc /proc; 
     mount -t sysfs sys /sys; 
     mount /boot; 
     source /boot/unattended&quot;
  </code></pre>
  <p>Inside of <code>/boot/unattended</code></p>
  <pre><code>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
  </code></pre>
  <p>Typically, I would add a code snippet like the one below ... but this is the one that fails in the early boot shell.</p>
  <pre><code># Redirect stdout and stderr
  exec &gt;  &gt;(tee -ia /boot/log/script_stdout.log &gt;&amp;1)
  exec 2&gt; &gt;(tee -ia /boot/log/script_stderr.log &gt;&amp;2)
  </code></pre>
  <p>In the early Bash shell, this results in:</p>
  <pre><code>bash: /dev/fd/62: No such file or directory
  </code></pre>
  <p>Needless to say, there is only a number of <code>tty</code> files, <code>urandom</code>, a few (what I think is) RPi video device nodes (<code>vc...</code>), <code>watchdog{0}</code> and <code>zero</code>.</p>