add kernel build infra and introduce development guide to README

This commit is contained in:
Alex Zenla 2024-02-19 01:29:11 +00:00
parent 1985ab4081
commit 73f1e980cd
No known key found for this signature in database
GPG Key ID: 067B238899B51269
5 changed files with 5709 additions and 0 deletions

View File

@ -35,3 +35,67 @@ Currently no external contributions are accepted. hypha is in it's early days an
### What are the future plans?
Mycelium is trying to build a company to compete in the hypervisor space with fully open-source technology. More information to come soon on official channels.
## Development Guide
### Structure
hypha is composed of three major executables:
| Executable | Runs On | User Interaction | Dev Runner | Code Path |
| ---------- | ------- | ---------------- | --------------------------- | ----------- |
| hyphanet | host | backend daemon | ./scripts/hyphanet-debug.sh | network |
| hyphactl | host | CLI tool | ./scripts/hyphactl-debug.sh | controller |
| hyphactr | guest | none, guest init | N/A | container |
You will find the code to each executable available in the bin/ and src/ directories inside
it's coresponding code path from the above table.
### Environment
| Component | Specification | Notes |
| ------------- | ------------- | --------------------------------------------------------------------------------- |
| Architecture | x86_64 | aarch64 support requires minimal effort, but limited to x86 for research phase |
| Memory | At least 6GB | dom0 will need to be configured will lower memory limit to give hypha guests room |
| Xen | 4.17 | Temporary due to hardcoded interface version constants |
| Debian | sid / stable | Debian is recommended due to the ease of Xen setup |
| musl-gcc | any | hyphactr is built for musl to allow static linking, as initrd is a single file |
| rustup | any | Install Rustup from https://rustup.rs |
### Setup
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. Ensure you have installed Xen (apt install xen-system-amd64) and configure `/etc/default/grub.d/xen.cfg` to give hypha guests
some room:
```sh
# Configure dom0_mem to be 4GB, but leave the rest of the RAM for hypha guests.
GRUB_CMDLINE_XEN_DEFAULT="dom0_mem=4G,max:4G"
```
3. Build a guest kernel image:
```sh
$ ./kernel/build.sh -j4
```
4. Copy the guest kernel image to `/var/lib/hypha/default/kernel` to have it automatically detected by hyphactl.
5. Launch `./scripts/hyphanet-debug.sh` and keep it running in the foreground.
6. Run hyphactl to launch a container:
```sh
$ ./scripts/hyphactl-debug.sh launch --attach mirror.gcr.io/library/alpine:latest /bin/busybox sh
```
To detach from the container console, use `Ctrl + ]` on your keyboard.
To list the running containers, run:
```sh
$ ./scripts/hyphactl-debug.sh list
```
To destroy a running container, copy it's UUID from either the launch command or the container list and run:
```sh
$ ./scripts/hyphactl-debug.sh destroy CONTAINER_UUID
```

2
kernel/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
linux-*
target/

22
kernel/build.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/sh
set -e
cd "$(dirname "${0}")"
# shellcheck source=config.sh
. "${PWD}/config.sh"
if [ ! -f "${SRC_DIR_NAME}/Makefile" ]
then
rm -rf "${SRC_DIR_NAME}"
curl -L -o "${SRC_DIR_NAME}.txz" "${KERNEL_SRC_URL}"
tar xvf "${SRC_DIR_NAME}.txz"
rm "${SRC_DIR_NAME}.txz"
fi
mkdir -p "${OUTPUT_DIR_NAME}"
cp hypha.config "${SRC_DIR_NAME}/.config"
make -C "${SRC_DIR_NAME}" "${@}" olddefconfig
make -C "${SRC_DIR_NAME}" "${@}" bzImage
cp "${SRC_DIR_NAME}/arch/x86/boot/bzImage" "${OUTPUT_DIR_NAME}/kernel"

5
kernel/config.sh Normal file
View File

@ -0,0 +1,5 @@
#!/bin/sh
KERNEL_VERSION="6.7.5"
KERNEL_SRC_URL="https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-${KERNEL_VERSION}.tar.xz"
SRC_DIR_NAME="linux-${KERNEL_VERSION}"
OUTPUT_DIR_NAME="out"

5616
kernel/hypha.config Normal file

File diff suppressed because it is too large Load Diff