1

Many Linux systems boot to an initrd/initramfs, then mount the real root filesystem, chroot to it, and continue booting. My initrd is still technically mounted, but how can I get to it? If I modify my initrd to bind mount itself into the new root, then I can see it. But is it possible to access it without taking those steps? Is there a particular device file associated with initrds that I could bind mount?

On why I want this...

I have an embedded system where the root file system is an overlay of a tmpfs sitting on top of a squashfs image. I'd like to do work on a system, and then look at the tmpfs to see what file system changes I've made. Under normal operation without me modifying the boot, the mounts for the tmpfs and squashfs layers are hidden/lost once the system switches to the overlay root.

  • The overlay filesystem works with directories - if you do a mount then you should see it listed as something like overlay on / type overlay (rw,lowerdir=/media/overlay-ro,upperdir=/media/overlay-rw/overlay,workdir=/media/overlay-rw/_). You should be able to access the tmpfs directly via /media/overlay-rw/overlay/. – lane Jun 15 '17 at 12:45
2

from the linux kernel documentation under the linux/Documentation/initrd.txt:

  noinitrd

    initrd data is preserved but it is not converted to a RAM disk and
    the "normal" root file system is mounted. initrd data can be read
    from /dev/initrd. Note that the data in initrd can have any structure
    in this case and doesn't necessarily have to be a file system image.
    This option is used mainly for debugging.

    Note: /dev/initrd is read-only and it can only be used once. As soon
    as the last process has closed it, all data is freed and /dev/initrd
    can't be opened anymore.

that is, if you specify the noinitrd in your boot options, supposedly you can access the original initrd at the /initrd mountpoint after pivot_root switches to the "real" root, with the caveats noted above. I played with this maybe 2 decades ago, and don't know if it still works.

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.