Created
June 26, 2022 13:54
-
-
Save peaceman/0d8e94cdc7d34f7815baaeccee0dabbb to your computer and use it in GitHub Desktop.
sgdisk
This file contains 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
#!/usr/bin/env bash | |
set -ex | |
DISK=/dev/sda | |
SYSTEM_PART_NR=1 | |
SYSTEM_PART_INFO=$(sgdisk $DISK -i $SYSTEM_PART_NR) | |
SYSTEM_PART_SIZE="10G" | |
SYSTEM_PART_GUID=$(sed -nr "s/^Partition unique GUID:\s+(\S+).+$/\1/p" <<< "$SYSTEM_PART_INFO") | |
SYSTEM_PART_FIRST_SECTOR=$(sed -nr "s/^First sector:\s+(\S+).*$/\1/p" <<< "$SYSTEM_PART_INFO") | |
APP_PART_NR=$((SYSTEM_PART_NR+1)) | |
if ! $(sgdisk $DISK -i $APP_PART_NR | grep -q "does not exist"); then | |
echo "Detected already existing application partition; abort repartitioning" | |
exit 0 | |
fi | |
SGDISK_ARGS=( | |
"$DISK" | |
# "--pretend" | |
"--delete" "$SYSTEM_PART_NR" | |
"--new" "$SYSTEM_PART_NR:$SYSTEM_PART_FIRST_SECTOR:+$SYSTEM_PART_SIZE" | |
"--partition-guid" "$SYSTEM_PART_NR:$SYSTEM_PART_GUID" | |
"--new" "$APP_PART_NR" | |
"--partition-guid" "$APP_PART_NR:R" | |
"--print" | |
) | |
sgdisk --move-second-header $DISK | |
sgdisk "${SGDISK_ARGS[@]}" | |
partprobe $DISK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment