#!/bin/bash # Builds the k-os disk: one ext4 filesystem holding every program init may # start, in /bin, and the apps (docs/apps.md). Init and storage themselves are packed into the kernel image. set -euo pipefail IMG="${IMG:-boot.img}" SIZE="${SIZE:-16M}" TARGET="riscv64gc-unknown-none-elf" BUILD_DIR="target/${TARGET}/release" # What the storage server's ext4 driver does not maintain, switched off so it # can write to the disk (see storage-server's tests/ext4_real.rs). FEATURES="^has_journal,^metadata_csum,^64bit,^dir_index,^huge_file,^orphan_file,^metadata_csum_seed" ROOT="$(mktemp -d)" trap 'rm -rf "${ROOT}"' EXIT copy() { local src="$1" dst="$2" if [ -f "${BUILD_DIR}/${src}" ]; then cp "${BUILD_DIR}/${src}" "${ROOT}/bin/${dst}" fi } # An app, installed and pre-approved by whoever builds the image, or (staged) # a folder the owner may install. See docs/apps.md. APP_IMAGE=(cargo run -q --release -p app-image --) app() { local crate="$1" if [ -f "${BUILD_DIR}/${crate}" ]; then "${APP_IMAGE[@]}" install "${ROOT}" "crates/apps/${crate}/manifest.toml" "${BUILD_DIR}/${crate}" fi } staged() { local crate="$1" folder="$2" if [ -f "${BUILD_DIR}/${crate}" ]; then "${APP_IMAGE[@]}" stage "${ROOT}/factory/home/${folder}" "crates/apps/${crate}/manifest.toml" "${BUILD_DIR}/${crate}" fi } # Each user's folder in users/ is encrypted, so not filled here: init seeds # a new user's areas from factory/ (plaintext) once they are signed in. mkdir -p "${ROOT}/bin" "${ROOT}/apps" "${ROOT}/users" "${ROOT}/factory/home" "${ROOT}/factory/permissions" "${ROOT}/factory/data" "${ROOT}/factory/apps" # System servers and the shell: init starts these. copy display-qemu display copy input-qemu input copy log-server log copy permission-manager permission copy session-server session copy terminal-server terminal copy shell shell copy gatekeeper gatekeeper # Apps. app cat app ls app sleep app snake app tally app settings staged counter inbox/counter # A user's first files. cp -r disk/home/. "${ROOT}/factory/home/" # Only the test image: its presence makes init run the self-test. if [ -n "${SMPTEST:-}" ]; then copy smptest smptest copy spawntest spawntest copy hello hello copy flaky flaky fi rm -f "${IMG}" mkfs.ext4 -q -F -b 4096 -L k-os -O "${FEATURES}" -d "${ROOT}" "${IMG}" "${SIZE}" echo "=== ${IMG}: ext4, ${SIZE} ===" find "${ROOT}" -mindepth 1 | sed "s|${ROOT}/||" | sort