github.com/containers/podman/v2@v2.2.2-0.20210501105131-c1e07d070c4c/contrib/cirrus/add_second_partition.sh (about) 1 #!/usr/bin/env bash 2 3 # N/B: This script could mega f*!@up your disks if run by mistake. 4 # it is left without the execute-bit on purpose! 5 6 set -eo pipefail 7 8 # shellcheck source=./lib.sh 9 source $(dirname $0)/lib.sh 10 11 # $SLASH_DEVICE is the disk device to be f*xtuP 12 SLASH_DEVICE="/dev/sda" # Always the case on GCP 13 14 # The unallocated space results from the difference in disk-size between VM Image 15 # and runtime request. 16 NEW_PART_START="50%" 17 NEW_PART_END="100%" 18 19 20 if [[ ! -r "/root" ]] || [[ -r "/root/second_partition_ready" ]] 21 then 22 warn "Ignoring attempted execution of $(basename $0)" 23 exit 0 24 fi 25 26 [[ -x "$(type -P parted)" ]] || \ 27 die "The parted command is required." 28 29 [[ ! -b ${SLASH_DEVICE}2 ]] || \ 30 die "Found unexpected block device ${SLASH_DEVICE}2" 31 32 PPRINTCMD="parted --script ${SLASH_DEVICE} print" 33 FINDMNTCMD="findmnt --source=${SLASH_DEVICE}1 --mountpoint=/ --canonicalize --evaluate --first-only --noheadings" 34 TMPF=$(mktemp -p '' $(basename $0)_XXXX) 35 trap "rm -f $TMPF" EXIT 36 37 if $FINDMNTCMD | tee $TMPF | egrep -q "^/\s+${SLASH_DEVICE}1" 38 then 39 msg "Repartitioning original partition table:" 40 $PPRINTCMD 41 else 42 die "Unexpected output from '$FINDMNTCMD': $(<$TMPF)" 43 fi 44 45 echo "Adding partition offset within unpartitioned space." 46 parted --script --align optimal /dev/sda unit % mkpart primary "" "" "$NEW_PART_START" "$NEW_PART_END" 47 48 msg "New partition table:" 49 $PPRINTCMD 50 51 msg "Growing ${SLASH_DEVICE}1 meet start of ${SLASH_DEVICE}2" 52 growpart ${SLASH_DEVICE} 1 53 54 FSTYPE=$(findmnt --first-only --noheadings --output FSTYPE ${SLASH_DEVICE}1) 55 echo "Expanding $FSTYPE filesystem on ${SLASH_DEVICE}1" 56 case $FSTYPE in 57 ext*) resize2fs ${SLASH_DEVICE}1 ;; 58 *) die "Script $(basename $0) doesn't know how to resize a $FSTYPE filesystem." ;; 59 esac 60 61 # Must happen last - signals completion to other tooling 62 msg "Recording newly available disk partition device into /root/second_partition_ready" 63 echo "${SLASH_DEVICE}2" > /root/second_partition_ready