A boot image is a bootable disk image containing an operating-system kernel and its bootloader. An ordinary executable is not enough when the operating system it targets does not yet exist. The Rust bootimage crate builds the image so the kernel can be started in a virtual machine or booted on hardware. section 11.1.1 section 11.1.2
For a new kernel target, the build has several jobs:
- Define the target machine’s conventions, including its CPU architecture. section 11.2.1
- Compile Rust’s core library and the kernel for that target. section 11.2.1
- Build a bootloader that loads the kernel, then start it in a virtual environment. bootimage automates these steps. section 11.2.1
Listing 11.1 Project metadata for fledgeos-0
[package]
name = "fledgeos"
version = "0.1.0"
authors = ["Tim McNamara <author@rustinaction.com>"]
edition = "2018"
[dependencies]
bootloader = "0.9"
x86_64 = "0.13"
[package.metadata.bootimage]
build-command = ["build"]
run-command = [ #1
"qemu-system-x86_64", "-drive", "format=raw,file={}"
]
Cargo.toml supplies bootimage instructions: build-command selects cargo build, while run-command starts QEMU with the generated image instead of running the kernel executable directly. section 11.2.3
Listing 11.3 Extra build-time configuration for cargo
[build] target = "fledge.json" [unstable] build-std = ["core", "compiler_builtins"] build-std-features = ["compiler-builtins-mem"] [target.'cfg(target_os = "none")'] runner = "bootimage runner"
The Cargo configuration selects a custom target, requests a build of core and compiler_builtins, and sets bootimage runner for the target without an operating system. section 11.2.3
First boot in QEMU
Run cargo +nightly run in the configured kernel project. The shown run starts qemu-system-x86_64 with a generated bootimage-fledgeos.bin disk image. section 11.2.1
