Let Multiple Firecracker VMs Share a Root Filesystem with Copy-on-Write #3061
xmarcalx
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Special thanks to @pfandzelter for the write up. This discussion was generated by the contribution proposed in #2743.
Let Multiple Firecracker VMs Share a Root Filesystem with Copy-on-Write
An overlay (copy-on-write) filesystem lets multiple microVMs share a common read-only
filesystem on the host. Each microVM can still write changes to that filesystem
by using its own overlay. By default, files are read from the underlying root filesystem.
All changes are written to the overlay by copying the file and writing the modified
copy. If such a copy exists on the overlay, it takes precedence over whatever is
in the root filesystem.
As used by
firecracker-containerd
,this requires a root filesystem in
squashfs
mounted as read-only and a write-layerformatted as
ext4
, which can be either a temporarytempfs
in guest memory ora sparse
ext4
file on the host. The latter method has the advantage that changescan be persisted across microVM reboots if required.
Please note that this requires changes on the guest and is thus only possible
if you control the guest's init.
Convert rootfs to squashfs
If you already have an existing
rootfs
file formatted asext4
, e.g., createdaccording to the rootfs-and-kernel-setup
documentation, you can simply mount it and create a new
squashfs
formatted filesystemfrom that.
This requires
mksquashfs
, which is available as part of thesquashfs-tools
for you distribution.
Create a mounting point
Mount the existing rootfs (e.g.,
rootfs.ext4
). If you don't have an existingrootfs, you can skip this step and simply copy your files directly.
Create necessary folders for mounting the overlay filesystem. These mount points
have to be created now as the microVM will not be able to change anything on
the read-only filesystem.
Create the
overlay-init
script (adapted from overlay-init of firecracker-containerd).Create a
squashfs
formatted filesystemUnmount the old rootfs (if mounted in step 2).
Now we have successfully prepared the rootfs.
Creating an ext4 Formatted Persistent Overlay
To allow microVMs to save persistent files that are available after a reboot, we
need to create an
ext4
image to use as an overlay. If data does not need to beavailable again after a reboot, you can skip this step, as it is possible to use
an in-memory
tmpfs
as an overlay instead.be increased.
space as it currently needs. The file size may still be reported as 1 GiB
(the file's apparent size). Note that this requires your host filesystem
to support sparse files. Its actual size can be checked with the following
command (which should be 0 right now):
du
can also be used to report the apparent size of a file (1GiB in thisexample):
ext4
file system on the image file.Done! The overlay is ready now. Note that you need to create one filesystem per
microVM.
Configure the rootfs and Kernel Boot Parameters
To actually use the overlay filesystem correctly, you will need to adapt your Firecracker
configuration and boot parameters for you microVMs.
First, mount the new
squashfs
root filesystem as read-only. Note that this stepis optional but recommended. Simply set the
is_read_only
parameter in your Firecrackerdisk parameters to
true
for the root device.Second, set the
init
parameter to/sbin/overlay-init
to execute the initalizationof our overlay filesystem before starting the rest of the microVM's init process.
If you set the
overlay_root
toram
or leave it unset, atmpfs
will be createdand used as the write layer. Otherwise, add the
overlay.ext4
as a second driveand set
overlay_root
tovdb
(or mount it as a third drive and set tovdc
, etc.).Beta Was this translation helpful? Give feedback.
All reactions