1
0
Files
nixfiles/pkgs/grow-last-partition-and-filesystem/grow-last-partition-and-filesystem.sh

30 lines
625 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [[ $# -ne 1 ]]; then
echo "Pass device to grow as first argument:"
echo "grow-last-partition-and-filesystem DEVICE"
exit 1
fi
DEVICE="$1"
PARTITIONDATA="$(parted --script --json --fix "${DEVICE}" print)"
PARTNUMBER="$(echo "${PARTITIONDATA}" | jq -r '.disk.partitions | last | .number')"
PARTNAME="$(echo "${PARTITIONDATA}" | jq -r '.disk.partitions | last | .name')"
echo "Growing partition ${DEVICE}${PARTNUMBER} (${PARTNAME})"
echo
parted "${DEVICE}" resizepart "${PARTNUMBER}" 100%
echo
echo "Resizing filesystem"
echo
resize2fs "${DEVICE}${PARTNUMBER}"
echo "Done."