1 个不稳定版本
0.1.0 | 2020年6月30日 |
---|
#329 在 日期和时间
210 星标 & 21 关注者
2KB
56 行
distinst
Distinst 是一个基于 Rust 的软件库,用于处理 Linux 发行版安装器的安装细节。它专门为构建 Linux 发行版安装器而构建,以便安装器可以花更多的时间改进他们的 UI,而不用过多担心一些更复杂的实现细节,例如分区管理和加密。
前端
目前,elementary 的安装器是 distinst 的主要目标。然而,distinst 还附带了一个 CLI 应用程序(也称为 distinst),它作为 distinst 库的完整功能测试床。在 tests 目录中存在示例脚本,以演示如何使用 CLI 通过 Pop! ISO 中的文件执行安装。
CLI
- distinst (Rust)
GTK
- elementary 安装器 (Vala)
功能
磁盘分区与格式化
Distinst 提供了 Rust、C 和 Vala API 用于探测磁盘和分区信息,以及创建和操作分区的功能。除了通过 libparted 绑定进行磁盘分区外,distinst 还将处理磁盘分区,前提是你已经安装了每个要支持文件系统类型的相应软件包。LUKS & LVM 配置也得到支持,可以在配置物理分区后进行配置。
库的实现者应注意的是,distinst使用内存分区管理逻辑来确定所指定的更改是否有效。指定的更改将由distinst在install
方法中应用,这是您传递磁盘配置的地方。在做出任何更改之前,distinst将对该配置进行验证。
Rust 示例
请参阅distinst CLI应用程序的源代码。
Vala 示例
if (disk.mklabel (bootloader) != 0) {
stderr.printf ("unable to write GPT partition table to /dev/sda");
exit (1);
}
var efi_sector = Sector() {
flag = SectorKind.MEGABYTE,
value = 512
};
var start = disk.get_sector (Sector.start());
var end = disk.get_sector (efi_sector);
int result = disk.add_partition(
new PartitionBuilder (start, end, FileSystem.FAT32)
.set_partition_type (PartitionType.PRIMARY)
.add_flag (PartitionFlag.ESP)
.set_mount ("/boot/efi")
);
if (result != 0) {
stderr.printf ("unable to add EFI partition to disk");
exit (1);
}
start = disk.get_sector (efi_sector);
end = disk.get_sector (Sector.end ());
result = disk.add_partition (
new PartitionBuilder (start, end, FileSystem.EXT4)
.set_partition_type (PartitionType.PRIMARY)
.set_mount ("/")
);
if (result != 0) {
stderr.printf ("unable to add / partition to disk");
exit (1);
}
Disks disks = Disks.with_capacity (1);
disks.push (disk);
installer.install (disks, config);
提取、Chrooting 和配置
库的实现者应提供一个squashfs文件,其中包含安装程序在安装过程中将提取的基本镜像,以及相应的.manifest-remove
文件。例如,这些可以在Pop!_OS ISO中找到。一旦提取了此镜像,安装程序将chroot到新的安装中,然后使用位于src/configure.sh
的配置脚本配置镜像。
引导加载程序
根据镜像是在支持EFI的系统上运行还是不支持,将使用systemd-boot或GRUB配置引导加载程序,从而使用户能够在系统重新启动后从安装中引导。
构建说明
为了在Pop!上构建distinst
,您需要遵循以下说明
# Install dependencies
sudo apt build-dep distinst
# Build in debug mode
# make all DEBUG=1
# Build in release mode
make
# Install in release mode
sudo make install prefix=/usr
# Install in debug mode
# sudo make install prefix=/usr DEBUG=1
# Uninstall
sudo make uninstall
以下文件将被生成
- CLI应用程序:
target/release/distinst
- 库:
target/release/libdistinst.so
- 头文件:
target/include/distinst.h
- pkg-config:
target/pkg-config/distinst.pc
这些文件在安装时将放置在/usr/local,并且可以使用pkg-config --cflags distinst
或pkg-config --libs distinst
来找到它们。
为了生成源代码包,您必须运行以下命令
# Install cargo-vendor
cargo install cargo-vendor
# Download vendored sources
make vendor