#!/usr/bin/env bash # CareTV mergerfs Existing-Data Adoption / Pool Rebuild # Version: v001 # # IMPORTANT DIFFERENCE FROM WINDOWS DRIVEPOOL: # mergerfs does NOT require files to be moved into a hidden pool folder. # Existing files remain exactly where they already are. # To "adopt" a disk, add its mount point as a mergerfs branch. # # This script: # 1. Reads branch mount points from /etc/caretv/mergerfs-branches.conf # 2. Verifies every branch exists and is mounted # 3. Creates /caretv if necessary # 4. Mounts/re-mounts the unified mergerfs namespace at /caretv # # It does NOT move, copy, delete, format, or rebalance existing files. set -euo pipefail CONFIG="/etc/caretv/mergerfs-branches.conf" POOL="/caretv" if [[ $EUID -ne 0 ]]; then echo "Run with sudo/root." exit 1 fi if ! command -v mergerfs >/dev/null 2>&1; then echo "mergerfs is not installed." echo "On Debian/Ubuntu: sudo apt install mergerfs" exit 1 fi mkdir -p /etc/caretv mkdir -p "$POOL" if [[ ! -f "$CONFIG" ]]; then cat > "$CONFIG" <<'EOF' # One existing filesystem mount point per line. # Files remain on these disks exactly where they are. # # Example: # /mnt/caretv-disk01 # /mnt/caretv-disk02 # /mnt/caretv-disk03 EOF echo "Created $CONFIG" echo "Add your disk mount points, one per line, then run this script again." exit 0 fi mapfile -t BRANCHES < <(grep -vE '^[[:space:]]*(#|$)' "$CONFIG") if [[ ${#BRANCHES[@]} -eq 0 ]]; then echo "No mergerfs branches are configured in $CONFIG" exit 1 fi for branch in "${BRANCHES[@]}"; do if [[ ! -d "$branch" ]]; then echo "Missing branch directory: $branch" exit 1 fi if ! mountpoint -q "$branch"; then echo "Branch is not mounted: $branch" echo "Refusing to continue so files cannot accidentally land on the root filesystem." exit 1 fi done BRANCH_STRING="$(IFS=:; echo "${BRANCHES[*]}")" if mountpoint -q "$POOL"; then umount "$POOL" fi # category.create=mfs = create new files on the branch with most free space. # Existing files are visible immediately; nothing is moved. mergerfs \ -o defaults,allow_other,use_ino,cache.files=partial,dropcacheonclose=true,category.create=mfs \ "$BRANCH_STRING" \ "$POOL" echo echo "CareTV mergerfs pool is online at: $POOL" echo "Existing files remain on their original physical filesystems." echo "No copy/move/delete operation was performed."