Crate libsdbootconf

source ·
Expand description

This library provides a configuration interface for systemd-boot. It parses systemd-boot loader configuration and systemd-boot entry configuration.

NOTE: Not all fields in https://www.freedesktop.org/software/systemd/man/systemd-boot.html are implemented, this library currently only provides interface for the fields listed on https://www.freedesktop.org/wiki/Software/systemd/systemd-boot/.

Create and write a new systemd-boot configuration

You can use the SystemdBootConfig struct to create a new systemd-boot configuration, or use SystemdBootConfigBuilder to build a SystemdBootConfig from scratch.

use libsdbootconf::{ConfigBuilder, EntryBuilder, SystemdBootConfBuilder};

let systemd_boot_conf = SystemdBootConfBuilder::new("/efi/loader")
    .config(ConfigBuilder::new()
        .default("5.12.0-aosc-main")
        .timeout(5u32)
        .build())
    .entry(EntryBuilder::new("5.12.0-aosc-main")
        .title("AOSC OS x86_64 (5.12.0-aosc-main)")
        .version("5.12.0-aosc-main")
        .build())
    .build();

// Or
use libsdbootconf::{Config, Entry, SystemdBootConf, Token};

let systemd_boot_conf = SystemdBootConf::new(
    "/efi/loader",
    Config::new(Some("5.12.0-aosc-main"), Some(5u32)),
    vec![Entry::new(
        "5.12.0-aosc-main",
        vec![
            Token::Title("AOSC OS x86_64 (5.12.0-aosc-main)".to_owned()),
            Token::Version("5.12.0-aosc-main".to_owned()),
        ],
    )]
);

systemd_boot_conf.write_all().unwrap();

Create a new systemd-boot menu entry

use libsdbootconf::entry::{Entry, EntryBuilder, Token};
use std::path::PathBuf;

let entry = EntryBuilder::new("5.12.0-aosc-main")
    .title("AOSC OS x86_64 (5.12.0-aosc-main)")
    .linux("/EFI/linux/vmlinux-5.12.0-aosc-main")
    .initrd("/EFI/linux/initramfs-5.12.0-aosc-main.img")
    .options("root=/dev/sda1 rw")
    .build();

// Or
let entry = Entry::new(
    "5.12.0-aosc-main",
    vec![
        Token::Title("AOSC OS x86_64 (5.12.0-aosc-main)".to_owned()),
        Token::Linux(PathBuf::from("/EFI/linux/vmlinux-5.12.0-aosc-main")),
        Token::Initrd(PathBuf::from("/EFI/linux/initramfs-5.12.0-aosc-main.img")),
        Token::Options("root=/dev/sda1 rw".to_owned()),
    ],
);

entry.write("/efi/loader/entries/5.12.0-aosc-main.conf").unwrap();

Re-exports

Modules

  • Configuration of the installed systemd-boot environment.
  • Configuration of a boot entry.

Structs

Enums