nixos/filesystems: init erofs
Enable using an erofs filesystem as one of the filesystems needed to boot the system. This is useful for example in image based deployments where the Nix store is mounted read only. [erofs](https://docs.kernel.org/filesystems/erofs.html) offers multiple benefits over older filesystems like squashfs. Skip fsck.erofs because it is still experimental.
This commit is contained in:
@@ -1,55 +1,106 @@
|
||||
import ./make-test-python.nix ({ lib, pkgs, ... }:
|
||||
{ system ? builtins.currentSystem
|
||||
, config ? { }
|
||||
, pkgs ? import ../.. { inherit system config; }
|
||||
}:
|
||||
|
||||
with import ../lib/testing-python.nix { inherit system pkgs; };
|
||||
with pkgs.lib;
|
||||
{
|
||||
name = "non-default-filesystems";
|
||||
|
||||
nodes.machine =
|
||||
{ config, pkgs, lib, ... }:
|
||||
let
|
||||
disk = config.virtualisation.rootDevice;
|
||||
in
|
||||
btrfs = makeTest
|
||||
{
|
||||
virtualisation.rootDevice = "/dev/vda";
|
||||
virtualisation.useDefaultFilesystems = false;
|
||||
name = "non-default-filesystems-btrfs";
|
||||
|
||||
boot.initrd.availableKernelModules = [ "btrfs" ];
|
||||
boot.supportedFilesystems = [ "btrfs" ];
|
||||
nodes.machine =
|
||||
{ config, pkgs, lib, ... }:
|
||||
let
|
||||
disk = config.virtualisation.rootDevice;
|
||||
in
|
||||
{
|
||||
virtualisation.rootDevice = "/dev/vda";
|
||||
virtualisation.useDefaultFilesystems = false;
|
||||
|
||||
boot.initrd.postDeviceCommands = ''
|
||||
FSTYPE=$(blkid -o value -s TYPE ${disk} || true)
|
||||
if test -z "$FSTYPE"; then
|
||||
modprobe btrfs
|
||||
${pkgs.btrfs-progs}/bin/mkfs.btrfs ${disk}
|
||||
boot.initrd.availableKernelModules = [ "btrfs" ];
|
||||
boot.supportedFilesystems = [ "btrfs" ];
|
||||
|
||||
mkdir /nixos
|
||||
mount -t btrfs ${disk} /nixos
|
||||
boot.initrd.postDeviceCommands = ''
|
||||
FSTYPE=$(blkid -o value -s TYPE ${disk} || true)
|
||||
if test -z "$FSTYPE"; then
|
||||
modprobe btrfs
|
||||
${pkgs.btrfs-progs}/bin/mkfs.btrfs ${disk}
|
||||
|
||||
${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/root
|
||||
${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/home
|
||||
mkdir /nixos
|
||||
mount -t btrfs ${disk} /nixos
|
||||
|
||||
umount /nixos
|
||||
fi
|
||||
${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/root
|
||||
${pkgs.btrfs-progs}/bin/btrfs subvolume create /nixos/home
|
||||
|
||||
umount /nixos
|
||||
fi
|
||||
'';
|
||||
|
||||
virtualisation.fileSystems = {
|
||||
"/" = {
|
||||
device = disk;
|
||||
fsType = "btrfs";
|
||||
options = [ "subvol=/root" ];
|
||||
};
|
||||
|
||||
"/home" = {
|
||||
device = disk;
|
||||
fsType = "btrfs";
|
||||
options = [ "subvol=/home" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
|
||||
with subtest("BTRFS filesystems are mounted correctly"):
|
||||
machine.succeed("grep -E '/dev/vda / btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/root 0 0' /proc/mounts")
|
||||
machine.succeed("grep -E '/dev/vda /home btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/home 0 0' /proc/mounts")
|
||||
'';
|
||||
|
||||
virtualisation.fileSystems = {
|
||||
"/" = {
|
||||
device = disk;
|
||||
fsType = "btrfs";
|
||||
options = [ "subvol=/root" ];
|
||||
};
|
||||
|
||||
"/home" = {
|
||||
device = disk;
|
||||
fsType = "btrfs";
|
||||
options = [ "subvol=/home" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
machine.wait_for_unit("multi-user.target")
|
||||
erofs =
|
||||
let
|
||||
fsImage = "/tmp/non-default-filesystem.img";
|
||||
in
|
||||
makeTest {
|
||||
name = "non-default-filesystems-erofs";
|
||||
|
||||
with subtest("BTRFS filesystems are mounted correctly"):
|
||||
machine.succeed("grep -E '/dev/vda / btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/root 0 0' /proc/mounts")
|
||||
machine.succeed("grep -E '/dev/vda /home btrfs rw,relatime,space_cache=v2,subvolid=[0-9]+,subvol=/home 0 0' /proc/mounts")
|
||||
'';
|
||||
})
|
||||
nodes.machine = _: {
|
||||
virtualisation.qemu.drives = [{
|
||||
name = "non-default-filesystem";
|
||||
file = fsImage;
|
||||
}];
|
||||
|
||||
virtualisation.fileSystems."/non-default" = {
|
||||
device = "/dev/vdb";
|
||||
fsType = "erofs";
|
||||
neededForBoot = true;
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
with tempfile.TemporaryDirectory() as tmp_dir:
|
||||
with open(f"{tmp_dir}/filesystem", "w") as f:
|
||||
f.write("erofs")
|
||||
|
||||
subprocess.run([
|
||||
"${pkgs.erofs-utils}/bin/mkfs.erofs",
|
||||
"${fsImage}",
|
||||
tmp_dir,
|
||||
])
|
||||
|
||||
machine.start()
|
||||
machine.wait_for_unit("default.target")
|
||||
|
||||
file_contents = machine.succeed("cat /non-default/filesystem")
|
||||
assert "erofs" in file_contents
|
||||
'';
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user