2022-04-11 18:28:09 +00:00
|
|
|
{ kernelPackages ? null, flavour }: let
|
|
|
|
preparationCode = {
|
|
|
|
raid = ''
|
2022-10-15 22:18:03 +00:00
|
|
|
machine.succeed("vgcreate test_vg /dev/vdb /dev/vdc")
|
2022-04-11 18:28:09 +00:00
|
|
|
machine.succeed("lvcreate -L 512M --type raid0 test_vg -n test_lv")
|
|
|
|
'';
|
|
|
|
|
|
|
|
thinpool = ''
|
2022-10-15 22:18:03 +00:00
|
|
|
machine.succeed("vgcreate test_vg /dev/vdb")
|
2022-04-11 18:28:09 +00:00
|
|
|
machine.succeed("lvcreate -L 512M -T test_vg/test_thin_pool")
|
|
|
|
machine.succeed("lvcreate -n test_lv -V 16G --thinpool test_thin_pool test_vg")
|
|
|
|
'';
|
|
|
|
|
|
|
|
vdo = ''
|
2022-10-15 22:18:03 +00:00
|
|
|
machine.succeed("vgcreate test_vg /dev/vdb")
|
2022-04-11 18:28:09 +00:00
|
|
|
machine.succeed("lvcreate --type vdo -n test_lv -L 6G -V 12G test_vg/vdo_pool_lv")
|
|
|
|
'';
|
|
|
|
}.${flavour};
|
|
|
|
|
|
|
|
extraConfig = {
|
|
|
|
raid = {
|
|
|
|
boot.initrd.kernelModules = [
|
|
|
|
"dm-raid"
|
|
|
|
"raid0"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
thinpool = {
|
|
|
|
services.lvm = {
|
|
|
|
boot.thin.enable = true;
|
|
|
|
dmeventd.enable = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
vdo = {
|
|
|
|
services.lvm = {
|
|
|
|
boot.vdo.enable = true;
|
|
|
|
dmeventd.enable = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}.${flavour};
|
|
|
|
|
|
|
|
extraCheck = {
|
|
|
|
raid = ''
|
|
|
|
"test_lv" in machine.succeed("lvs --select segtype=raid0")
|
|
|
|
'';
|
|
|
|
|
|
|
|
thinpool = ''
|
|
|
|
"test_lv" in machine.succeed("lvs --select segtype=thin-pool")
|
|
|
|
'';
|
|
|
|
|
|
|
|
vdo = ''
|
|
|
|
"test_lv" in machine.succeed("lvs --select segtype=vdo")
|
|
|
|
'';
|
|
|
|
}.${flavour};
|
|
|
|
|
|
|
|
in import ../make-test-python.nix ({ pkgs, ... }: {
|
|
|
|
name = "lvm2-${flavour}-systemd-stage-1";
|
|
|
|
meta.maintainers = with pkgs.lib.maintainers; [ das_j ];
|
|
|
|
|
|
|
|
nodes.machine = { pkgs, lib, ... }: {
|
|
|
|
imports = [ extraConfig ];
|
|
|
|
# Use systemd-boot
|
|
|
|
virtualisation = {
|
|
|
|
emptyDiskImages = [ 8192 8192 ];
|
|
|
|
useBootLoader = true;
|
|
|
|
useEFIBoot = true;
|
2023-05-26 15:17:35 +00:00
|
|
|
# To boot off the LVM disk, we need to have a init script which comes from the Nix store.
|
|
|
|
mountHostNixStore = true;
|
2022-04-11 18:28:09 +00:00
|
|
|
};
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
|
|
|
|
environment.systemPackages = with pkgs; [ e2fsprogs ]; # for mkfs.ext4
|
|
|
|
boot = {
|
|
|
|
initrd.systemd = {
|
|
|
|
enable = true;
|
|
|
|
emergencyAccess = true;
|
|
|
|
};
|
|
|
|
initrd.services.lvm.enable = true;
|
|
|
|
kernelPackages = lib.mkIf (kernelPackages != null) kernelPackages;
|
|
|
|
};
|
|
|
|
|
2022-10-15 22:18:03 +00:00
|
|
|
specialisation.boot-lvm.configuration.virtualisation.rootDevice = "/dev/test_vg/test_lv";
|
2022-04-11 18:28:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
# Create a VG for the root
|
|
|
|
${preparationCode}
|
|
|
|
machine.succeed("mkfs.ext4 /dev/test_vg/test_lv")
|
|
|
|
machine.succeed("mkdir -p /mnt && mount /dev/test_vg/test_lv /mnt && echo hello > /mnt/test && umount /mnt")
|
|
|
|
|
|
|
|
# Boot from LVM
|
|
|
|
machine.succeed("bootctl set-default nixos-generation-1-specialisation-boot-lvm.conf")
|
|
|
|
machine.succeed("sync")
|
|
|
|
machine.crash()
|
|
|
|
machine.wait_for_unit("multi-user.target")
|
|
|
|
|
|
|
|
# Ensure we have successfully booted from LVM
|
|
|
|
assert "(initrd)" in machine.succeed("systemd-analyze") # booted with systemd in stage 1
|
|
|
|
assert "/dev/mapper/test_vg-test_lv on / type ext4" in machine.succeed("mount")
|
|
|
|
assert "hello" in machine.succeed("cat /test")
|
|
|
|
${extraCheck}
|
|
|
|
'';
|
|
|
|
})
|