A sleazy trick to capture debugging output from an initramfs
Suppose, not entirely hypothetically, that something in your system's initramfs is failing or that you just want to capture some debugging output or state information in general. The traditional way to do this when console output isn't good enough is to just dump the output into a file and read the file later, but this has a problem in the initramfs world; the file you write out will be in the initramfs, which means that it will quietly disappear when boot process is finished and the initramfs goes away.
So we need two things. We need to preserve the initramfs or at least the bit of it that we care about, and then we need some way to get access to it. There is probably an official way to do this, but here is my sleazy trick.
We can preserve a file from the initramfs by starting a process in the initramfs (and then having it stay running) that has a file descriptor for the file. For example (on Ubuntu 12.04):
(udevadm monitor >/tmp/logfile 2>&1) &
(I believe that even something like '
sleep 16000 >/tmp/logfile &'
should do it. You can then have other commands append things to it with
There are undoubtedly clever ways to preserve the initramfs or get
access to it, but once you have a preserved file descriptor there's a
simpler brute force way. Simply look at
/proc/<pid>/fd/<N> (<N> is
often 1 or 2) and there's your debug file. You can now use whatever tool
you like (including a pager like
less) to look at it.