Creating Custom rootfs and kernel Images
Creating a kernel Image
Currently, Firecracker supports only uncompressed, ELF kernel images. You can build an uncompressed Linux kernel image with:
Here's a quick step-by-step guide to building your own kernel that Firecracker can boot:
Get the Linux source code:
Check out the Linux version you want to build (e.g. we'll be using v4.20 here):
You will need to configure your Linux build. You can start from our recommended config by copying it to
.config(under the Linux sources dir). You can make interactive config adjustments using:Note: there are many ways of building a kernel config file, other than
menuconfig. You are free to use whichever one you choose.Build the uncompressed kernel image:
Upon a successful build, you can find the uncompressed kernel image under
./vmlinux.
Creating a rootfs Image
A rootfs image is just a file system image, that hosts at least an init system. For instance, our getting started guide uses an EXT4 FS image with OpenRC as an init system. Note that, whichever file system you choose to use, support for it will have to be compiled into the kernel, so it can be mounted at boot time.
To build an EXT4 image:
Prepare a properly-sized file. We'll use 50MiB here, but this depends on how much data you'll want to fit inside:
Create an empty file system on the file you created:
You now have an empty EXT4 image in rootfs.ext4, so let's prepare to populate it. First, you'll need to mount this new file system, so you can easily access its contents:
The minimal init system would be just an ELF binary, placed at /sbin/init. The final step in the Linux boot process executes /sbin/init and expects it to never exit. More complex init systems build on top of this, providing service configuration files, startup / shutdown scripts for various services, and many other features.
For the sake of simplicity, let's set up an Alpine-based rootfs, with OpenRC as an init system. To that end, we'll use the official Docker image for Alpine Linux:
First, let's start the Alpine container, bind-mounting the EXT4 image created earlier, to
/my-rootfs:Then, inside the container, install the OpenRC init system, and some basic tools:
And set up userspace init (still inside the container shell):
Finally, unmount your rootfs image:
You should now have a kernel image (vmlinux) and a rootfs image (rootfs.ext4), that you can boot with Firecracker.