Get mirror config working

This commit is contained in:
Raphaël Numbus
2026-01-10 12:29:44 +01:00
parent 1018610252
commit e5b0930175
2 changed files with 26 additions and 3 deletions
+23 -1
View File
@@ -169,6 +169,7 @@ 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
@@ -193,6 +194,7 @@ for DISK in \$(lsblk -x SIZE -d -n -e 7,11 -o NAME); do
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}"
@@ -215,7 +217,8 @@ for var in \
DISK_TYPE \
DISK_HEALTH \
DISK_ID \
DISK_SIZE; do
DISK_SIZE \
DISK_SIZE_BYTES; do
declare -p \${var} | sed 's/^declare /declare -g /' >> "${TMPFILE}"
done
SSHEND
@@ -485,6 +488,25 @@ disks_generation() {
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}GiB"
(envsubst < "templates/nix-config/disks/mirror.nix") >> final-nix-config/etc/nixos/disks/disko.nix
# SnapRAID configuration
+3 -2
View File
@@ -6,7 +6,7 @@
type = "gpt";
partitions = {
"data-1" = {
size = "100%";
size = "$PARTITION_SIZE";
content = {
type = "luks";
name = "crypted-content-1";
@@ -27,7 +27,7 @@
type = "gpt";
partitions = {
"parity-1" = {
size = "100%";
size = "$PARTITION_SIZE";
content = {
type = "luks";
name = "crypted-parity-1";
@@ -48,6 +48,7 @@
"data-storage" = {
type = "mdadm";
level = 1;
postCreateHook = "mdadm --grow /dev/md/data-storage --bitmap=internal";
content = {
type = "filesystem";
format = "xfs";