From ef80e11032c66d9e978eff9472687c983361fe08 Mon Sep 17 00:00:00 2001 From: nikstur Date: Thu, 18 May 2023 03:16:35 +0200 Subject: nixos/systemd-repart: enable creating root partition --- nixos/tests/systemd-repart.nix | 62 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'nixos/tests') diff --git a/nixos/tests/systemd-repart.nix b/nixos/tests/systemd-repart.nix index 36de5d988fdb1..9f5867c0f7ddc 100644 --- a/nixos/tests/systemd-repart.nix +++ b/nixos/tests/systemd-repart.nix @@ -56,8 +56,8 @@ let # however, creates separate filesystem images without a partition table, so # we have to create a disk image manually. # - # This creates two partitions, an ESP mounted on /dev/vda1 and the root - # partition mounted on /dev/vda2 + # This creates two partitions, an ESP available as /dev/vda1 and the root + # partition available as /dev/vda2. system.build.diskImage = import ../lib/make-disk-image.nix { inherit config pkgs lib; # Use a raw format disk so that it can be resized before starting the @@ -131,4 +131,62 @@ in assert "Growing existing partition 1." in systemd_repart_logs ''; }; + + create-root = makeTest { + name = "systemd-repart-create-root"; + meta.maintainers = with maintainers; [ nikstur ]; + + nodes.machine = { config, lib, pkgs, ... }: { + virtualisation.useDefaultFilesystems = false; + virtualisation.fileSystems = { + "/" = { + device = "/dev/disk/by-partlabel/created-root"; + fsType = "ext4"; + }; + "/nix/store" = { + device = "/dev/vda2"; + fsType = "ext4"; + }; + }; + + # Create an image containing only the Nix store. This enables creating + # the root partition with systemd-repart and then successfully booting + # into a working system. + # + # This creates two partitions, an ESP available as /dev/vda1 and the Nix + # store available as /dev/vda2. + system.build.diskImage = import ../lib/make-disk-image.nix { + inherit config pkgs lib; + onlyNixStore = true; + format = "raw"; + bootSize = "32M"; + additionalSpace = "0M"; + partitionTableType = "efi"; + installBootLoader = false; + copyChannel = false; + }; + + boot.initrd.systemd.enable = true; + + boot.initrd.systemd.repart.enable = true; + boot.initrd.systemd.repart.device = "/dev/vda"; + systemd.repart.partitions = { + "10-root" = { + Type = "root"; + Label = "created-root"; + Format = "ext4"; + }; + }; + }; + + testScript = { nodes, ... }: '' + ${useDiskImage nodes.machine} + + machine.start() + machine.wait_for_unit("multi-user.target") + + systemd_repart_logs = machine.succeed("journalctl --boot --unit systemd-repart.service") + assert "Adding new partition 2 to partition table." in systemd_repart_logs + ''; + }; } -- cgit 1.4.1