Change from mirror to snapraid with quirks
This commit is contained in:
@@ -169,10 +169,9 @@ DISK_NAME=()
|
||||
DISK_TYPE=()
|
||||
DISK_HEALTH=()
|
||||
DISK_ID=()
|
||||
DISK_SIZE=()
|
||||
DISK_SIZE_BYTES=()
|
||||
|
||||
for DISK in \$(lsblk -x SIZE -d -n -e 7,11 -o NAME); do
|
||||
|
||||
# Disk name and simple path
|
||||
DISK_DEVPATH+=("/dev/\$DISK")
|
||||
DISK_NAME+=("\$DISK")
|
||||
@@ -185,8 +184,8 @@ for DISK in \$(lsblk -x SIZE -d -n -e 7,11 -o NAME); do
|
||||
elif [[ "\$HDD" -eq 0 ]]; then DISK_TYPE+=("SSD");
|
||||
else DISK_TYPE+=("Other")
|
||||
fi
|
||||
# Disk health
|
||||
|
||||
# Disk health
|
||||
if [[ \$(echo "$REMOTE_PASS" | sudo -S smartctl -H /dev/\$DISK 2>/dev/null | grep 'self-assessment' | awk '{print \$6}') == "PASSED" ]]; then
|
||||
DISK_HEALTH+=("PASSED")
|
||||
else
|
||||
@@ -194,9 +193,6 @@ for DISK in \$(lsblk -x SIZE -d -n -e 7,11 -o NAME); do
|
||||
fi
|
||||
# Disk ID
|
||||
DISK_ID+=("\$(ls -l /dev/disk/by-id | grep -m1 "../../\$DISK" | awk '{print "/dev/disk/by-id/" \$9}')")
|
||||
# Disk size
|
||||
DISK_SIZE+=("\$(lsblk -x SIZE -d -n -e 7,11 -o SIZE /dev/\$DISK)")
|
||||
DISK_SIZE_BYTES+=("\$(lsblk -x SIZE -d -n -e 7,11 -b -o SIZE /dev/\$DISK)")
|
||||
done
|
||||
|
||||
echo "# Hardware detection results on \$(date)" > "${TMPFILE}"
|
||||
@@ -218,9 +214,7 @@ for var in \
|
||||
DISK_NAME \
|
||||
DISK_TYPE \
|
||||
DISK_HEALTH \
|
||||
DISK_ID \
|
||||
DISK_SIZE \
|
||||
DISK_SIZE_BYTES; do
|
||||
DISK_ID; do
|
||||
declare -p \${var} | sed 's/^declare /declare -g /' >> "${TMPFILE}"
|
||||
done
|
||||
SSHEND
|
||||
@@ -513,33 +507,8 @@ disks_generation() {
|
||||
(envsubst < "templates/nix-config/disks/content.nix") >> final-nix-config/etc/nixos/disks/disko.nix
|
||||
sed -i "s|/mnt/content-1|/mnt/data|" final-nix-config/etc/nixos/disks/disko.nix
|
||||
|
||||
# Mirror configuration
|
||||
elif [[ "$CONTENT_DISK_NUMBER" -eq 1 && "$PARITY_DISK_NUMBER" -eq 1 ]]; then
|
||||
export CONTENT_DISK_ID="${DATA_DISKS_ID[0]}"
|
||||
export PARITY_DISK_ID="${DATA_DISKS_ID[1]}"
|
||||
|
||||
# Calculate partition size to avoid mdadm size mismatch warning
|
||||
local SIZE1=0
|
||||
local SIZE2=0
|
||||
for k in "${!DISK_ID[@]}"; do
|
||||
[[ "${DISK_ID[$k]}" == "$CONTENT_DISK_ID" ]] && SIZE1="${DISK_SIZE_BYTES[$k]}"
|
||||
[[ "${DISK_ID[$k]}" == "$PARITY_DISK_ID" ]] && SIZE2="${DISK_SIZE_BYTES[$k]}"
|
||||
done
|
||||
# Fallback to devpath if ID lookup failed
|
||||
if [[ "$SIZE1" == "0" ]]; then for k in "${!DISK_DEVPATH[@]}"; do [[ "${DISK_DEVPATH[$k]}" == "$CONTENT_DISK_ID" ]] && SIZE1="${DISK_SIZE_BYTES[$k]}"; done; fi
|
||||
if [[ "$SIZE2" == "0" ]]; then for k in "${!DISK_DEVPATH[@]}"; do [[ "${DISK_DEVPATH[$k]}" == "$PARITY_DISK_ID" ]] && SIZE2="${DISK_SIZE_BYTES[$k]}"; done; fi
|
||||
|
||||
local MIN_SIZE=$SIZE1
|
||||
if [[ "$SIZE2" -lt "$SIZE1" ]]; then MIN_SIZE=$SIZE2; fi
|
||||
|
||||
# Subtract 2GB for safety (headers, rounding)
|
||||
local PART_SIZE_GIB=$(( (MIN_SIZE - 2147483648) / 1024 / 1024 / 1024 ))
|
||||
export PARTITION_SIZE="${PART_SIZE_GIB}G"
|
||||
|
||||
(envsubst < "templates/nix-config/disks/mirror.nix") >> final-nix-config/etc/nixos/disks/disko.nix
|
||||
|
||||
# SnapRAID configuration
|
||||
elif [[ "$CONTENT_DISK_NUMBER" -gt 1 ]]; then
|
||||
elif [[ ${CONTENT_DISK_NUMBER} -gt 0 && ${PARITY_DISK_NUMBER} -gt 0 ]]; then
|
||||
sed -i "s|# ./disks/snapraid.nix| ./disks/snapraid.nix|" final-nix-config/etc/nixos/configuration.nix
|
||||
j=0
|
||||
for i in $(seq 0 $(($CONTENT_DISK_NUMBER - 1))); do
|
||||
@@ -570,14 +539,16 @@ disks_generation() {
|
||||
MOUNT_DEPENDENCIES_STOP+=" \${pkgs.cryptsetup}/bin/cryptsetup close crypted-parity-${j}"$'\n'
|
||||
done
|
||||
echo -e "\n ✅ Generated $PARITY_DISK_NUMBER parity disk configuration(s)."
|
||||
[[ ${CONTENT_DISK_NUMBER} -eq 1 && ${PARITY_DISK_NUMBER} ]] && SNAPRAID_CONTENT_FILES+=" \"/mnt/content-0/snapraid.content\""$'\n'
|
||||
export SNAPRAID_CONTENT_FILES
|
||||
export SNAPRAID_DATA_DISKS
|
||||
export SNAPRAID_PARITY_FILES
|
||||
export MOUNT_DEPENDENCIES_START
|
||||
export MOUNT_DEPENDENCIES_STOP
|
||||
envsubst < templates/nix-config/disks/snapraid.nix > final-nix-config/etc/nixos/disks/snapraid.nix
|
||||
fi
|
||||
|
||||
envsubst < templates/nix-config/disks/snapraid.nix > final-nix-config/etc/nixos/disks/snapraid.nix
|
||||
|
||||
# Close the disko.nix block
|
||||
cat <<'EOF' >> final-nix-config/etc/nixos/disks/disko.nix
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
disko.devices = {
|
||||
# Boot disk LVM configuration
|
||||
@@ -12,6 +11,12 @@
|
||||
content.format = "btrfs";
|
||||
content.mountpoint = "/";
|
||||
};
|
||||
snapraid = {
|
||||
size = "1G";
|
||||
content.type = "filesystem";
|
||||
content.format = "btrfs";
|
||||
content.mountpoint = "/mnt/content-0";
|
||||
};
|
||||
swap = {
|
||||
size = "16G";
|
||||
content.type = "swap";
|
||||
@@ -23,7 +28,7 @@
|
||||
# Boot disk
|
||||
"boot-1" = {
|
||||
type = "disk";
|
||||
device = "${BOOT_DISK_1_ID}";
|
||||
device = "$BOOT_DISK_1_ID";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
{ lib, ... }:
|
||||
{
|
||||
disko.devices = {
|
||||
disk = {
|
||||
"boot-1" = {
|
||||
boot-1 = {
|
||||
type = "disk";
|
||||
device = "${BOOT_DISK_1_ID}";
|
||||
device = "$BOOT_DISK_1_ID";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
@@ -12,61 +11,112 @@
|
||||
size = "1G";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
type = "mdraid";
|
||||
name = "boot";
|
||||
};
|
||||
};
|
||||
crypt_p1 = {
|
||||
luks = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "crypted-boot-1";
|
||||
settings = {
|
||||
keyFile = "/etc/secrets/disks/boot-1";
|
||||
allowDiscards = true;
|
||||
keyFile = "/etc/secrets/disks/boot-1";
|
||||
};
|
||||
content = {
|
||||
type = "lvm_pv";
|
||||
vg = "pool";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"boot-2" = {
|
||||
boot-2 = {
|
||||
type = "disk";
|
||||
device = "${BOOT_DISK_2_ID}";
|
||||
device = "$BOOT_DISK_2_ID";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
crypt_p2 = {
|
||||
ESP = {
|
||||
size = "1G";
|
||||
type = "EF00";
|
||||
content = {
|
||||
type = "mdraid";
|
||||
name = "boot";
|
||||
};
|
||||
};
|
||||
luks = {
|
||||
size = "100%";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "crypted-boot-2";
|
||||
settings = {
|
||||
keyFile = "/etc/secrets/disks/boot-2";
|
||||
allowDiscards = true;
|
||||
keyFile = "/etc/secrets/disks/boot-2";
|
||||
};
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = [
|
||||
"-d raid1"
|
||||
"/dev/mapper/crypted-boot-1"
|
||||
];
|
||||
subvolumes = {
|
||||
"/root" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = [
|
||||
"rw"
|
||||
"relatime"
|
||||
"ssd"
|
||||
];
|
||||
};
|
||||
"/swap" = {
|
||||
mountpoint = "none";
|
||||
swap.size = "16G";
|
||||
};
|
||||
};
|
||||
type = "lvm_pv";
|
||||
vg = "pool";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
mdadm = {
|
||||
boot = {
|
||||
type = "mdadm";
|
||||
level = 1;
|
||||
metadata = "1.2";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "vfat";
|
||||
mountpoint = "/boot";
|
||||
mountOptions = [ "umask=0077" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
lvm_vg = {
|
||||
pool = {
|
||||
type = "lvm_vg";
|
||||
lvs = {
|
||||
swap = {
|
||||
size = "16G";
|
||||
lvm_type = "mirror";
|
||||
content = {
|
||||
type = "swap";
|
||||
};
|
||||
};
|
||||
snapraid = {
|
||||
size = "1G";
|
||||
lvm_type = "mirror";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "btrfs";
|
||||
mountpoint = "/mnt/content-0";
|
||||
};
|
||||
};
|
||||
root = {
|
||||
size = "100%";
|
||||
lvm_type = "mirror";
|
||||
content = {
|
||||
type = "btrfs";
|
||||
extraArgs = [ "-f" ];
|
||||
subvolumes = {
|
||||
"/rootfs" = {
|
||||
mountpoint = "/";
|
||||
mountOptions = [ "compress=zstd" "noatime" ];
|
||||
};
|
||||
"/home" = {
|
||||
mountpoint = "/home";
|
||||
mountOptions = [ "compress=zstd" ];
|
||||
};
|
||||
"/nix" = {
|
||||
mountpoint = "/nix";
|
||||
mountOptions = [ "compress=zstd" "noatime" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
"content-1" = {
|
||||
type = "disk";
|
||||
device = "$CONTENT_DISK_ID";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
mdadm = {
|
||||
size = "$PARTITION_SIZE";
|
||||
content = {
|
||||
type = "mdraid";
|
||||
name = "raid1";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
"parity-1" = {
|
||||
type = "disk";
|
||||
device = "$PARITY_DISK_ID";
|
||||
content = {
|
||||
type = "gpt";
|
||||
partitions = {
|
||||
mdadm = {
|
||||
size = "$PARTITION_SIZE";
|
||||
content = {
|
||||
type = "mdraid";
|
||||
name = "raid1";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
mdadm = {
|
||||
raid1 = {
|
||||
type = "mdadm";
|
||||
level = 1;
|
||||
metadata = "1.2";
|
||||
content = {
|
||||
type = "luks";
|
||||
name = "crypted-mirror";
|
||||
settings.keyFile = "/etc/secrets/disks/mirror";
|
||||
content = {
|
||||
type = "filesystem";
|
||||
format = "xfs";
|
||||
mountpoint = "/mnt/data";
|
||||
};
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user