# Linux Kernel Module Cheat

### 8.2. initramfs

initramfs is just like initrd, but you also glue the image directly to the kernel image itself using the kernel’s build system.

Try it out with:

    ./build-buildroot --initramfs
    ./build-linux --initramfs
    ./run --initramfs

Notice how we had to rebuild the Linux kernel this time around as well after Buildroot, since in that build we will be gluing the CPIO to the kernel image.

Now, once again, if we look at the QEMU run command generated, we see all that QEMU needs is the `-kernel` option, no `-drive` not even `-initrd`! Pretty cool:

    cat "$(./getvar run_dir)/run.sh"

It is also interesting to observe how this increases the size of the kernel image if you do a:

    ls -lh "$(./getvar linux_image)"

before and after using initramfs, since the `.cpio` is now glued to the kernel image.

Don’t forget that to stop using initramfs, you must rebuild the kernel without `--initramfs` to get rid of the attached CPIO image:

    ./build-linux
    ./run

Alternatively, consider using Linux kernel build variants if you need to switch between initramfs and non initramfs often:

    ./build-buildroot --initramfs
    ./build-linux --initramfs --linux-build-id initramfs
    ./run --initramfs --linux-build-id

Setting up initramfs is very easy: our scripts just set `CONFIG_INITRAMFS_SOURCE` to point to the CPIO path.

http://nairobi-embedded.org/initramfs_tutorial.html shows a full manual setup.