Get mirror config working
This commit is contained in:
@@ -169,6 +169,7 @@ DISK_TYPE=()
|
|||||||
DISK_HEALTH=()
|
DISK_HEALTH=()
|
||||||
DISK_ID=()
|
DISK_ID=()
|
||||||
DISK_SIZE=()
|
DISK_SIZE=()
|
||||||
|
DISK_SIZE_BYTES=()
|
||||||
|
|
||||||
for DISK in \$(lsblk -x SIZE -d -n -e 7,11 -o NAME); do
|
for DISK in \$(lsblk -x SIZE -d -n -e 7,11 -o NAME); do
|
||||||
# Disk name and simple path
|
# 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_ID+=("\$(ls -l /dev/disk/by-id | grep -m1 "../../\$DISK" | awk '{print "/dev/disk/by-id/" \$9}')")
|
||||||
# Disk size
|
# Disk size
|
||||||
DISK_SIZE+=("\$(lsblk -x SIZE -d -n -e 7,11 -o SIZE /dev/\$DISK)")
|
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
|
done
|
||||||
|
|
||||||
echo "# Hardware detection results on \$(date)" > "${TMPFILE}"
|
echo "# Hardware detection results on \$(date)" > "${TMPFILE}"
|
||||||
@@ -215,7 +217,8 @@ for var in \
|
|||||||
DISK_TYPE \
|
DISK_TYPE \
|
||||||
DISK_HEALTH \
|
DISK_HEALTH \
|
||||||
DISK_ID \
|
DISK_ID \
|
||||||
DISK_SIZE; do
|
DISK_SIZE \
|
||||||
|
DISK_SIZE_BYTES; do
|
||||||
declare -p \${var} | sed 's/^declare /declare -g /' >> "${TMPFILE}"
|
declare -p \${var} | sed 's/^declare /declare -g /' >> "${TMPFILE}"
|
||||||
done
|
done
|
||||||
SSHEND
|
SSHEND
|
||||||
@@ -485,6 +488,25 @@ disks_generation() {
|
|||||||
elif [[ "$CONTENT_DISK_NUMBER" -eq 1 && "$PARITY_DISK_NUMBER" -eq 1 ]]; then
|
elif [[ "$CONTENT_DISK_NUMBER" -eq 1 && "$PARITY_DISK_NUMBER" -eq 1 ]]; then
|
||||||
export CONTENT_DISK_ID="${DATA_DISKS_ID[0]}"
|
export CONTENT_DISK_ID="${DATA_DISKS_ID[0]}"
|
||||||
export PARITY_DISK_ID="${DATA_DISKS_ID[1]}"
|
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
|
(envsubst < "templates/nix-config/disks/mirror.nix") >> final-nix-config/etc/nixos/disks/disko.nix
|
||||||
|
|
||||||
# SnapRAID configuration
|
# SnapRAID configuration
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
"data-1" = {
|
"data-1" = {
|
||||||
size = "100%";
|
size = "$PARTITION_SIZE";
|
||||||
content = {
|
content = {
|
||||||
type = "luks";
|
type = "luks";
|
||||||
name = "crypted-content-1";
|
name = "crypted-content-1";
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
type = "gpt";
|
type = "gpt";
|
||||||
partitions = {
|
partitions = {
|
||||||
"parity-1" = {
|
"parity-1" = {
|
||||||
size = "100%";
|
size = "$PARTITION_SIZE";
|
||||||
content = {
|
content = {
|
||||||
type = "luks";
|
type = "luks";
|
||||||
name = "crypted-parity-1";
|
name = "crypted-parity-1";
|
||||||
@@ -48,6 +48,7 @@
|
|||||||
"data-storage" = {
|
"data-storage" = {
|
||||||
type = "mdadm";
|
type = "mdadm";
|
||||||
level = 1;
|
level = 1;
|
||||||
|
postCreateHook = "mdadm --grow /dev/md/data-storage --bitmap=internal";
|
||||||
content = {
|
content = {
|
||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "xfs";
|
format = "xfs";
|
||||||
|
|||||||
Reference in New Issue
Block a user