07

September
2012

initrd versus initramfs

As Wikipedia nicely describes, initrd (initial ramdisk) is a scheme for loading a temporary file system into memory in the boot process of the Linux kernel. Initrd and initramfs refer to slightly different methods of achieving this. Both are commonly used to make preparations before the real root file system can be mounted, but there is a difference.

Initrd is a fixed-size block device, which requires to be 'formatted' by a filesystem such as ext2. It sits on /dev/ram0 by default, and cannot be enlarged or shortened.

On the other hand, initramfs is a cpio archive which is simply unpacked during boot to ramfs memory. This memory is of dynamic size and thus can be shortened or enlarged as needed.

So initramfs seems better, right? Not necessarily. The main problem is that it doesn't support pivot_root. What pivot_root does? It basically 'switches' from initrd to the new root (unioned data structures mounted from CD/USB), but initramfs somehow is not capable of that. It seems there was some circular reference and kernel developers disabled pivot_root for initramfs at all. And without pivot_root we cant transpose the current root with the new one. But I want to keep using initramfs.

Currently I'm able to (almost) accomplish the goal by mounting union over tmpfs, and then rbind mounting the tmpfs over a subdirectory in union. Seems strange, but works :) The only part which is left are the initramfs tools (busybox etc), I'd like to have those accessible as well in the chrooted environment. This will probably require copying, which I'm trying to avoid, so I'll keep digging ...

User comments