22 lines
570 B
Bash
Executable File
22 lines
570 B
Bash
Executable File
#!/bin/bash
|
|
DEVICE="$1"
|
|
FAKE_DEV="/tmp/dev"
|
|
|
|
mkdir -p "$FAKE_DEV"
|
|
|
|
echo "Refreshing partition table..."
|
|
partx -u "$DEVICE" 2>/dev/null || partx -a "$DEVICE"
|
|
|
|
# Find partitions and their Major:Minor numbers
|
|
lsblk -rn -o NAME,MAJ:MIN "$DEVICE" | while read -r NAME MAJMIN; do
|
|
# Skip the parent loop0
|
|
if [[ "$NAME" == "loop0" ]]; then continue; fi
|
|
|
|
PART_PATH="$FAKE_DEV/$NAME"
|
|
MAJOR=$(echo $MAJMIN | cut -d: -f1)
|
|
MINOR=$(echo $MAJMIN | cut -d: -f2)
|
|
|
|
echo "Creating node: $PART_PATH (b $MAJOR $MINOR)"
|
|
mknod "$PART_PATH" b "$MAJOR" "$MINOR"
|
|
done
|