A sleazy trick to capture debugging output from an initramfs

July 22, 2012

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 '>>/tmp/logfile'.)

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.

Written on 22 July 2012.
« Ubuntu 12.04 can't reliably boot with software RAID (and why)
The history of booting Linux with software RAID »

Page tools: View Source, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sun Jul 22 00:53:53 2012
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.