#hardware #linux #hardware-support #support

pop-os/distinst-hardware-support

Linux 硬件检测和软件包推荐

1 个不稳定版本

0.1.0 2020年6月30日

#479 in Unix APIs

210 stars & 21 watchers

MIT 许可证

8KB
198 代码行,不包括注释

distinst

Distinst 是一个基于 Rust 的软件库,用于处理 Linux 发行版安装器的安装细节。它专门构建用于 Linux 发行版安装器的构建,以便安装器可以花费更多时间改进其用户界面,而不是担心一些更复杂的实现细节,例如分区管理 & 加密。

前端

目前,elementary 的安装器是 distinst 的主要目标。然而,distinst 还附带了一个 CLI 应用程序(也称为 distinst),作为 distinst 库的完全功能测试平台。在 测试 目录中存在示例脚本,演示如何使用 CLI 通过 Pop! ISO 文件执行安装。

命令行界面

GTK

功能

磁盘分区与格式化

Distinst 提供了 Rust、C 和 Vala API,用于探测磁盘和分区信息,以及创建和操作分区的功能。除了通过 libparted 绑定进行磁盘分区外,distinst 还会使用 mkfs 来处理磁盘分区,前提是你已经安装了支持你安装器中所需文件系统类型的相应软件包。也支持 LUKS & LVM 配置,并且可以在配置物理分区后进行配置。

库的实现者应注意,distinst使用内存分区管理逻辑来确定指定的更改是否有效。指定的更改将在install方法中由distinst应用,这是您将传递您的磁盘配置的地方。在做出任何更改之前,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 ISOs中找到,例如。一旦提取了此映像,安装程序将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 distinstpkg-config --libs distinst来找到它们。

为了生成源代码包,您必须运行以下命令

# Install cargo-vendor
cargo install cargo-vendor

# Download vendored sources
make vendor

依赖项

~6MB
~127K SLoC