2

I want to boot a system with an initramfs that's the actual final filesystem, not a temporary initramfs for loading drivers. Unfortunately, Linux imposes different (and in my case, undesirable) behaviors when using initramfs, including at least the following differences:

  • devtmpfs is not auto-mounted, at least not at first, but seems to get auto-mounted at some point later which I can't figure out.
  • Instead of running /sbin/init (or the init program specified by init= on the command line) the kernel attempts to invoke /init.

I know it's possible to work around these by putting some extra junk on the initramfs, but I'd rather it just behave like a normal root fs. Is there any way to achieve this?

If I do need to work around it with userspace scripting in the initramfs, I at least want to understand what triggers the auto-mounting of devtmpfs.

  • of course. it already does. the init executable has to explicitly do something like busybox's switch-root to do otherwise. so just don't do that and you're golden. and by the way, all that is done in initramfs is something like userspace scripting - initramfs is the first userspace. that's its job. – mikeserv Oct 10 '15 at 22:02
  • @mikeserv: Your comment is demonstrably false and does not address the question. – R.. Oct 10 '15 at 22:45
  • it is a comment, not an answer, and it is a true one. – mikeserv Oct 10 '15 at 22:45
  • @mikeserv: You can observe all the behaviors I described with a trivial initramfs containing nothing but a static-linked program named init which lists the contents of /dev. – R.. Oct 10 '15 at 22:46
  • 1
    @mikeserv: Despite being frustrating, discussing this was productive in tracking down the issue. I've added an answer including notes on why I expected what I want to be possible, why it's not practical without modifying the kernel, and how the kernel could be trivially modified to support it. – R.. Oct 11 '15 at 1:09
2

This is achievable if CONFIG_BLOCK is undefined, since init/do_mounts.c contains in mount_root, which runs after the kernel fails to execute /init on the initramfs, the following:

#ifdef CONFIG_BLOCK
    {
        int err = create_dev("/dev/root", ROOT_DEV);

        if (err < 0)
            pr_emerg("Failed to create /dev/root: %d\n", err);
        mount_block_root("/dev/root", root_mountflags);
    }
#endif

Source: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/init/do_mounts.c?id=c69e3c3a0c014e86750e78b7e2ae823f7a9b2cb2#n535

In this case, mount_root succeeds without having done anything and the kernel proceeds to treat the initramfs as a proper root fs.

Unfortunately, turning CONFIG_BLOCK off is not practical for most uses. What led me to believe this should work is that, on the patch for the particular development board I'm working with, the condition was replaced with:

#if defined(CONFIG_BLOCK) && !defined(CONFIG_INITRAMFS_SOURCE)

It would be nice to add support for root=initramfs that causes mount_root to return without doing anything, and this should be a trivial one-line patch. I have no idea whether it would be acceptable upstream, though.

0

Well, this is rather late but I have an answer that might help you:

First off, you'll want to include /dev/console in your initramfs. This will allow you to get sysinit functionality reporting back to the console (prints from userspace will again show up on your main display). Next, if you are using busybox for your init process, add a sym-link to busybox in the root of your RFS called init. The problem is that the Linux kernel filesystem layer changed a few years back. Originally, you HAD to have /init to launch the system. This was thought of as a security hole and was relocated to /sbin/init. Later, IIRC, this became linuxrc but I believe it has been removed all together now.

In my inittab, the first two lines are mount proc and mount devtmpfs. All seems to work correctly.

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.