Building Motor OS
Motor OS is cross-compiled on Linux with the Motor toolchain. One script
builds the system, its external sources, and the VM images from a clean checkout; after that,
make rebuilds the system in minutes. The script is tested on Ubuntu 24.04 and
26.04.
What you need
- An x86-64 Linux host with KVM (
/dev/kvm), which the VM scripts use. Ubuntu 24.04 or 26.04 is what the build script provisions; on another distribution, install the packages listed below yourself and the script carries on. sudo, for installing packages and for the host side of VM networking, and network access, for the external sources and their dependencies.- The Motor toolchain that
rust-toolchain.tomlnames,x86_64-unknown-motor-1.99.1: its two archives, from the release of motor-os-toolchain or a build of that repository.
The packages the script installs are git, build-essential,
nasm, clang, cmake, ninja-build, meson,
zlib1g-dev, libssl-dev, pkg-config, curl,
qemu-system, and qemu-utils, plus rustup without a default
toolchain. Cloud Hypervisor and Firecracker are not installed; QEMU is enough to build
and test.
Build the toolchain first
The toolchain is built separately and does not need a Motor OS checkout. On Ubuntu 24.04 or 26.04, create the development root and clone the toolchain repository inside it:
sudo apt-get update
sudo apt-get install git zstd
mkdir motor-dev
cd motor-dev
git clone https://github.com/moturus/motor-os-toolchain.git
cd motor-os-toolchain
./build-toolchain.sh --provision
cd ..
--provision installs missing build packages with sudo
and installs rustup. The build fetches the sources selected by the toolchain
repository's versions.sh and builds both the Linux-host cross
toolchain and the native Motor OS toolchain. It writes these files into its
parent directory, motor-dev, where the commands above leave you:
motor-toolchain-x86_64-unknown-motor-1.99.1-x86_64-linux.tar.zst
motor-toolchain-x86_64-unknown-motor-1.99.1-x86_64-linux.tar.zst.sha256
motor-toolchain-x86_64-unknown-motor-1.99.1.tar.zst
motor-toolchain-x86_64-unknown-motor-1.99.1.tar.zst.sha256
Each toolchain build starts from scratch, replaces archives of the same name,
and removes its build/ directory after success. Allow about 30 GB of
disk space during the build; the toolchain README estimates about 50 minutes on
24 cores. See its
build instructions
for details. The resulting toolchain name must match rust-toolchain.toml
in the Motor OS checkout.
Alternatively, download both archives and their checksum files from a matching
toolchain release into motor-dev, then enter that directory. GNU tar
needs zstd on the host to extract the .tar.zst archive.
The one-script build
Install rustup before the host toolchain. If it is not installed yet:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |
sh -s -- -y --default-toolchain none
. "$HOME/.cargo/env"
If rustup was installed by --provision, load it into your current
shell with . "$HOME/.cargo/env"; otherwise ensure it is on
PATH. From motor-dev, verify both archives, install the
host toolchain, and build Motor OS:
sha256sum -c motor-toolchain-x86_64-unknown-motor-1.99.1-x86_64-linux.tar.zst.sha256
sha256sum -c motor-toolchain-x86_64-unknown-motor-1.99.1.tar.zst.sha256
git clone https://github.com/moturus/motor-os.git
tar -xaf motor-toolchain-x86_64-unknown-motor-1.99.1-x86_64-linux.tar.zst
motor-toolchain-x86_64-unknown-motor-1.99.1-x86_64-linux/install.sh
rm -rf motor-toolchain-x86_64-unknown-motor-1.99.1-x86_64-linux
cd motor-os
src/build-motor-os.sh
The archive's install.sh installs the Linux-host toolchain and links it into
rustup; the native archive, motor-toolchain-x86_64-unknown-motor-1.99.1.tar.zst,
stays next to the checkout. src/build-motor-os.sh is the single supported entry
point. In order, it:
- checks that the selected native archive is in place, then installs the missing
host packages and rustup, creates the
moto-tapinterface with the forwarding and masquerade rules that let VMs reach the Internet, and makes/dev/kvmaccessible. Each step is skipped when it has already been done;MOTOR_SKIP_HOST_NETWORK_SETUP=1skips the network part if you have configured it yourself; - exports the name from
rust-toolchain.tomlasRUSTUP_TOOLCHAIN, so external sources with their own selectors also use the installed Motor toolchain; - prepares the external sources and checks their lockfiles. Failures are collected
in
build/external-lockfiles.log; a stale lockfile must be updated in its owning repository, and the build does not repair it; - unpacks the native toolchain's files from its archive;
- builds the external sources with that toolchain: Lua, ripgrep, Helix, sed, tar and zstd, Javy and Wasmi, and Wasmtime. Lua is a release, the others follow one branch or revision of their fork; every run builds them all again, incrementally;
- builds the base, standard, developer, and wasm images into
vm_images/release/.
The developer-image target boots its new image once under QEMU to prepare the
staged Motor OS library workspace and compile dependencies for offline native tests.
It needs moto-tap configured and no other running VM; preparation takes about
10 seconds for a release image and 4 minutes for a debug image.
Next to the checkout, in the directory MOTORH names
(the parent of the checkout by default), it only reads the native archive. Everything it
fetches or builds stays in the checkout, in directories Git ignores:
| Directory | Contents |
|---|---|
external-sources/ | The external sources: ripgrep/,
helix/, sed/, motor-os-tar/, javy/,
wasmtime/, lua-<version>/, and the wasi-sdk that the Javy
test plugins need. |
build/assembly/ | The assembly:
images/ (the libc, LLVM, rustc, and rust-analyzer files of the native
toolchain and the external sources, which the imager places into the images) and
build/ (the external sources' build trees), plus tests/
(Javy and Wasmtime test inputs). |
build/obj/<profile>/ | Motor OS component build trees. |
vm_images/<profile>/ | VM images and host-side tools. |
If the native archive lives elsewhere, set its directory explicitly:
export MOTORH=/absolute/path/to/motor-dev
src/build-motor-os.sh
The build is incremental and safe to rerun: after a failure, run the same command
again. After installing a different or rebuilt toolchain, run make clean
first: it removes all build artifacts, including the assembly and images, while keeping
external-sources/. Follow the
toolchain update procedure for a
new version or a replacement -dev build.
The toolchain the repository uses
The checkout's rust-toolchain.toml names the toolchain, so ordinary commands
run from the checkout use it without a +nightly, +stable, or
+dev-* selector; do not add one. To see which one it is:
rustc -vV
cargo -Vv
Cargo reports 1.99.1-dev and the exact Cargo commit: the current toolchain
is built from the Rust 1.99.1 tag with the Motor patches rebased onto it.
The cross sysroot and the LLVM tools are found from rustc --print sysroot, and
the images' toolchain files in the assembly, build/assembly/images.
Building with make
With the toolchain in place, the Makefile in the repository root builds the system, the programs, and the images. Debug is the default profile:
make -j"$(nproc)" # base and standard images, debug, into vm_images/debug/
make -j"$(nproc)" images # the developer and wasm images as well
make -j"$(nproc)" BUILD=release # the same into vm_images/release/
make -j"$(nproc)" dev.img BUILD=release
make sys-io rush # individual components
src/tests/test-system-tty.sh # builds, runs, and removes its temporary test image
make clippy
make clean # removes build/, the assembly included, and vm_images/
Every component is a target named after its binary: kernel,
vdso, sys-io, sys-init, sys-tty,
strobe, dns-resolver, sysbox, rush,
russhd, red, rmux, kibim,
httpd, httpd-axum, lorry, curl,
gears, mdbg, systest, and so on; the image targets
are base.img, main.img, dev.img, wasm.img, and
system-tty.img and vsock-test.img. The two test image
targets require an absolute TEST_IMAGE_ROOT outside vm_images/;
their test scripts create temporary directories and remove them after use.
Stripped binaries go to build/bin/<profile>/,
and Cargo's target directories, with the unstripped binaries that addr2line
needs, to build/obj/<profile>/<component>/.
The imager (src/imager) assembles each image from a YAML description and
the permission policy; see Filesystem. The standard image
takes libc configuration, ripgrep, tar, and zstd from the assembly; the developer image
adds LLVM, Rust, and other developer tools. The wasm image takes its runtimes from the
assembly and omits the native development toolchain. The base image needs no assembly.
Running the tests
src/tests/full-test.sh # debug
src/tests/full-test.sh --release
src/tests/full-test-dev.sh --release
full-test.sh is the suite every change is expected to pass. It runs the
host-side tests of the build scripts, builds the standard image and the test programs,
runs the host cargo test suites (the imager, Motor FS, the networking stack,
rush, rmux, red, russhd, rnetbench, sys-init, and the runtime libraries) and the
System-console, TUI, and terminal-size tests, then boots the image under QEMU and drives
it over SSH: systest, mio-test, tokio-tests, crossterm-smoke, SFTP, and the rest. Test
execution is limited to fifteen minutes for a release run and twenty-five for debug
or developer-image runs; a single vCPU doubles those budgets. Build preparation runs
before that timer. full-test-dev.sh runs the repository suite against the
developer image, then compiles the source snapshots natively inside the VM, runs the
tests of the Motor OS libraries staged there, runs Lorry's own suite, and installs the
native toolchain archive on a separate copy of the developer image to build and run
C, C++, and Rust programs. The repository phase defaults to an 8 GiB VM and the
developer-source phase to 4 GiB.
The main suite also checks boot under Cloud Hypervisor and Firecracker when
cloud-hypervisor-static and firecracker are on PATH;
it reports skips when they are absent. full-test-networking.sh is the
networking subset with rnetbench throughput runs, and stress-soak.sh keeps one
VM under concurrent load for as long as you ask, watching for crashes and stalls.
On the developer image the same test programs are in /devtools/tests and can
be run from the shell; see Developer image.
Working on the compilers
The compilers are built by
motor-os-toolchain, whose
build-toolchain.sh builds the heads of the branches its versions.sh
names, local ones included, and packages them as the two archives. A local build is named
<version>-dev; install it and name it in rust-toolchain.toml
to build Motor OS with it.
Further reading
The repository describes the build in more depth:
docs/build.md
(the quick start),
docs/build-motor-os.md
(the external sources, build order, and outputs),
docs/build-llvm.md
and
docs/build-rustc.md
(the C/C++ and Rust components and their layout on the developer image), and
docs/toolchain.md
(how the toolchain is installed, selected, and changed). What the
toolchains contain and how programs are compiled with them is on the
Toolchains page.
Once you have images, Running Motor OS describes the VM scripts, and Hello Motor OS walks through running your own program.
Image construction and customization
The Make image targets invoke the host-side imager. Its reference covers image YAML, raw output, permission changes, resizing, and SSH/TLS credential replacement. Use those editing commands on a stopped VM's image; rebuilding the named image replaces its customizations.