Skip to content

Commit 29ada2a

Browse files
committed
grow ssd partition and filesystem at boot (one-shot)
1 parent b23f541 commit 29ada2a

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

base/voidlinux.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,25 @@ fi
2525

2626
# install required packages and config files
2727
set -e
28-
xbps-install -y opendoas tar gzip curl diffutils
28+
xbps-install -y \
29+
cloud-guest-utils \
30+
curl \
31+
diffutils \
32+
gzip \
33+
opendoas \
34+
tar
35+
36+
# grow ssd partition and filesystem at boot (one-shot)
37+
GROW_SSD_SVDIR=etc/sv/grow-ssd
38+
mkdir -p /$GROW_SSD_SVDIR
39+
mkdir -p /$GROW_SSD_SVDIR/log
40+
if [ ! -f /$GROW_SSD_SVDIR/run ]; then
41+
cp "$SYSUPDATES_ROOTDIR/files/$GROW_SSD_SVDIR/run" /$GROW_SSD_SVDIR/run
42+
chmod +x /$GROW_SSD_SVDIR/run
43+
cp "$SYSUPDATES_ROOTDIR/files/$GROW_SSD_SVDIR/run" /$GROW_SSD_SVDIR/finish
44+
chmod +x /$GROW_SSD_SVDIR/finish
45+
fi
46+
ln -sfT /$GROW_SSD_SVDIR /etc/runit/runsvdir/default/
2947

3048
# openbsd's doas util config, a minial replacement of sudo
3149
if [ ! -f /etc/doas.conf ]; then

files/etc/sv/grow-ssd/finish

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
exit 0

files/etc/sv/grow-ssd/run

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
# grow ssd partition and filesystem at boot (one-shot)
3+
4+
set -e
5+
6+
SSD_DEV=$(findmnt -n -o SOURCE /ssd 2>/dev/null || echo "")
7+
case "$SSD_DEV" in
8+
/dev/*) ;;
9+
*)
10+
echo "grow-ssd: unable to detect root device for /ssd; skipping"
11+
exit 0
12+
;;
13+
esac
14+
15+
PKNAME=$(lsblk -no pkname "$SSD_DEV" 2>/dev/null || echo "")
16+
if [ -n "$PKNAME" ]; then
17+
DISK="/dev/$PKNAME"
18+
else
19+
DISK=$(printf '%s\n' "$SSD_DEV" | sed -E 's/p?[0-9]+$//')
20+
fi
21+
22+
PART=$(printf '%s\n' "$SSD_DEV" | sed -E 's/.*p?([0-9]+)$/\1/')
23+
case "$PART" in
24+
''|*[!0-9]*)
25+
echo "grow-ssd: unable to determine partition number from $SSD_DEV; skipping"
26+
exit 0
27+
;;
28+
esac
29+
30+
# Only run if partition can be grown
31+
growpart --dry-run "$DISK" "$PART" >/dev/null 2>&1 || exit 0
32+
33+
echo "Growing partition $SSD_DEV"
34+
growpart "$DISK" "$PART"
35+
36+
echo "Resizing filesystem on $SSD_DEV"
37+
resize2fs "$SSD_DEV"
38+
39+
echo "grow-ssd completed"

0 commit comments

Comments
 (0)