bootmgr-rs-core

Crates.iobootmgr-rs-core
lib.rsbootmgr-rs-core
version0.16.5
created_at2025-08-02 13:26:42.840153+00
updated_at2025-08-19 00:01:45.72878+00
descriptionA framework for easily creating boot managers in Rust
homepage
repositoryhttps://github.com/some100/bootmgr-rs
max_upload_size
id1778828
size260,332
someone (some100)

documentation

README

bootmgr-rs-core

NOTE: This crate has been renamed to bootmgr. Use that crate instead.

A framework for creating boot managers in Rust. Has support for Windows, BLS, and UKIs, with auto detection for the fallback bootloader, UEFI shell, and macOS.

Example

#![no_main]
#![no_std]

use bootmgr_rs_core::{
    boot::BootMgr,
    error::BootError,
    system::{helper::locate_protocol, log_backend::UefiLogger}
};
use uefi::{
    prelude::*,
    println,
    proto::console::text::{Input, Key, Output},
    system::with_stdout,
};

fn main_func() -> anyhow::Result<Handle> {
    uefi::helpers::init().map_err(BootError::Uefi)?;
    with_stdout(Output::clear)?; 
    let _ = log::set_logger(UefiLogger::static_new())
        .map(|()| log::set_max_level(log::LevelFilter::Warn));

    let mut boot_mgr = BootMgr::new()?;

    for (i, config) in boot_mgr.list().iter().enumerate() {
        println!("{i}: {}", config.get_preferred_title(Some(i))); // get all boot entries in system
    }
    println!("Enter the preferred boot option here:");

    let mut input = locate_protocol::<Input>()?;

    let mut events = [input.wait_for_key_event().expect("Failed to create key event")];
    loop {
        boot::wait_for_event(&mut events)?;

        if let Some(Key::Printable(key)) = input.read_key()? {
            let key = char::from(key);
            if let Some(key) = key.to_digit(10)
                && (key as usize) < boot_mgr.configs.len()
            { // test if input as number falls in range, and load that entry to get an image Handle
                return Ok(boot_mgr.load(key as usize)?);
            }
        }
    }
}

#[entry]
fn main() -> Status {
    let image = main_func().unwrap_or_else(|e| panic!("Error: {e}")); // get an image Handle or panic on error
    boot::start_image(image).status() // start the image
}

This example can also be found in bootmgr-rs-minimal.

Licensing

The code of this project is licensed under the MIT license. However, with the windows_bcd feature enabled, due to the nt-hive dependency, the library will be licensed under GPLv2 or later.

Commit count: 106

cargo fmt