-
Notifications
You must be signed in to change notification settings - Fork 1
grow ssd partition and filesystem at boot (one-shot) #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kristapsk
wants to merge
1
commit into
dev
Choose a base branch
from
grow-ssd
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| exec vlogger -t grow-ssd -p daemon | ||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # 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/') | ||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ;; | ||
| *) | ||
| 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" | ||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
| } | ||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo "Growing partition $SSD_DEV" | ||
| growpart "$DISK" "$PART" | ||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| echo "Resizing filesystem on $SSD_DEV" | ||
| resize2fs "$SSD_DEV" | ||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "grow-ssd completed" | ||
|
|
||
| # Disable the service after successful completion | ||
| sv down /var/service/grow-ssd >/dev/null 2>&1 || true | ||
kristapsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.