krunvm

repository·main·Indexed 23 days ago

https://github.com/libkrun/krunvm

A CLI utility for creating microVMs from OCI images using libkrun and buildah. It provides a lightweight virtualization experience with fast boot times and minimal footprint, eliminating disk image maintenance and complex network configurations. Supported platforms include Linux/KVM (x86_64, AArch64) and macOS/Hypervisor.framework (ARM64), with support for x86_64 emulation on macOS via Rosetta.

Tokens
2.4K
Snippets
5
Records
20
Agent score
82%

What's inside krunvm

  1. Overview of krunvm

    main

    krunvm is a CLI-based utility designed to create microVMs directly from OCI images. It leverages libkrun and buildah to provide a lightweight virtualization experience.

    Key Features

    • Minimal footprint: Optimized for low resource usage.
    • Fast boot time: Rapidly initializes microVMs.
    • Zero disk image maintenance: Uses OCI images directly.
    • Zero network configuration: Simplifies networking setup.
    • Volume Mapping: Supports mapping host volumes into the guest.
    • Port Forwarding: Supports exposing guest ports to the host.

    Supported Platforms

    • Linux/KVM on x86_64.
    • Linux/KVM on AArch64.
    • macOS/Hypervisor.framework on ARM64.
  2. Install krunvm on Fedora

    main

    To install krunvm on Fedora, enable the necessary Copr repositories for libkrunfw, libkrun, and krunvm, then install the package using dnf.

    dnf copr enable -y slp/libkrunfw
    dnf copr enable -y slp/libkrun
    dnf copr enable -y slp/krunvm
    dnf install -y krunvm
  3. Linux Setup: Buildah unshare requirement

    main
    On Linux, krunvm requires specific user namespace privileges. If you are not running as root, you must execute krunvm within a buildah unshare session to ensure the necessary environment is available.
  4. macOS Setup: Case-sensitive volume requirement

    main

    On macOS, krunvm requires a dedicated, case-sensitive APFS volume for storage. If a valid volume is not configured, the CLI will prompt you to provide a mountpoint and will perform a case-sensitivity test.

    You can create a suitable volume using diskutil in a separate terminal:

    diskutil apfs addVolume disk3 "Case-sensitive APFS" krunvm

    When prompted by krunvm, you can enter the mountpoint (defaulting to /Volumes/krunvm) or provide a custom path.

  5. Configure x86_64 emulation on macOS via Rosetta

    main

    On macOS (Aarch64), you can run x86_64 microVMs using the --x86 flag. This requires setting up a Rosetta support file for Linux.

    1. Create a file named .krunvm-rosetta in your $HOME directory.
    2. Populate it with the contents that the rosetta binary expects to be served from its specific ioctl.

    Limitations:

    • x86 microVMs on Aarch64 are restricted to exactly 1 CPU.
  6. VmConfig structure

    main

    The VmConfig struct defines the specific configuration for an individual virtual machine.

    #[derive(Default, Debug, Serialize, Deserialize)]
    pub struct VmConfig {
        name: String,
        cpus: u32,
        mem: u32,
        container: String,
        workdir: String,
        dns: String,
        mapped_volumes: HashMap<String, String>,
        mapped_ports: HashMap<String, String>,
    }
  7. KrunvmConfig structure

    main

    The KrunvmConfig struct defines the global configuration for the krunvm application. It is persisted using confy under the name krunvm.

    Fields:

    • version: Configuration version (defaults to 1).
    • default_cpus: Default number of CPUs for new VMs (defaults to 2).
    • default_mem: Default memory in MB for new VMs (defaults to 1024).
    • default_dns: Default DNS server (defaults to 1.1.1.1).
    • storage_volume: The mountpoint for the dedicated storage volume.
    • vmconfig_map: A map of VM names to their specific VmConfig settings.
    #[derive(Debug, Serialize, Deserialize)]
    pub struct KrunvmConfig {
        version: u8,
        default_cpus: u32,
        default_mem: u32,
        default_dns: String,
        storage_volume: String,
        vmconfig_map: HashMap<String, VmConfig>,
    }
  8. Reference: `create` command flags

    main

    The following flags are available when using the create command to configure the microVM:

    FlagArgumentDescription
    image<string>The OCI image to use as a template (positional argument).
    --name<string>Assign a specific name to the VM.
    --cpus<u32>Number of vCPUs to allocate.
    --mem<u32>Amount of RAM in MiB to allocate.
    --dns<string>DNS server to use inside the microVM.
    --workdir<string>Working directory inside the microVM (default: empty).
    --volume<host_path:guest_path>Volume(s) to expose to the guest. Can be used multiple times.
    --port<host_port:guest_port>Port(s) to expose to the host. Can be used multiple times.
    --x86(boolean)macOS only: Create an x86_64 microVM even on an Aarch64 host. Restricts CPU count to 1.