improve stratis initrd support

it is now possible to supply a stratis pool uuid
for every filesystem, and if that filesystem
is required for boot, the relevant pool will be
started in the initramfs.
This commit is contained in:
Matthias Berndt 2023-05-16 22:48:36 -04:00
parent 3aa262b644
commit 92814241a8
4 changed files with 37 additions and 39 deletions

View File

@ -476,7 +476,7 @@ In addition to numerous new and upgraded packages, this release has the followin
- `boot.initrd.luks.device.<name>` has a new `tryEmptyPassphrase` option, this is useful for OEM's who need to install an encrypted disk with a future settable passphrase
- there is a new `boot/stratisroot.nix` module that enables booting from a volume managed by the Stratis storage management daemon. Use `boot.stratis.rootPoolUuid` to configure the pool containing the root volume
- there is a new `boot/stratisroot.nix` module that enables booting from a volume managed by the Stratis storage management daemon. Use `fileSystems.<name>.stratis.poolUuid` to configure the pool containing the fs.
- Lisp gained a [manual section](https://nixos.org/manual/nixpkgs/stable/#lisp), documenting a new and backwards incompatible interface. The previous interface will be removed in a future release.

View File

@ -1,19 +1,11 @@
{ config, lib, pkgs, ... }:
{ config, lib, pkgs, utils, ... }:
let
types = lib.types;
requiredStratisFilesystems = lib.attrsets.filterAttrs (_: x: utils.fsNeededForBoot x && x.stratis.poolUuid != null) config.fileSystems;
in
{
options.boot.stratis = {
rootPoolUuid = lib.mkOption {
type = types.uniq (types.nullOr types.str);
description = lib.mdDoc ''
UUID of the stratis pool that the root fs is located in
'';
example = "04c68063-90a5-4235-b9dd-6180098a20d9";
default = null;
};
};
config = lib.mkIf (config.boot.stratis.rootPoolUuid != null) {
options = {};
config = lib.mkIf (builtins.length (lib.attrsets.attrValues requiredStratisFilesystems) != 0) {
assertions = [
{
assertion = config.boot.initrd.systemd.enable;
@ -36,25 +28,29 @@ in
thin_metadata_size = "${pkgs."thin-provisioning-tools"}/bin/thin_metadata_size";
stratis-min = "${pkgs.stratisd}/bin/stratis-min";
};
services = {
stratis-setup = {
description = "setup for Stratis root filesystem";
unitConfig.DefaultDependencies = "no";
conflicts = [ "shutdown.target" "initrd-switch-root.target" ];
onFailure = [ "emergency.target" ];
unitConfig.OnFailureJobMode = "isolate";
wants = [ "stratisd-min.service" "plymouth-start.service" ];
wantedBy = [ "initrd.target" ];
after = [ "paths.target" "plymouth-start.service" "stratisd-min.service" ];
before = [ "initrd.target" "shutdown.target" "initrd-switch-root.target" ];
environment.STRATIS_ROOTFS_UUID = config.boot.stratis.rootPoolUuid;
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.stratisd.initrd}/bin/stratis-rootfs-setup";
RemainAfterExit = "yes";
};
};
};
services =
lib.attrsets.mapAttrs' (
mountPoint: fileSystem: {
name = "stratis-setup-${fileSystem.stratis.poolUuid}";
value = {
description = "setup for Stratis root filesystem";
unitConfig.DefaultDependencies = "no";
conflicts = [ "shutdown.target" "initrd-switch-root.target" ];
onFailure = [ "emergency.target" ];
unitConfig.OnFailureJobMode = "isolate";
wants = [ "stratisd-min.service" "plymouth-start.service" ];
wantedBy = [ "initrd.target" ];
after = [ "paths.target" "plymouth-start.service" "stratisd-min.service" ];
before = [ "initrd.target" "shutdown.target" "initrd-switch-root.target" ];
environment.STRATIS_ROOTFS_UUID = fileSystem.stratis.poolUuid;
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.stratisd.initrd}/bin/stratis-rootfs-setup";
RemainAfterExit = "yes";
};
};
}
) requiredStratisFilesystems;
};
availableKernelModules = [ "dm-thin-pool" "dm-crypt" ] ++ [ "aes" "aes_generic" "blowfish" "twofish"
"serpent" "cbc" "xts" "lrw" "sha1" "sha256" "sha512"

View File

@ -36,6 +36,15 @@ let
description = lib.mdDoc "Location of the mounted file system.";
};
stratis.poolUuid = lib.mkOption {
type = types.uniq (types.nullOr types.str);
description = lib.mdDoc ''
UUID of the stratis pool that the fs is located in
'';
example = "04c68063-90a5-4235-b9dd-6180098a20d9";
default = null;
};
device = mkOption {
default = null;
example = "/dev/sda";

View File

@ -1038,12 +1038,6 @@ in {
"mkdir -p /mnt/boot",
"mount /dev/vda1 /mnt/boot"
)
(header, pool_line) = machine.succeed("stratis pool list").splitlines()
index = header.find("UUID")
uuid = pool_line[index - 32: index + 4]
machine.succeed("mkdir -p /mnt/etc/nixos")
machine.succeed(f"printf %s {uuid} > /mnt/etc/nixos/rootPoolUuid.txt")
'';
bootLoader = "systemd-boot";
extraInstallerConfig = { modulesPath, ...}: {
@ -1058,6 +1052,5 @@ in {
];
};
};
extraConfig = "boot.stratis.rootPoolUuid = builtins.readFile ./rootPoolUuid.txt;";
};
}