penguin/monok8s

k8s image for Mono Gateway Dev Kit

alpine/sync-loop.sh

raw ยท 752 bytes

#!/bin/bash
set -euo pipefail

DEVICE="$1"
FAKE_DEV="/tmp/dev"

mkdir -p "$FAKE_DEV"
PARENT_NAME=$(basename "$DEVICE")

echo "Refreshing partition table for $DEVICE..."
partx -u "$DEVICE" 2>/dev/null || partx -a "$DEVICE" || true

# Remove old fake nodes for this loop device first
find "$FAKE_DEV" -maxdepth 1 -type b -name "${PARENT_NAME}*" -exec rm -f {} \;

lsblk -rn -o NAME,MAJ:MIN "$DEVICE" | while read -r NAME MAJMIN; do
    # Skip the parent loop device itself
    if [[ "$NAME" == "$PARENT_NAME" ]]; then
        continue
    fi

    PART_PATH="$FAKE_DEV/$NAME"
    MAJOR="${MAJMIN%%:*}"
    MINOR="${MAJMIN##*:}"

    echo "Creating node: $PART_PATH (b $MAJOR $MINOR)"
    rm -f "$PART_PATH"
    mknod "$PART_PATH" b "$MAJOR" "$MINOR"
done