Files
k-os/scripts/make-disk-image.sh

69 lines
2.2 KiB
Bash
Executable File

#!/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}/home/${folder}" "crates/apps/${crate}/manifest.toml" "${BUILD_DIR}/${crate}"
fi
}
mkdir -p "${ROOT}/bin" "${ROOT}/apps" "${ROOT}/data" "${ROOT}/system/permissions" "${ROOT}/home"
# 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
staged counter inbox/counter
# The owner's files.
cp -r disk/home/. "${ROOT}/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
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