#disk-image #kernel #bootable #bootloader #osdev #binary

bin+lib bootimage

Tool to create a bootable OS image from a kernel binary

60 releases

0.10.3 Apr 1, 2021
0.10.2 Dec 10, 2020
0.10.1 Aug 3, 2020
0.9.0 Jul 17, 2020
0.2.1 Mar 31, 2018

#495 in Operating systems

Download history 561/week @ 2023-11-18 586/week @ 2023-11-25 630/week @ 2023-12-02 598/week @ 2023-12-09 647/week @ 2023-12-16 614/week @ 2023-12-23 647/week @ 2023-12-30 653/week @ 2024-01-06 699/week @ 2024-01-13 626/week @ 2024-01-20 597/week @ 2024-01-27 596/week @ 2024-02-03 689/week @ 2024-02-10 540/week @ 2024-02-17 756/week @ 2024-02-24 542/week @ 2024-03-02

2,623 downloads per month

MIT/Apache

52KB
1K SLoC

bootimage

Creates a bootable disk image from a Rust OS kernel.

Installation

> cargo install bootimage

Usage

First you need to add a dependency on the bootloader crate:

# in your Cargo.toml

[dependencies]
bootloader = "0.6.4"

Note: At least bootloader version 0.5.1 is required since bootimage 0.7.0. For earlier bootloader versions, use bootimage 0.6.6.

If you want to use a custom bootloader with a different name, you can use Cargo's rename functionality.

Building

Now you can build the kernel project and create a bootable disk image from it by running:

cargo bootimage --target your_custom_target.json [other_args]

The command will invoke cargo build, forwarding all passed options. Then it will build the specified bootloader together with the kernel to create a bootable disk image.

Running

To run your kernel in QEMU, you can set a bootimage runner as a custom runner in a .cargo/config file:

[target.'cfg(target_os = "none")']
runner = "bootimage runner"

Then you can run your kernel through:

cargo xrun --target your_custom_target.json [other_args] -- [qemu args]

All arguments after -- are passed to QEMU. If you want to use a custom run command, see the Configuration section below.

Testing

The bootimage has built-in support for running unit and integration tests of your kernel. For this, you need to use the custom_tests_framework feature of Rust as described here.

Configuration

Configuration is done through a through a [package.metadata.bootimage] table in the Cargo.toml of your kernel. The following options are available:

[package.metadata.bootimage]
# The cargo subcommand that will be used for building the kernel.
#
# For building using the `cargo-xbuild` crate, set this to `xbuild`.
build-command = ["build"]
# The command invoked with the created bootimage (the "{}" will be replaced
# with the path to the bootable disk image)
# Applies to `bootimage run` and `bootimage runner`
run-command = ["qemu-system-x86_64", "-drive", "format=raw,file={}"]

# Additional arguments passed to the run command for non-test executables
# Applies to `bootimage run` and `bootimage runner`
run-args = []

# Additional arguments passed to the run command for test executables
# Applies to `bootimage runner`
test-args = []

# An exit code that should be considered as success for test executables
test-success-exit-code = {integer}

# The timeout for running a test through `bootimage test` or `bootimage runner` (in seconds)
test-timeout = 300

# Whether the `-no-reboot` flag should be passed to test executables
test-no-reboot = true

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.3–2.2MB
~47K SLoC