krata/DEV.md
Alex Zenla d46aa878af
feat(build): fetch kernels from image registry instead of building the kernel (#156)
Now that we have the kernel build infrastructure at https://github.com/edera-dev/kernels
it makes sense to drop building the kernel and download the kernel images directly.

This change introduces a ./hack/kernel/fetch.sh script which is backed by crates/build
We utilize the OCI infrastructure itself to download the kernel image. The DEV guide
has been updated to include calling the fetch script, and the OS builder now uses this
method instead. Due to the lack of need for the kernel build infra to exist here now,
it has also been removed. This should significantly speed up full builds.

This change will also enable us to turn on os build workflows for all PRs. We should
likely make the OS status checks required once this is merged.
2024-05-16 08:40:58 +00:00

3.7 KiB

Development Guide

Structure

krata is composed of four major executables:

Executable Runs On User Interaction Dev Runner Code Path
kratad host backend daemon ./hack/debug/kratad.sh crates/daemon
kratanet host backend daemon ./hack/debug/kratanet.sh crates/network
kratactl host CLI tool ./hack/debug/kratactl.sh crates/ctl
krataguest guest none, guest init N/A crates/guest

You will find the code to each executable available in the bin/ and src/ directories inside it's corresponding code path from the above table.

Environment

Component Specification Notes
Architecture x86_64 aarch64 support is still in development
Memory At least 6GB dom0 will need to be configured with lower memory limit to give krata guests room
Xen 4.17 Temporary due to hardcoded interface version constants
Debian stable / sid Debian is recommended due to the ease of Xen setup
rustup any Install Rustup from https://rustup.rs

Setup Guide

  1. Install the specified Debian version on a x86_64 host capable of KVM (NOTE: KVM is not used, Xen is a type-1 hypervisor).

  2. Install required packages:

$ apt install git xen-system-amd64 build-essential \
      libclang-dev musl-tools flex bison libelf-dev libssl-dev bc \
      protobuf-compiler libprotobuf-dev squashfs-tools erofs-utils
  1. Install rustup for managing a Rust environment.

Make sure to install the targets that you need for krata:

$ rustup target add x86_64-unknown-linux-gnu
$ rustup target add x86_64-unknown-linux-musl
  1. Configure /etc/default/grub.d/xen.cfg to give krata guests some room:
# Configure dom0_mem to be 4GB, but leave the rest of the RAM for krata guests.
GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=4G,max:4G"

After changing the grub config, update grub: update-grub

Then reboot to boot the system as a Xen dom0.

You can validate that Xen is setup by running dmesg | grep "Hypervisor detected" and ensuring it returns a line like Hypervisor detected: Xen PV, if that is missing, the host is not running under Xen.

  1. Clone the krata source code:
$ git clone https://github.com/edera-dev/krata.git krata
$ cd krata
  1. Fetch the guest kernel image:
$ ./hack/kernel/fetch.sh -u
  1. Copy the guest kernel artifacts to /var/lib/krata/guest/kernel so it is automatically detected by kratad:
$ mkdir -p /var/lib/krata/guest
$ cp target/kernel/kernel-x86_64 /var/lib/krata/guest/kernel
$ cp target/kernel/addons-x86_64.squashfs /var/lib/krata/guest/addons.squashfs
  1. Launch ./hack/debug/kratad.sh and keep it running in the foreground.
  2. Launch ./hack/debug/kratanet.sh and keep it running in the foreground.
  3. Run kratactl to launch a guest:
$ ./hack/debug/kratactl.sh launch --attach alpine:latest

To detach from the guest console, use Ctrl + ] on your keyboard.

To list the running guests, run:

$ ./hack/debug/kratactl.sh list

To destroy a running guest, copy it's UUID from either the launch command or the guest list and run:

$ ./hack/debug/kratactl.sh destroy GUEST_UUID