Firecracker (firecracker v0.1.0)
View SourceFirecracker is a low-level interface for interacting with Firecracker VMs.
This library is intentionally low-level and makes few deviations from the API surface exposed by Firecracker. If you are looking for a simpler, higher-level VM orchestrator, stay tuned.
System Requirements
In order to run Firecracker, you must be running on a machine that supports virtualizaiton and KVM. You can use the checkenv devtool provided by the Firecracker developers to determine if your machine supports running the Firecracker binary.
Overview
Firecracker lets you create VMs programmatically. You start by creating a new VM
struct with Firecracker.new/1:
vm = Firecracker.new()This creates a %Firecracker{} struct which is meant to be an Elixir representation of
a Firecracker VM.
You can configure the VM by manipulating the data structure with the various helper
functions. Options are configurable via Firecracker.set_option/3:
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")Options represent Firecracker "process" options and are mostly one-to-one to the binary
CLI arguments. Detailed VM configuration options can be configured via Firecracker.configure/3
or Firecracker.add/4.
Firecracker.configure/3 lets you configure VM-specific settings. For example, you can configure
the machine configuration:
vm =
Firecracker.new()
|> Firecracker.configure(:machine_config, vcpu_count: 3)Firecracker.add/4 lets you add VM devices such as drives, network interfaces or persistent memory devices:
vm =
Firecracker.new()
|> Firecracker.add(:drive, "root", is_root_device: true)VM configurations map directly to the VM configurations present in the Firecracker API. See the respective module documentation for per-resource options:
Firecracker.BalloonFirecracker.BootSourceFirecracker.CpuConfigFirecracker.DriveFirecracker.EntropyFirecracker.LoggerFirecracker.MachineConfigFirecracker.MmdsConfigFirecracker.NetworkInterfaceFirecracker.PmemFirecracker.SerialFirecracker.Vsock
Prerequisites
Before you can use this library, you should ensure you have the Firecracker binary and jailer binary downloaded on your system. You can download all of the Firecracker project binaries with the mix task:
mix firecracker.installThis will download the latest Firecracker binaries for your system architecture to
$HOME/.firecracker/bin.
Starting Firecracker VMs
Calling Firecracker.new/1 does not actually start a Firecracker process. The struct
representation is data-only up until the point you call Firecracker.start/1:
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.start()After starting, you'll notice the struct state changes from :initial to :started and
has an attached PID. This PID represents the externally running Firecracker process. It's
important to note that this library does not do any automatic cleanup. Failure to call
Firecracker.stop/1 on created VMs will result in zombie processes.
Firecracker.start/1 simply starts the Firecracker process. To boot the actual VM you
must call Firecracker.boot/1. In order to boot, you need to configure the VM with a kernel
image and rootfs:
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.configure(:boot_source, kernel_image_path: kernel)
|> Firecracker.add(:drive, "rootfs",
path_on_host: rootfs,
is_root_device: true,
is_read_only: false
)
|> Firecracker.start()
|> Firecracker.boot()After booting a VM, you can pause the VM:
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.configure(:boot_source, kernel_image_path: kernel)
|> Firecracker.add(:drive, "rootfs",
path_on_host: rootfs,
is_root_device: true,
is_read_only: false
)
|> Firecracker.start()
|> Firecracker.boot()
paused = Firecracker.pause(vm)Or shutdown the VM:
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.configure(:boot_source, kernel_image_path: kernel)
|> Firecracker.add(:drive, "rootfs",
path_on_host: rootfs,
is_root_device: true,
is_read_only: false
)
|> Firecracker.start()
|> Firecracker.boot()
shutdown = Firecracker.shutdown(vm)Note that shutting down the VM does not kill the Firecracker process. To stop the running
process, you must use Firecracker.stop/1:
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.configure(:boot_source, kernel_image_path: kernel)
|> Firecracker.add(:drive, "rootfs",
path_on_host: rootfs,
is_root_device: true,
is_read_only: false
)
|> Firecracker.start()
|> Firecracker.boot()
Firecracker.stop(vm)Firecracker.stop/1 will ensure all of the resources associated with the VM are cleaned up
properly. Internally, Firecracker.stop/1 sends SIGTERM to the running process, waits for
the process to exit, and then cleans up all created sockets. The returned VM will be in an
:exited state and cannot be restarted.
Applying configuration changes
At any point after a VM has been started, you can change a VM's configuration
options and re-apply them to the VM using Firecracker.apply/1. Configuration changes via
functions like Firecracker.configure/3 and Firecracker.add/4 are data only until they
have been properly applied:
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.configure(:boot_source, kernel_image_path: kernel)
|> Firecracker.start()
# change the kernel and add a rootfs after start
vm =
Firecracker.new()
|> Firecracker.configure(:boot_source, kernel_image_path: new_kernel)
|> Firecracker.add(:drive, "rootfs",
path_on_host: rootfs,
is_root_device: true,
is_read_only: false
)
# apply the changes
vm = Firecracker.apply(vm)You can inspect what configuration changes will be applied by using Firecracker.dry_run/1
IO.inspect Firecracker.dry_run(vm)
# will show a configuration object
%{config: "vsock" => %{"guest_cid" => 3, "uds_path" => "/tmp/vsock.sock"}}The Firecracker data structure keeps track of which configurations have changed since the last persisted update, and will only make the changes necessary.
Note that some changes are valid only pre-boot. If you attempt to make a change which is invalid after a VM is in a booted state, the update will fail.
Jailer
You can configure the VM to run within the Firecracker Jailer for enhanced security and resource isolation. The jailer provides sandboxing by switching to a non-root user, constraining the microVM to a chroot environment, and optionally setting up cgroups and resource limits.
To use the jailer, you must configure it before starting the VM. The uid and gid options are required:
vm =
Firecracker.new()
|> Firecracker.jail(uid: 1000, gid: 1000)
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.start()You can optionally specify additional jailer configuration:
vm =
Firecracker.new()
|> Firecracker.jail(
uid: 1000,
gid: 1000,
chroot_base_dir: "/srv/myjailer",
netns: "/var/run/netns/custom-ns",
parent_cgroup: "custom.slice"
)Configuring cgroups
Once a jailer is configured, you can set cgroup constraints:
vm =
Firecracker.new()
|> Firecracker.jail(uid: 1000, gid: 1000)
|> Firecracker.cgroup("memory.limit_in_bytes", "512M")
|> Firecracker.cgroup("cpu.cfs_quota_us", "100000")Configuring resource limits
You can also set resource limits for the jailed process:
vm =
Firecracker.new()
|> Firecracker.jail(uid: 1000, gid: 1000)
|> Firecracker.resource_limit("fsize", 1024 * 1024 * 1024)
|> Firecracker.resource_limit("no-file", 1024)Inspection
At any point after starting a VM, you can inspect the configuration options and status
of the VM using Firecracker.describe/1 or Firecracker.describe/2. Firecracker.describe/1
will provide basic information about the state of your VM:
Firecracker.describe(vm)This will show:
%{
"id" => "anonymous-instance",
"state" => "Running",
"app_name" => "Firecracker",
"vmm_version" => "1.0.0"
}Firecracker.describe/2 can be used to inspect specific configurations and metadata:
# Inspect machine configuration
machine_config = Firecracker.describe(vm, :machine_config)
# Returns CPU count, memory size, etc.
# Check balloon device configuration
balloon_config = Firecracker.describe(vm, :balloon)
# Returns target memory size if balloon is configured
# Get balloon statistics (memory reclamation stats)
balloon_stats = Firecracker.describe(vm, :balloon_statistics)
# Returns actual memory usage, target memory, etc.
# View metadata store contents
mmds_data = Firecracker.describe(vm, :mmds)
# Returns the current metadata key-value pairs
# Get complete VM configuration
vm_config = Firecracker.describe(vm, :vm_config)
# Returns full configuration including drives, network interfaces, etc.Snapshots
Firecracker supports creating snapshots of running VMs, which capture the complete state of the microVM including CPU registers, device states, and memory contents. Snapshots can be used for fast VM startup from saved states, creating VM templates, or implementing rollback functionality.
To create a snapshot, the VM must first be paused. Only paused VMs can be snapshotted to ensure consistent state:
# Start and boot a VM
vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker.sock")
|> Firecracker.configure(:boot_source, kernel_image_path: kernel)
|> Firecracker.add(:drive, "rootfs",
path_on_host: rootfs,
is_root_device: true,
is_read_only: false
)
|> Firecracker.start()
|> Firecracker.boot()
# Pause the VM to prepare for snapshot
paused_vm = Firecracker.pause(vm)
# Create a full snapshot
snapshot = Firecracker.snapshot(paused_vm,
mem_file_path: "/path/to/memory.mem",
snapshot_path: "/path/to/vm-state.json",
type: :full
)Firecracker supports two types of snapshots:
:fullsnapshots capture the complete VM state and memory:diffsnapshots capture only the changes since the last snapshot
To load a snapshot, you must create and start (but not boot!) a VM. Then, you can load
the VM from a snapshot created with Firecracker.snapshot/2, or from a snapshot configured
using the Firecracker.Snapshot module:
new_vm =
Firecracker.new()
|> Firecracker.set_option(:api_sock, "/tmp/firecracker-new.sock")
|> Firecracker.start()
# Create a snapshot from file paths
snapshot = Firecracker.Snapshot.new(
path: "/path/to/vm-state.json",
type: :full,
mem_file_path: "/path/to/file.mem"
)
resumed_vm = Firecracker.load(new_vm, snapshot)When loading snapshots, you can override network interface configurations to adapt to different host environments:
snapshot =
Firecracker.Snapshot.new(
path: "/path/to/vm-state.json",
type: :full,
mem_file_path: "/path/to/memory.mem"
)
|> Firecracker.Snapshot.network_override("eth0", host_dev_name: "tap1")
restored_vm = Firecracker.load(new_vm, snapshot)This is particularly useful when:
- Restoring VMs on different hosts
- The original TAP device names are no longer available
- You need to reconfigure networking after restore
Metadata
Firecracker provides a metadata service (MMDS) that allows you to inject custom data into your VMs. This metadata can be accessed from within the VM and is particularly useful for configuration management, initialization scripts, and passing runtime parameters.
You can configure metadata for your VM using the Firecracker.metadata/2 and Firecracker.metadata/3
functions. There are two ways to set metadata. Either by setting the complete metadata up front:
vm =
Firecracker.new()
|> Firecracker.metadata(%{
"user_data" => "#!/bin/bashecho 'Hello from metadata!'",
"hostname" => "firecracker-vm",
"environment" => "production",
"config" => %{
"database_url" => "postgres://localhost:5432/mydb",
"api_key" => "abc123"
}
})Or by setting/updating individual keys:
vm =
Firecracker.new()
|> Firecracker.metadata("user_data", "#!/bin/bashecho 'Hello!'")
|> Firecracker.metadata("instance_id", "i-1234567890abcdef")Like other configuration changes, metadata modifications are data-only until applied. You need to explicitly apply them:
# Before starting the VM
vm =
Firecracker.new()
|> Firecracker.metadata("hostname", "web-server-1")
|> Firecracker.start() # Metadata is applied when starting
# After the VM is running
vm =
vm
|> Firecracker.metadata("status", "active")
|> Firecracker.apply() # Apply metadata changes to running VMYou can inspect the metadata of a VM using Firecracker.describe/2 with :mmds key:
Firecracker.describe(vm, :mmds)I/O Rate Limiters
Firecracker provides fine-grained control over I/O operations through rate limiters that use a token bucket algorithm. These limiters help manage resource contention and ensure predictable performance when running multiple VMs.
Rate limiters control two aspects of I/O operations:
- Bandwidth - controls data transfer rate (bytes per second)
- Operations - controls frequency of I/O operations (operations per second)
You can create rate limiters with specific configurations:
# Basic rate limiter with default settings
limiter = Firecracker.RateLimiter.new()
# Rate limiter with bandwidth constraints
limiter = Firecracker.RateLimiter.new(
bandwidth: [
size: 10_000_000, # 10MB bucket size
refill_time: 100, # Refill every 100ms
one_time_burst: 5_000_000 # 5MB initial burst
]
)
# Rate limiter with operations constraints
limiter = Firecracker.RateLimiter.new(
ops: [
size: 1000, # 1000 operations max
refill_time: 1000, # Refill every second
one_time_burst: 100 # 100 extra ops for burst
]
)
# Combined bandwidth and operations limits
limiter = Firecracker.RateLimiter.new(
bandwidth: [size: 5_000_000, refill_time: 50],
ops: [size: 500, refill_time: 100]
)And apply them to any configuration that supports rate limiters:
Firecracker.configure(vm, :entropy, rate_limiter: limiter)
Summary
Creation
Creates a new data-only representation of a VM.
Configuration
Adds the given interface to the VM.
Applies configuration changes to the VM.
Updates the VM configuration given by the given key.
Flushes metrics to the configured metrics file or pipe.
Configures the given VM with the given metadata.
Configures the given metadata key to have the given value.
Configures or updates the given metadata key with a default
value or function.
Sets the given Firecracker option key with value.
Sets the given Firecracker options.
Configures tracing for the VM's API requests.
Lifecycle
Boots a Firecracker VM.
Pauses a Firecracker VM.
Resumes a paused Firecracker VM.
Shutsdown a Firecracker VM.
Starts a new Firecracker VM with the given configuration.
Stops a Firecracker VM.
Inspection
Describes information about the given Firecracker instance.
Describes information about the given Firecracker instance configuration key.
Describes the changes that will be applied on start or application.
Jailer
Configures the given VM to run with the given cgroup value.
Configures the given VM to run in the context of the Firecracker Jailer.
Configures the given VM to run with the given resource limits.
Helpers
Returns the Firecracker snapshot version using the environment Firecracker binary, or the default binary.
Returns the Firecracker snapshot version for the VM.
Returns the Firecracker version using the environment Firecracker binary, or the default binary.
Returns the Firecracker version for the VM.
Returns the default Firecracker binary as given by the environment or default value.
Return the Firecracker binary for the given VM.
Creation
Creates a new data-only representation of a VM.
Options passed here will set CLI options for use before running the Firecracker binary.
Options
:api_sock- Path of the unix socket to use for the VM API. Defaults to"/tmp/firecracker.#{System.unique_integer([:positive])}}.sock".:boot_timer- Whether or not to load boot timer device for logging elapsed time since InstanceStart command.:config_file- Path to a file that contains the microVM configuration in JSON format. Note that setting this option will override any configurations you set. This is not recommended.:enable_pci- Enables PCIe support.:http_api_max_payload_size- Http API request payload max size, in bytes. Defaults to 51200.:id- MicroVM unique identifier. Defaults to"anonymous-instance-#{System.unique_integer([:positive])}". IDs should unique across all running VM instances.:level- Firecracker log level.:log_path- Path to a fifo or file used for configuring the logger on startup.:metadata- Path to a file that contains metadata in JSON format to add to the mmds.:metrics_path- Path to a fifo or a file used for configuring the metrics on startup.:mmds_size_limit- Mmds data store limit, in bytes.:module- Set the logger module filter.:no_api- Optional parameter which allows starting and using a microVM without an active API socket.:no_seccomp- Optional parameter which allows starting and using a microVM without seccomp filtering. Not recommended.:parent_cpu_time_us- Parent process CPU time (wall clock, microseconds). This parameter is optional.:seccomp_filter- Optional parameter which allows specifying the path to a custom seccomp filter. For advanced users.:show_level- Whether or not to output the level in the logs.:show_log_origin- Whether or not to include the file path and line number of the log's origin.:start_time_cpu_us- Process start CPU time (wall clock, microseconds). This parameter is optional.:start_time_us- Process start time (wall clock, microseconds). This parameter is optional.
Configuration
Adds the given interface to the VM.
Valid interfaces are:
:drive- Add a drive to the VM:network_interface- Add a network interface to the VM:pmem- Add a persistent memory device to the VM
id must be a unique string key identifying the interface. If id already
exists, the interface will be modified with the updated configuration. id
overwrites Firecracker-specific identifiers you may set, e.g. drive_id,
iface_id, and id respectively.
See Firecracker.Drive, Firecracker.NetworkInterface, and Firecracker.Pmem
for available device-specific configuration options.
Applies configuration changes to the VM.
Firecracker struct keeps track of un-applied configuration changes and applies them using the running REST API.
The struct will also keep track of any errors accumulated
during application of changes. If a particular configuration change
results in an error, the field will be left in an "un-applied" state,
and the error will be prepended to the :errors field of the VM
struct.
@spec configure(t(), configurable(), keyword()) :: t()
Updates the VM configuration given by the given key.
Valid configurables are:
* `:balloon`
* `:boot_source`
* `:cpu_config`
* `:entropy`
* `:logger`
* `:machine_config`
* `:metrics`
* `:mmds_config`
* `:serial`
* `:vsock`Configuration options for each API map directly to the Firecracker API spec. See the corresponding configuration module's documentation for more detailed information.
Note this change is data-only. Changes are only applied after calling
Firecracker.start/1 or Firecracker.apply/1.
Flushes metrics to the configured metrics file or pipe.
This triggers an immediate flush of all accumulated metrics to the metrics destination configured via the metrics_path option. Useful for ensuring metrics are written before taking snapshots or for periodic metrics collection.
Returns the updated VM struct.
Configures the given VM with the given metadata.
This operation replaces all of the metadata currently present in
the VM MMDS. If you'd like to add or update a single key, see
Firecracker.metadata/3.
Note this change is data-only. Changes are only applied after calling
Firecracker.start/1 or Firecracker.apply/1.
Configures the given metadata key to have the given value.
If key exists, the data is overwritten. If it does not, the key
is created.
Metadata is stored in the MicroVMs Metadata store and can be retrieved when the VM is running.
Note this change is data-only. Changes are only applied after calling
Firecracker.start/1 or Firecracker.apply/1.
Configures or updates the given metadata key with a default
value or function.
If key exists, the data is updated using fun, if it does not
it is created with value.
Metadata is stored in the MicroVMs Metadata store and can be retrieved when the VM is running.
Note this change is data-only. Changes are only applied after calling
Firecracker.start/1 or Firecracker.apply/1.
Sets the given Firecracker option key with value.
Options are applied at VM create time. Options that can be configured here map directly to CLI arguments that can be passed to the Firecracker binary.
In addition to the CLI arguments, you may also configure the path to the
Firecracker binary via the :firecracker_path argument.
Note that these options may only be applied before the VM has been created. Changes after creation are prohibited.
Options
* `:api_sock` - Path of the unix socket to use for the VM API. Defaults
to `"/tmp/firecracker.#{System.unique_integer([:positive])}.sock"`.
* `:boot_timer` - Whether or not to load boot timer device for logging elapsed
time since InstanceStart command.
* `:config_file` - Path to a file that contains the microVM configuration in JSON
format. Note that setting this option will override any configurations you set.
This is not recommended.
* `:http_api_max_payload_size` - Http API request payload max size, in bytes.
Defaults to 51200.
* `:id` - MicroVM unique identifier. Defaults to `"anonymous-instance"`.
* `:level` - Firecracker log level.
* `:log_path` - Path to a fifo or file used for configuring the logger on startup.
* `:metrics_path` - Path to a fifo or a file used for configuring the metrics
on startup.
* `:mmds_size_limit` - Mmds data store limit, in bytes.
* `:module` - Set the logger module filter.
* `:no_api` - Optional parameter which allows starting and using a microVM
without an active API socket.
* `:no_seccomp` - Optional parameter which allows starting and using a microVM
without seccomp filtering. Not recommended.
* `:parent_cpu_time_us` - Parent process CPU time (wall clock, microseconds).
This parameter is optional.
* `:seccomp_filter` - Optional parameter which allows specifying the path to a custom
seccomp filter. For advanced users.
* `:show_level` - Whether or not to output the level in the logs.
* `:show_log_origin` - Whether or not to include the file path and line number of
the log's origin.
* `:start_time_cpu_us` - Process start CPU time (wall clock, microseconds).
This parameter is optional.
* `:start_time_us` - Process start time (wall clock, microseconds). This parameter
is optional.
Sets the given Firecracker options.
Options are applied at VM create time. Options that can be configured here map directly to CLI arguments that can be passed to the Firecracker binary.
In addition to the CLI arguments, you may also configure the path to the
Firecracker binary via the :firecracker_path argument.
Note that these options may only be applied before the VM has been created. Changes after creation are prohibited.
Each option may take a function in-place of a value. The value will be computed at VM creation time.
Options
:api_sock- Path of the unix socket to use for the VM API. Defaults to"/tmp/firecracker.#{System.unique_integer([:positive])}.sock".:boot_timer- Whether or not to load boot timer device for logging elapsed time since InstanceStart command.:config_file- Path to a file that contains the microVM configuration in JSON format. Note that setting this option will override any configurations you set. This is not recommended.:http_api_max_payload_size- HTTP API request payload max size, in bytes. Defaults to 51200.:id- MicroVM unique identifier. Defaults to"anonymous-instance".:level- Firecracker log level.:log_path- Path to a fifo or file used for configuring the logger on startup.:metrics_path- Path to a fifo or a file used for configuring the metrics on startup.:mmds_size_limit- Mmds data store limit, in bytes.:module- Set the logger module filter.:no_api- Optional parameter which allows starting and using a microVM without an active API socket.:no_seccomp- Optional parameter which allows starting and using a microVM without seccomp filtering. Not recommended.:parent_cpu_time_us- Parent process CPU time (wall clock, microseconds). This parameter is optional.:seccomp_filter- Optional parameter which allows specifying the path to a custom seccomp filter. For advanced users.:show_level- Whether or not to output the level in the logs.:show_log_origin- Whether or not to include the file path and line number of the log's origin.:start_time_cpu_us- Process start CPU time (wall clock, microseconds). This parameter is optional.:start_time_us- Process start time (wall clock, microseconds). This parameter is optional.
Configures tracing for the VM's API requests.
This function instruments the Req struct, enabling request/response tracing for all API calls made to the Firecracker API.
The currently supported tracers are :log and :file. Custom function
support is planned.
Lifecycle
Boots a Firecracker VM.
This method invokes the InstanceStart action on a created VM which
kicks off the boot process. The VM must already be in a :started
state.
Attempting to start an already running VM is a no-op.
Pauses a Firecracker VM.
Attempting to pause an already paused VM is a no-op.
Resumes a paused Firecracker VM.
Attempting to resume an already running VM is a no-op.
Shutsdown a Firecracker VM.
Attempting to shutdown an already shutdown VM is a no-op.
Starts a new Firecracker VM with the given configuration.
The Firecracker process will be attached to the :process key with
the information about the running PID. This library does not do any
automatic cleanup. Failure to stop the running VM will result in
Zombie processes.
Note starting the VM is not equivalent to booting the VM. See Firecracker.boot/1
for details on booting.
Stops a Firecracker VM.
Stopping the VM sends SIGTERM to the running Firecracker process. You
will not be able to resume from this state.
Attempting to stop an already exited VM is a no-op.
Snapshots
@spec load(t(), Firecracker.Snapshot.t()) :: t()
Loads a Firecracker VM from a snapshot.
The VM must be in a started state, but not yet booted. The
snapshot must be a valid %Firecracker.Snapshot{} struct.
See Firecracker.Snapshot for information on configuring snapshots.
@spec snapshot( t(), keyword() ) :: Firecracker.Snapshot.t()
Creates a snapshot of the Firecracker VM.
The VM must be in a :paused state before creating the snapshot.
Returns a %Firecracker.Snapshot{}
Options
* `:mem_file_path` - Path to the file that will contain the guest memory.
This is a required argument.
* `:path` - Path to the file that will contain the microVM state.
This is a required argument.
* `:type` - Type of snapshot to create. Can be either `:full` or
`:diff`. Defaults to `:full`
Inspection
Describes information about the given Firecracker instance.
The instance must be in :started, :running, or :paused state
for this invocation to work.
@spec describe(t(), describable()) :: map()
Describes information about the given Firecracker instance configuration key.
The instance must be in :started, :running, or :paused state
for this invocation to work.
Valid keys to describe are:
:balloon- returns information about the balloon device configuration:balloon_statistics- returns information about balloon device statistics:machine_config- returns information about the machine configuration:mmds- returns information about the mmds data content:vm_config- returns information about the full vm configuration
Describes the changes that will be applied on start or application.
Dry-run will return a map with the following keys:
Jailer
Configures the given VM to run with the given cgroup value.
The VM must be in an :initial state with a jailer configured.
Configures the given VM to run in the context of the Firecracker Jailer.
The VM must be in an :initial state.
You must configure the uid and gid options. See Firecracker.cgroup/3
and Firecracker.resource_limit/3 for configuring cgroups and resource
limits on the jailer.
Options
:uid- uid the jailer switches to in order to exec target binary:gid- gid the jailer switches to in order to exec target binary:parent_cgroup- allows the placement of microvm cgroups in custom nested hierarchies:cgroup_version- selects the type of cgroup hierarchy to use for creation of cgroups:chroot_base_dir- the base folder where chroot jails are built. Defaults to/srv/jailer:netns- path to a network namespace handle for the jailer to use to join the associated network namespace.
Configures the given VM to run with the given resource limits.
The VM must be in an :initial state with a jailer configured.
Valid resources are:
"fsize"- maximum size in bytes for files created by the process"no-file"- value one greater than the maximum file descriptor number that can be opened by this process.
Helpers
@spec snapshot_version() :: String.t()
Returns the Firecracker snapshot version using the environment Firecracker binary, or the default binary.
Returns the Firecracker snapshot version for the VM.
If the :firecracker_path is not set for the VM, this will use
the environment path, or the default path.
@spec version() :: String.t()
Returns the Firecracker version using the environment Firecracker binary, or the default binary.
Returns the Firecracker version for the VM.
If the :firecracker_path is not set for the VM, this will use
the environment path, or the default path.
@spec which() :: String.t()
Returns the default Firecracker binary as given by the environment or default value.
Return the Firecracker binary for the given VM.
Types
@type addable() :: :drive | :network_interface | :pmem
@type configurable() ::
:balloon
| :boot_source
| :cpu_config
| :entropy
| :logger
| :machine_config
| :metrics
| :mmds_config
| :serial
| :vsock
@type describable() ::
:balloon | :balloon_statistics | :machine_config | :mmds | :vm_config
@type t() :: %Firecracker{ api_sock: String.t() | nil, balloon: Firecracker.Balloon.t() | nil, boot_source: Firecracker.BootSource.t() | nil, config_file: term(), cpu_config: Firecracker.CpuConfig.t() | nil, drives: %{required(String.t()) => Firecracker.Drive.t()}, entropy: Firecracker.Entropy.t() | nil, errors: term(), firecracker_path: String.t() | nil, id: String.t() | nil, jailer: Firecracker.Jailer.t() | nil, logger: Firecracker.Logger.t() | nil, machine_config: Firecracker.MachineConfig.t() | nil, metrics: Firecracker.Metrics.t() | nil, mmds: Firecracker.Mmds.t() | nil, mmds_config: Firecracker.MmdsConfig.t() | nil, network_interfaces: %{ required(String.t()) => Firecracker.NetworkInterface.t() }, no_api: term(), options: map(), pmems: %{required(String.t()) => Firecracker.Pmem.t()}, process: term() | nil, req: Req.Request.t() | nil, serial: Firecracker.Serial.t() | nil, state: vm_state(), tracing: term(), vsock: Firecracker.Vsock.t() | nil }
@type vm_state() :: :initial | :started | :running | :paused | :shutdown | :exited