Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 25 additions & 35 deletions files/etc/sv/grow-ssd/run
Original file line number Diff line number Diff line change
Expand Up @@ -40,44 +40,34 @@ case "$SSD_DEV" in
;;
esac

# Parse disk and partition from the device path
case "$SSD_DEV" in
# Bare NVMe namespace device, e.g. /dev/nvme0n1
/dev/nvme[0-9]n[0-9])
DISK="$SSD_DEV"
PART=""
;;
# NVMe partition device, e.g. /dev/nvme0n1p1 -> /dev/nvme0n1
/dev/nvme[0-9]n[0-9]p[0-9]*)
DISK=$(printf '%s\n' "$SSD_DEV" | sed -E 's/p[0-9]+$//')
PART=$(printf '%s\n' "$SSD_DEV" | sed -E 's/.*p([0-9]+)$/\1/')
;;
# Non-NVMe devices with numeric partition suffix, e.g. /dev/sda1 -> /dev/sda
/dev/*[0-9])
DISK=$(printf '%s\n' "$SSD_DEV" | sed -E 's/[0-9]+$//')
PART=$(printf '%s\n' "$SSD_DEV" | sed -E 's/.*[^0-9]([0-9]+)$/\1/')
;;
# Fallback: leave as-is if we cannot reliably parse
*)
DISK="$SSD_DEV"
PART=""
;;
esac

# If the device has a parent (e.g., LVM, LUKS), use the parent as the disk
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is not correct, this will work not only with LVM or whatever, in most cases lsblk output will always succeed (e.g. lsblk -no pkname /dev/sda1 2>/dev/null || echo "" -> sda).

PKNAME=$(lsblk -no pkname "$SSD_DEV" 2>/dev/null || echo "")
if [ -n "$PKNAME" ]; then
DISK="/dev/$PKNAME"
# Extract partition number from the device path
case "$SSD_DEV" in
/dev/nvme*p[0-9]*)
PART=$(printf '%s\n' "$SSD_DEV" | sed -E 's/.*p([0-9]+)$/\1/')
;;
/dev/*[0-9])
PART=$(printf '%s\n' "$SSD_DEV" | sed -E 's/.*[^0-9]([0-9]+)$/\1/')
;;
*)
PART=""
;;
esac
else
case "$SSD_DEV" in
# Bare NVMe namespace device, e.g. /dev/nvme0n1
/dev/nvme[0-9]n[0-9])
DISK="$SSD_DEV"
PART=""
;;
# NVMe partition device, e.g. /dev/nvme0n1p1 -> /dev/nvme0n1
/dev/nvme[0-9]n[0-9]p[0-9]*)
DISK=$(printf '%s\n' "$SSD_DEV" | sed -E 's/p[0-9]+$//')
PART=$(printf '%s\n' "$SSD_DEV" | sed -E 's/.*p([0-9]+)$/\1/')
;;
# Non-NVMe devices with numeric partition suffix, e.g. /dev/sda1 -> /dev/sda
/dev/*[0-9])
DISK=$(printf '%s\n' "$SSD_DEV" | sed -E 's/[0-9]+$//')
PART=$(printf '%s\n' "$SSD_DEV" | sed -E 's/.*[^0-9]([0-9]+)$/\1/')
;;
# Fallback: leave as-is if we cannot reliably parse
*)
DISK="$SSD_DEV"
PART=""
;;
esac
fi

# No support for bare non-partitioned devices currently
Expand Down
Loading