23 releases
0.11.2 | May 9, 2023 |
---|---|
0.11.1 | Sep 22, 2022 |
0.11.0 | Aug 27, 2022 |
0.10.2 | Jun 6, 2022 |
#468 in Configuration
Used in systemd-boot-friend-rs
26KB
411 lines
libsdbootconf
A systemd-boot configuration and boot entry configuration parser library.
Usage
use libsdbootconf::{config::ConfigBuilder, entry::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();
systemd_boot_conf.write_all().unwrap();
lib.rs
:
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();
Dependencies
~250–710KB
~17K SLoC