-
-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathmdadm-btrfs-wipe.nix
More file actions
130 lines (116 loc) · 2.88 KB
/
mdadm-btrfs-wipe.nix
File metadata and controls
130 lines (116 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{
pkgs,
...
}:
let
inherit (pkgs) lib;
diskoModule = ../module.nix;
diskoConfig = {
disko.devices.disk = {
main = {
device = "/dev/vdb";
type = "disk";
content = {
type = "gpt";
partitions = {
ESP = {
type = "EF00";
size = "500M";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
encryptedSwap = {
size = "100%";
content = {
type = "swap";
randomEncryption = true;
};
};
};
};
};
}
// (lib.genAttrs [ "pool1" "pool2" ] (name: {
type = "disk";
device =
{
pool1 = "/dev/vdc";
pool2 = "/dev/vdd";
}
.${name};
content = {
type = "gpt";
partitions.mdadm = {
size = "100%";
content = {
type = "mdraid";
name = "raid0";
};
};
};
}));
disko.devices.mdadm.raid0 = {
type = "mdadm";
level = 0;
content = {
type = "btrfs";
extraArgs = [ "-f" ];
mountpoint = "/";
};
};
};
in
pkgs.testers.runNixOSTest {
name = "disko-btrfs-mdadm-resurrection";
nodes.machine =
{ config, pkgs, ... }:
{
imports = [
diskoModule
diskoConfig
];
boot.loader.grub.devices = [ "/dev/null" ];
virtualisation.emptyDiskImages = [
4096
4096
4096
];
boot.swraid.enable = true;
environment.systemPackages = with pkgs; [
mdadm
btrfs-progs
cryptsetup
parted
];
};
testScript =
{ nodes, ... }:
let
inherit (nodes.machine.system.build) destroyScript formatScript mountScript;
in
''
machine.wait_for_unit("multi-user.target")
print("Running initial format and mount...")
machine.succeed("${formatScript}")
machine.succeed("${mountScript}")
print("Writing canary file...")
machine.succeed("echo 'I survived the wipe!' > /mnt/canary.txt")
machine.succeed("sync")
machine.succeed("umount -R /mnt")
print("Running the destroy script...")
machine.execute("${destroyScript}")
print("Attempting to reformat and remount...")
machine.execute("${formatScript}")
machine.execute("${mountScript}")
print("Checking if the canary file is still there...")
status, output = machine.execute("cat /mnt/canary.txt")
if status == 0 and "I survived the wipe!" in output:
raise Exception("The canary file survived the Disko wipe process!")
else:
print("Test passed: Data was successfully destroyed.")
'';
}