Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 21 additions & 1 deletion base/voidlinux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,27 @@ fi

# install required packages and config files
set -e
xbps-install -y opendoas tar gzip curl diffutils
xbps-install -y \
cloud-guest-utils \
curl \
diffutils \
gzip \
opendoas \
tar

# grow ssd partition and filesystem at boot (one-shot)
GROW_SSD_SVDIR=etc/sv/grow-ssd
mkdir -p /$GROW_SSD_SVDIR
mkdir -p /$GROW_SSD_SVDIR/log
if [ ! -f /$GROW_SSD_SVDIR/run ]; then
cp "$SYSUPDATES_ROOTDIR/files/$GROW_SSD_SVDIR/run" /$GROW_SSD_SVDIR/run
chmod +x /$GROW_SSD_SVDIR/run
fi
if [ ! -f /$GROW_SSD_SVDIR/log/run ]; then
cp "$SYSUPDATES_ROOTDIR/files/$GROW_SSD_SVDIR/log/run" /$GROW_SSD_SVDIR/log/run
chmod +x /$GROW_SSD_SVDIR/log/run
fi
ln -sfT /$GROW_SSD_SVDIR /var/service/grow-ssd

# openbsd's doas util config, a minial replacement of sudo
if [ ! -f /etc/doas.conf ]; then
Expand Down
2 changes: 2 additions & 0 deletions files/etc/sv/grow-ssd/log/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec vlogger -t grow-ssd -p daemon
104 changes: 104 additions & 0 deletions files/etc/sv/grow-ssd/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/sh
# grow ssd partition and filesystem at boot (one-shot)

set -eu

# Wait for /ssd to be mounted (up to 60 seconds)
MAX_WAIT=60
WAITED=0
SSD_DEV=$(findmnt -n -o SOURCE /ssd 2>/dev/null || echo "")

case "$SSD_DEV" in
/dev/*)
# Already mounted, proceed
;;
*)
# Not yet mounted, wait for it
echo "grow-ssd: waiting for /ssd to be mounted..."
while [ $WAITED -lt $MAX_WAIT ]; do
SSD_DEV=$(findmnt -n -o SOURCE /ssd 2>/dev/null || echo "")
case "$SSD_DEV" in
/dev/*)
echo "grow-ssd: /ssd is mounted on $SSD_DEV"
break
;;
esac
sleep 1
WAITED=$((WAITED + 1))
done
# Check if we actually found the device
case "$SSD_DEV" in
/dev/*)
# Successfully detected, continue
;;
*)
echo "grow-ssd: unable to detect source device for /ssd; mount point /ssd may not exist or may not be ready yet; skipping"
sv down /var/service/grow-ssd >/dev/null 2>&1 || true
exit 0
;;
esac
;;
esac

PKNAME=$(lsblk -no pkname "$SSD_DEV" 2>/dev/null || echo "")
if [ -n "$PKNAME" ]; then
DISK="/dev/$PKNAME"
else
case "$SSD_DEV" in
# Bare NVMe namespace device, e.g. /dev/nvme0n1
/dev/nvme[0-9]n[0-9])
DISK="$SSD_DEV"
;;
# 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]+$//')
;;
# 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]+$//')
;;
# Fallback: leave as-is if we cannot reliably parse
*)
DISK="$SSD_DEV"
;;
esac
fi

# 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

# No support for bare non-partitioned devices currently
case "$PART" in
''|*[!0-9]*)
echo "grow-ssd: unable to determine partition number from $SSD_DEV or no partition; skipping"
sv down /var/service/grow-ssd >/dev/null 2>&1 || true
exit 0
;;
esac

# Only run if partition can be grown
growpart --dry-run "$DISK" "$PART" >/dev/null 2>&1 || {
sv down /var/service/grow-ssd >/dev/null 2>&1 || true
exit 0
}

echo "Growing partition $SSD_DEV"
growpart "$DISK" "$PART"

echo "Resizing filesystem on $SSD_DEV"
resize2fs "$SSD_DEV"

echo "grow-ssd completed"

# Disable the service after successful completion
sv down /var/service/grow-ssd >/dev/null 2>&1 || true